| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 using base::string16; | 29 using base::string16; |
| 30 using base::UTF8ToUTF16; | 30 using base::UTF8ToUTF16; |
| 31 | 31 |
| 32 namespace extensions { | 32 namespace extensions { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char kTestingPage[] = "/extensions/test_file.html"; | 36 const char kTestingPage[] = "/extensions/test_file.html"; |
| 37 const char kAnonymousFunction[] = "(anonymous function)"; | 37 const char kAnonymousFunction[] = "(anonymous function)"; |
| 38 const char* kBackgroundPageName = | 38 const char* const kBackgroundPageName = |
| 39 extensions::kGeneratedBackgroundPageFilename; | 39 extensions::kGeneratedBackgroundPageFilename; |
| 40 const int kNoFlags = 0; | 40 const int kNoFlags = 0; |
| 41 | 41 |
| 42 const StackTrace& GetStackTraceFromError(const ExtensionError* error) { | 42 const StackTrace& GetStackTraceFromError(const ExtensionError* error) { |
| 43 CHECK(error->type() == ExtensionError::RUNTIME_ERROR); | 43 CHECK(error->type() == ExtensionError::RUNTIME_ERROR); |
| 44 return (static_cast<const RuntimeError*>(error))->stack_trace(); | 44 return (static_cast<const RuntimeError*>(error))->stack_trace(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Verify that a given |frame| has the proper source and function name. | 47 // Verify that a given |frame| has the proper source and function name. |
| 48 void CheckStackFrame(const StackFrame& frame, | 48 void CheckStackFrame(const StackFrame& frame, |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // We should only have errors for a single extension, or should have no | 267 // We should only have errors for a single extension, or should have no |
| 268 // entries, if no errors were expected. | 268 // entries, if no errors were expected. |
| 269 ASSERT_EQ(errors_expected > 0 ? 1u : 0u, | 269 ASSERT_EQ(errors_expected > 0 ? 1u : 0u, |
| 270 error_console()->get_num_entries_for_test()); | 270 error_console()->get_num_entries_for_test()); |
| 271 ASSERT_EQ( | 271 ASSERT_EQ( |
| 272 errors_expected, | 272 errors_expected, |
| 273 error_console()->GetErrorsForExtension((*extension)->id()).size()); | 273 error_console()->GetErrorsForExtension((*extension)->id()).size()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 ErrorConsole* error_console() { return error_console_; } | 276 ErrorConsole* error_console() { return error_console_; } |
| 277 |
| 277 private: | 278 private: |
| 278 // The URL used in testing for simple page navigations. | 279 // The URL used in testing for simple page navigations. |
| 279 GURL test_url_; | 280 GURL test_url_; |
| 280 | 281 |
| 281 // Weak reference to the ErrorConsole. | 282 // Weak reference to the ErrorConsole. |
| 282 ErrorConsole* error_console_; | 283 ErrorConsole* error_console_; |
| 283 }; | 284 }; |
| 284 | 285 |
| 285 // Test to ensure that we are successfully reporting manifest errors as an | 286 // Test to ensure that we are successfully reporting manifest errors as an |
| 286 // extension is installed. | 287 // extension is installed. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 "Hello, World!", // The error message is the log. | 385 "Hello, World!", // The error message is the log. |
| 385 logging::LOG_INFO, | 386 logging::LOG_INFO, |
| 386 GetTestURL(), // Content scripts run in the web page. | 387 GetTestURL(), // Content scripts run in the web page. |
| 387 2u); | 388 2u); |
| 388 | 389 |
| 389 const StackTrace& stack_trace1 = GetStackTraceFromError(errors[0]); | 390 const StackTrace& stack_trace1 = GetStackTraceFromError(errors[0]); |
| 390 CheckStackFrame(stack_trace1[0], | 391 CheckStackFrame(stack_trace1[0], |
| 391 script_url, | 392 script_url, |
| 392 "logHelloWorld", // function name | 393 "logHelloWorld", // function name |
| 393 6u, // line number | 394 6u, // line number |
| 394 11u /* column number */ ); | 395 11u /* column number */); |
| 395 | 396 |
| 396 CheckStackFrame(stack_trace1[1], | 397 CheckStackFrame(stack_trace1[1], |
| 397 script_url, | 398 script_url, |
| 398 kAnonymousFunction, | 399 kAnonymousFunction, |
| 399 9u, | 400 9u, |
| 400 1u); | 401 1u); |
| 401 | 402 |
| 402 // The second error should be a runtime error. | 403 // The second error should be a runtime error. |
| 403 CheckRuntimeError(errors[1], | 404 CheckRuntimeError(errors[1], |
| 404 extension->id(), | 405 extension->id(), |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 574 |
| 574 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 575 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
| 575 ASSERT_EQ(1u, stack_trace.size()); | 576 ASSERT_EQ(1u, stack_trace.size()); |
| 576 CheckStackFrame(stack_trace[0], | 577 CheckStackFrame(stack_trace[0], |
| 577 script_url, | 578 script_url, |
| 578 kAnonymousFunction, | 579 kAnonymousFunction, |
| 579 12u, 20u); | 580 12u, 20u); |
| 580 } | 581 } |
| 581 | 582 |
| 582 } // namespace extensions | 583 } // namespace extensions |
| OLD | NEW |