OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/error_console/error_console.h" | 5 #include "chrome/browser/extensions/error_console/error_console.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/common/extensions/feature_switch.h" | 15 #include "chrome/common/extensions/feature_switch.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
19 #include "extensions/browser/extension_error.h" | 19 #include "extensions/browser/extension_error.h" |
20 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
21 #include "extensions/common/id_util.h" | 21 #include "extensions/common/id_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "url/gurl.h" |
23 | 24 |
24 using base::string16; | 25 using base::string16; |
25 using base::UTF8ToUTF16; | |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char kExecutionContextURLKey[] = "executionContextURL"; | 31 const char kDefaultStackTrace[] = "function_name (https://url.com:1:1)"; |
32 const char kStackTraceKey[] = "stackTrace"; | |
33 | 32 |
34 string16 CreateErrorDetails(const std::string& extension_id) { | 33 StackTrace GetDefaultStackTrace() { |
35 base::DictionaryValue value; | 34 StackTrace stack_trace; |
36 value.SetString( | 35 scoped_ptr<StackFrame> frame = |
37 kExecutionContextURLKey, | 36 StackFrame::CreateFromText(base::UTF8ToUTF16(kDefaultStackTrace)); |
| 37 CHECK(frame.get()); |
| 38 stack_trace.push_back(*frame); |
| 39 return stack_trace; |
| 40 } |
| 41 |
| 42 string16 GetSourceForExtensionId(const std::string& extension_id) { |
| 43 return base::UTF8ToUTF16( |
38 std::string(kExtensionScheme) + | 44 std::string(kExtensionScheme) + |
39 content::kStandardSchemeSeparator + | 45 content::kStandardSchemeSeparator + |
40 extension_id); | 46 extension_id); |
41 value.Set(kStackTraceKey, new ListValue); | |
42 std::string json_utf8; | |
43 base::JSONWriter::Write(&value, &json_utf8); | |
44 return UTF8ToUTF16(json_utf8); | |
45 } | 47 } |
46 | 48 |
47 scoped_ptr<ExtensionError> CreateNewRuntimeError( | 49 scoped_ptr<ExtensionError> CreateNewRuntimeError( |
48 bool from_incognito, | 50 bool from_incognito, |
49 const std::string& extension_id, | 51 const std::string& extension_id, |
50 const string16& message) { | 52 const string16& message) { |
51 return scoped_ptr<ExtensionError>(new RuntimeError( | 53 return scoped_ptr<ExtensionError>(new RuntimeError( |
52 from_incognito, | 54 from_incognito, |
53 UTF8ToUTF16("source"), | 55 GetSourceForExtensionId(extension_id), |
54 message, | 56 message, |
55 logging::LOG_INFO, | 57 GetDefaultStackTrace(), |
56 CreateErrorDetails(extension_id))); | 58 GURL::EmptyGURL(), // no context url |
| 59 logging::LOG_INFO)); |
57 } | 60 } |
58 | 61 |
59 } // namespace | 62 } // namespace |
60 | 63 |
61 class ErrorConsoleUnitTest : public testing::Test { | 64 class ErrorConsoleUnitTest : public testing::Test { |
62 public: | 65 public: |
63 ErrorConsoleUnitTest() : error_console_(NULL) { } | 66 ErrorConsoleUnitTest() : error_console_(NULL) { } |
64 virtual ~ErrorConsoleUnitTest() { } | 67 virtual ~ErrorConsoleUnitTest() { } |
65 | 68 |
66 virtual void SetUp() OVERRIDE { | 69 virtual void SetUp() OVERRIDE { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 error_console_->GetErrorsForExtension(kId); | 197 error_console_->GetErrorsForExtension(kId); |
195 ASSERT_EQ(kNumErrors, errors.size()); | 198 ASSERT_EQ(kNumErrors, errors.size()); |
196 | 199 |
197 // The duplicate error should be the last reported (pointer comparison)... | 200 // The duplicate error should be the last reported (pointer comparison)... |
198 ASSERT_EQ(weak_error, errors.back()); | 201 ASSERT_EQ(weak_error, errors.back()); |
199 // ... and should have two reported occurrences. | 202 // ... and should have two reported occurrences. |
200 ASSERT_EQ(2u, errors.back()->occurrences()); | 203 ASSERT_EQ(2u, errors.back()->occurrences()); |
201 } | 204 } |
202 | 205 |
203 } // namespace extensions | 206 } // namespace extensions |
OLD | NEW |