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/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/extension_toolbar_model.h" | 15 #include "chrome/browser/extensions/extension_toolbar_model.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/feature_switch.h" | 18 #include "chrome/common/extensions/feature_switch.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 kNoFlags, | 420 kNoFlags, |
420 1u, // One error: A reference error from within the browser action. | 421 1u, // One error: A reference error from within the browser action. |
421 ACTION_BROWSER_ACTION, | 422 ACTION_BROWSER_ACTION, |
422 &extension); | 423 &extension); |
423 | 424 |
424 std::string script_url = extension->url().Resolve("browser_action.js").spec(); | 425 std::string script_url = extension->url().Resolve("browser_action.js").spec(); |
425 | 426 |
426 const ErrorConsole::ErrorList& errors = | 427 const ErrorConsole::ErrorList& errors = |
427 error_console()->GetErrorsForExtension(extension->id()); | 428 error_console()->GetErrorsForExtension(extension->id()); |
428 | 429 |
| 430 std::string event_bindings_str = |
| 431 base::StringPrintf("extensions::%s", kEventBindings); |
| 432 |
429 CheckRuntimeError( | 433 CheckRuntimeError( |
430 errors[0], | 434 errors[0], |
431 extension->id(), | 435 extension->id(), |
432 script_url, | 436 script_url, |
433 false, // not incognito | 437 false, // not incognito |
434 "Error in event handler for browserAction.onClicked: " | 438 "Error in event handler for browserAction.onClicked: " |
435 "ReferenceError: baz is not defined", | 439 "ReferenceError: baz is not defined", |
436 logging::LOG_ERROR, | 440 logging::LOG_ERROR, |
437 extension->url().Resolve(kBackgroundPageName), | 441 extension->url().Resolve(kBackgroundPageName), |
438 6u); | 442 6u); |
439 | 443 |
440 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 444 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
441 | 445 |
442 CheckStackFrame(stack_trace[0], script_url, kAnonymousFunction); | 446 CheckStackFrame(stack_trace[0], script_url, kAnonymousFunction); |
443 CheckStackFrame(stack_trace[1], | 447 CheckStackFrame(stack_trace[1], |
444 "extensions::SafeBuiltins", | 448 "extensions::SafeBuiltins", |
445 std::string("Function.target.") + kAnonymousFunction); | 449 std::string("Function.target.") + kAnonymousFunction); |
446 CheckStackFrame( | 450 CheckStackFrame( |
447 stack_trace[2], kEventBindings, "Event.dispatchToListener"); | 451 stack_trace[2], event_bindings_str, "Event.dispatchToListener"); |
448 CheckStackFrame(stack_trace[3], kEventBindings, "Event.dispatch_"); | 452 CheckStackFrame(stack_trace[3], event_bindings_str, "Event.dispatch_"); |
449 CheckStackFrame(stack_trace[4], kEventBindings, "dispatchArgs"); | 453 CheckStackFrame(stack_trace[4], event_bindings_str, "dispatchArgs"); |
450 CheckStackFrame(stack_trace[5], kEventBindings, "dispatchEvent"); | 454 CheckStackFrame(stack_trace[5], event_bindings_str, "dispatchEvent"); |
451 } | 455 } |
452 | 456 |
453 // Test that we can catch an error for calling an API with improper arguments. | 457 // Test that we can catch an error for calling an API with improper arguments. |
454 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadAPIArgumentsRuntimeError) { | 458 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadAPIArgumentsRuntimeError) { |
455 const Extension* extension = NULL; | 459 const Extension* extension = NULL; |
456 LoadExtensionAndCheckErrors( | 460 LoadExtensionAndCheckErrors( |
457 "bad_api_arguments_runtime_error", | 461 "bad_api_arguments_runtime_error", |
458 kNoFlags, | 462 kNoFlags, |
459 1, // One error: call an API with improper arguments. | 463 1, // One error: call an API with improper arguments. |
460 ACTION_NONE, | 464 ACTION_NONE, |
461 &extension); | 465 &extension); |
462 | 466 |
463 const ErrorConsole::ErrorList& errors = | 467 const ErrorConsole::ErrorList& errors = |
464 error_console()->GetErrorsForExtension(extension->id()); | 468 error_console()->GetErrorsForExtension(extension->id()); |
465 | 469 |
| 470 std::string schema_utils_str = |
| 471 base::StringPrintf("extensions::%s", kSchemaUtils); |
| 472 |
466 CheckRuntimeError( | 473 CheckRuntimeError( |
467 errors[0], | 474 errors[0], |
468 extension->id(), | 475 extension->id(), |
469 kSchemaUtils, // API calls are checked in schemaUtils.js. | 476 schema_utils_str, // API calls are checked in schemaUtils.js. |
470 false, // not incognito | 477 false, // not incognito |
471 "Uncaught Error: Invocation of form " | 478 "Uncaught Error: Invocation of form " |
472 "tabs.get(string, function) doesn't match definition " | 479 "tabs.get(string, function) doesn't match definition " |
473 "tabs.get(integer tabId, function callback)", | 480 "tabs.get(integer tabId, function callback)", |
474 logging::LOG_ERROR, | 481 logging::LOG_ERROR, |
475 extension->url().Resolve(kBackgroundPageName), | 482 extension->url().Resolve(kBackgroundPageName), |
476 1u); | 483 1u); |
477 | 484 |
478 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 485 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
479 ASSERT_EQ(1u, stack_trace.size()); | 486 ASSERT_EQ(1u, stack_trace.size()); |
480 CheckStackFrame(stack_trace[0], | 487 CheckStackFrame(stack_trace[0], |
481 kSchemaUtils, | 488 schema_utils_str, |
482 kAnonymousFunction); | 489 kAnonymousFunction); |
483 } | 490 } |
484 | 491 |
485 // Test that we catch an error when we try to call an API method without | 492 // Test that we catch an error when we try to call an API method without |
486 // permission. | 493 // permission. |
487 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadAPIPermissionsRuntimeError) { | 494 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadAPIPermissionsRuntimeError) { |
488 const Extension* extension = NULL; | 495 const Extension* extension = NULL; |
489 LoadExtensionAndCheckErrors( | 496 LoadExtensionAndCheckErrors( |
490 "bad_api_permissions_runtime_error", | 497 "bad_api_permissions_runtime_error", |
491 kNoFlags, | 498 kNoFlags, |
(...skipping 19 matching lines...) Expand all Loading... |
511 | 518 |
512 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 519 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
513 ASSERT_EQ(1u, stack_trace.size()); | 520 ASSERT_EQ(1u, stack_trace.size()); |
514 CheckStackFrame(stack_trace[0], | 521 CheckStackFrame(stack_trace[0], |
515 script_url, | 522 script_url, |
516 kAnonymousFunction, | 523 kAnonymousFunction, |
517 5u, 1u); | 524 5u, 1u); |
518 } | 525 } |
519 | 526 |
520 } // namespace extensions | 527 } // namespace extensions |
OLD | NEW |