[email protected] | 71c10c5 | 2014-01-24 01:06:40 | [diff] [blame^] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "extensions/browser/extension_error_test_util.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "base/strings/string_util.h" |
| 9 | #include "base/strings/utf_string_conversions.h" |
| 10 | #include "content/public/common/url_constants.h" |
| 11 | #include "extensions/browser/extension_error.h" |
| 12 | #include "extensions/common/constants.h" |
| 13 | #include "extensions/common/stack_frame.h" |
| 14 | #include "url/gurl.h" |
| 15 | |
| 16 | namespace extensions { |
| 17 | namespace error_test_util { |
| 18 | |
| 19 | namespace { |
| 20 | const char kDefaultStackTrace[] = "function_name (https://url.com:1:1)"; |
| 21 | } |
| 22 | |
| 23 | scoped_ptr<ExtensionError> CreateNewRuntimeError( |
| 24 | const std::string& extension_id, |
| 25 | const std::string& message, |
| 26 | bool from_incognito) { |
| 27 | StackTrace stack_trace; |
| 28 | scoped_ptr<StackFrame> frame = |
| 29 | StackFrame::CreateFromText(base::UTF8ToUTF16(kDefaultStackTrace)); |
| 30 | CHECK(frame.get()); |
| 31 | stack_trace.push_back(*frame); |
| 32 | |
| 33 | base::string16 source = |
| 34 | base::UTF8ToUTF16(std::string(kExtensionScheme) + |
| 35 | content::kStandardSchemeSeparator + |
| 36 | extension_id); |
| 37 | |
| 38 | return scoped_ptr<ExtensionError>(new RuntimeError( |
| 39 | extension_id, |
| 40 | from_incognito, |
| 41 | source, |
| 42 | base::UTF8ToUTF16(message), |
| 43 | stack_trace, |
| 44 | GURL::EmptyGURL(), // no context url |
| 45 | logging::LOG_INFO, |
| 46 | 0, 0 /* Render [View|Process] ID */ )); |
| 47 | } |
| 48 | |
| 49 | scoped_ptr<ExtensionError> CreateNewRuntimeError( |
| 50 | const std::string& extension_id, const std::string& message) { |
| 51 | return CreateNewRuntimeError(extension_id, message, false); |
| 52 | } |
| 53 | |
| 54 | scoped_ptr<ExtensionError> CreateNewManifestError( |
| 55 | const std::string& extension_id, const std::string& message) { |
| 56 | return scoped_ptr<ExtensionError>( |
| 57 | new ManifestError(extension_id, |
| 58 | base::UTF8ToUTF16(message), |
| 59 | base::EmptyString16(), |
| 60 | base::EmptyString16())); |
| 61 | } |
| 62 | |
| 63 | } // namespace error_test_util |
| 64 | } // namespace extensions |