| 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 441 |
| 442 std::string event_dispatch_to_listener_str = | 442 std::string event_dispatch_to_listener_str = |
| 443 base::StringPrintf("Event.publicClass.%s [as dispatchToListener]", | 443 base::StringPrintf("Event.publicClass.%s [as dispatchToListener]", |
| 444 kAnonymousFunction); | 444 kAnonymousFunction); |
| 445 | 445 |
| 446 CheckRuntimeError( | 446 CheckRuntimeError( |
| 447 errors[0], | 447 errors[0], |
| 448 extension->id(), | 448 extension->id(), |
| 449 script_url, | 449 script_url, |
| 450 false, // not incognito | 450 false, // not incognito |
| 451 "Error in event handler for browserAction.onClicked: baz is not defined\n" | 451 "Error in event handler for browserAction.onClicked: ReferenceError: " |
| 452 "Stack trace: ReferenceError: baz is not defined", | 452 "baz is not defined", |
| 453 logging::LOG_ERROR, | 453 logging::LOG_ERROR, |
| 454 extension->url().Resolve(kBackgroundPageName), | 454 extension->url().Resolve(kBackgroundPageName), |
| 455 6u); | 455 1u); |
| 456 | 456 |
| 457 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 457 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
| 458 // Note: This test used to have a stack trace of length 6 that contains stack |
| 459 // frames in the extension code, but since crbug.com/404406 was fixed only |
| 460 // stack frames within user-defined extension code are printed. |
| 458 | 461 |
| 459 CheckStackFrame(stack_trace[0], script_url, kAnonymousFunction); | 462 CheckStackFrame(stack_trace[0], script_url, kAnonymousFunction); |
| 460 CheckStackFrame(stack_trace[1], event_bindings_str, | |
| 461 "EventImpl.dispatchToListener"); | |
| 462 CheckStackFrame(stack_trace[2], "extensions::utils", | |
| 463 event_dispatch_to_listener_str); | |
| 464 CheckStackFrame(stack_trace[3], event_bindings_str, "EventImpl.dispatch_"); | |
| 465 CheckStackFrame(stack_trace[4], event_bindings_str, "dispatchArgs"); | |
| 466 CheckStackFrame(stack_trace[5], event_bindings_str, "dispatchEvent"); | |
| 467 } | 463 } |
| 468 | 464 |
| 469 // Test that we can catch an error for calling an API with improper arguments. | 465 // Test that we can catch an error for calling an API with improper arguments. |
| 470 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadAPIArgumentsRuntimeError) { | 466 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadAPIArgumentsRuntimeError) { |
| 471 const Extension* extension = NULL; | 467 const Extension* extension = NULL; |
| 472 LoadExtensionAndCheckErrors( | 468 LoadExtensionAndCheckErrors( |
| 473 "bad_api_arguments_runtime_error", | 469 "bad_api_arguments_runtime_error", |
| 474 kNoFlags, | 470 kNoFlags, |
| 475 1, // One error: call an API with improper arguments. | 471 1, // One error: call an API with improper arguments. |
| 476 ACTION_NONE, | 472 ACTION_NONE, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 575 |
| 580 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 576 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
| 581 ASSERT_EQ(1u, stack_trace.size()); | 577 ASSERT_EQ(1u, stack_trace.size()); |
| 582 CheckStackFrame(stack_trace[0], | 578 CheckStackFrame(stack_trace[0], |
| 583 script_url, | 579 script_url, |
| 584 kAnonymousFunction, | 580 kAnonymousFunction, |
| 585 12u, 20u); | 581 12u, 20u); |
| 586 } | 582 } |
| 587 | 583 |
| 588 } // namespace extensions | 584 } // namespace extensions |
| OLD | NEW |