1 // Copyright (c) 2013 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 var pass
= chrome
.test
.callbackPass
;
6 var fail
= chrome
.test
.callbackFail
;
9 var protocolVersion
= "1.1";
11 chrome
.test
.runTests([
14 var extensionId
= chrome
.extension
.getURL('').split('/')[2];
15 debuggee
= {extensionId
: extensionId
};
16 chrome
.debugger.attach(debuggee
, protocolVersion
, pass());
19 function attachToMissing() {
20 var missingDebuggee
= {extensionId
: "foo"};
21 chrome
.debugger.attach(missingDebuggee
, protocolVersion
,
22 fail("No background page with given id " +
23 missingDebuggee
.extensionId
+ "."));
26 function attachAgain() {
27 chrome
.debugger.attach(debuggee
, protocolVersion
,
28 fail("Another debugger is already attached " +
29 "to the background page with id: " + debuggee
.extensionId
+ "."));
33 chrome
.debugger.detach(debuggee
, pass());
36 function detachAgain() {
37 chrome
.debugger.detach(debuggee
,
38 fail("Debugger is not attached to the background page with id: " +
39 debuggee
.extensionId
+ "."));
42 function discoverOwnBackgroundPage() {
43 chrome
.debugger.getTargets(function(targets
) {
44 var target
= targets
.filter(
46 return t
.type
== 'background_page' &&
47 t
.extensionId
== debuggee
.extensionId
&&
48 t
.title
== 'Extension Debugger';
51 chrome
.debugger.attach({targetId
: target
.id
}, protocolVersion
, pass());
53 chrome
.test
.fail("Cannot discover own background page");
58 function discoverWorker() {
59 var workerPort
= new SharedWorker("worker.js").port
;
60 workerPort
.onmessage = function() {
61 chrome
.debugger.getTargets(function(targets
) {
62 var page
= targets
.filter(
63 function(t
) { return t
.type
== 'worker' })[0];
65 chrome
.debugger.attach({targetId
: page
.id
}, protocolVersion
, pass());
67 chrome
.test
.fail("Cannot discover a newly created worker");