blob: 8f42ec937c89454afa697762f0e99d298f992a45 [file] [log] [blame]
[email protected]71c10c52014-01-24 01:06:401// 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
16namespace extensions {
17namespace error_test_util {
18
19namespace {
20const char kDefaultStackTrace[] = "function_name (https://url.com:1:1)";
21}
22
dchengf5d241082016-04-21 03:43:1123std::unique_ptr<ExtensionError> CreateNewRuntimeError(
[email protected]71c10c52014-01-24 01:06:4024 const std::string& extension_id,
25 const std::string& message,
26 bool from_incognito) {
27 StackTrace stack_trace;
dchengf5d241082016-04-21 03:43:1128 std::unique_ptr<StackFrame> frame =
[email protected]553f2cf2014-05-24 00:28:5629 StackFrame::CreateFromText(base::ASCIIToUTF16(kDefaultStackTrace));
[email protected]71c10c52014-01-24 01:06:4030 CHECK(frame.get());
31 stack_trace.push_back(*frame);
32
33 base::string16 source =
34 base::UTF8ToUTF16(std::string(kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:2435 url::kStandardSchemeSeparator +
[email protected]71c10c52014-01-24 01:06:4036 extension_id);
37
dchengf5d241082016-04-21 03:43:1138 return std::unique_ptr<ExtensionError>(
rdevlin.cronin86f5b702015-06-24 18:49:1739 new RuntimeError(extension_id, from_incognito, source,
40 base::UTF8ToUTF16(message), stack_trace,
[email protected]2919a5e2014-04-24 08:34:0541 GURL::EmptyGURL(), // no context url
42 logging::LOG_INFO,
rdevlin.cronin86f5b702015-06-24 18:49:1743 0, // Render frame id
44 0)); // Render process id
[email protected]71c10c52014-01-24 01:06:4045}
46
dchengf5d241082016-04-21 03:43:1147std::unique_ptr<ExtensionError> CreateNewRuntimeError(
48 const std::string& extension_id,
49 const std::string& message) {
[email protected]71c10c52014-01-24 01:06:4050 return CreateNewRuntimeError(extension_id, message, false);
51}
52
dchengf5d241082016-04-21 03:43:1153std::unique_ptr<ExtensionError> CreateNewManifestError(
54 const std::string& extension_id,
55 const std::string& message) {
56 return std::unique_ptr<ExtensionError>(
57 new ManifestError(extension_id, base::UTF8ToUTF16(message),
58 base::string16(), base::string16()));
[email protected]71c10c52014-01-24 01:06:4059}
60
61} // namespace error_test_util
62} // namespace extensions