1 // 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.
5 function createTestFunction(expected_message
) {
7 function onDebuggerEvent(debuggee
, method
, params
) {
8 if (debuggee
.tabId
== tab
.id
&& method
== 'Console.messageAdded') {
9 if (params
.message
.text
.indexOf(expected_message
) > -1) {
10 chrome
.debugger.onEvent
.removeListener(onDebuggerEvent
);
11 chrome
.test
.succeed();
15 chrome
.debugger.onEvent
.addListener(onDebuggerEvent
);
16 chrome
.debugger.attach({ tabId
: tab
.id
}, "1.1", function() {
17 // Enabling console provides both stored and new messages via the
18 // Console.messageAdded event.
19 chrome
.debugger.sendCommand({ tabId
: tab
.id
}, "Console.enable");
24 chrome
.test
.runTests([
25 function testExceptionInExtensionPage() {
27 {url
: chrome
.runtime
.getURL('extension_page.html')},
28 createTestFunction('Exception thrown in extension page.'));
31 function testExceptionInInjectedScript() {
32 function injectScriptAndSendMessage(tab
) {
33 chrome
.tabs
.executeScript(
35 { file
: 'content_script.js' },
37 createTestFunction('Exception thrown in injected script.')(tab
);
41 chrome
.test
.getConfig(function(config
) {
43 'http://localhost:PORT/extensions/test_file.html'
44 .replace(/PORT/, config
.testServer
.port
);
46 chrome
.tabs
.create({ url
: test_url
}, injectScriptAndSendMessage
);