Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/test/data/extensions/api_test/debugger/background.js

Issue 12377047: Add chrome.debugger.getTargets method to discover available debug targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@targets
Patch Set: Rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 var pass = chrome.test.callbackPass; 5 var pass = chrome.test.callbackPass;
6 var fail = chrome.test.callbackFail; 6 var fail = chrome.test.callbackFail;
7 7
8 var tabId; 8 var tabId;
9 var debuggee; 9 var debuggee;
10 var protocolVersion = "1.0"; 10 var protocolVersion = "1.0";
11 11
12 var SILENT_FLAG_REQUIRED = "Cannot attach to this target unless " +
13 "'silent-debugger-extension-api' flag is enabled.";
14
12 chrome.test.runTests([ 15 chrome.test.runTests([
13 16
14 function attachMalformedVersion() { 17 function attachMalformedVersion() {
15 chrome.tabs.getSelected(null, function(tab) { 18 chrome.tabs.getSelected(null, function(tab) {
16 chrome.debugger.attach({tabId: tab.id}, "malformed-version", 19 chrome.debugger.attach({tabId: tab.id}, "malformed-version",
17 fail("Requested protocol version is not supported: malformed-version." )); 20 fail("Requested protocol version is not supported: malformed-version." ));
18 }); 21 });
19 }, 22 },
20 23
21 function attachUnsupportedMinorVersion() { 24 function attachUnsupportedMinorVersion() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 chrome.tabs.remove(tab.id); 102 chrome.tabs.remove(tab.id);
100 }); 103 });
101 }, 104 },
102 105
103 function attachToMissing() { 106 function attachToMissing() {
104 var missingDebuggee = {tabId: -1}; 107 var missingDebuggee = {tabId: -1};
105 chrome.debugger.attach(missingDebuggee, protocolVersion, 108 chrome.debugger.attach(missingDebuggee, protocolVersion,
106 fail("No tab with given id " + missingDebuggee.tabId + ".")); 109 fail("No tab with given id " + missingDebuggee.tabId + "."));
107 }, 110 },
108 111
109 function attachToExtensionWithNoSilentFlag() { 112 function attachToOwnBackgroundPageWithNoSilentFlag() {
110 debuggeeExtension = {extensionId: "foo"}; 113 var ownExtensionId = chrome.extension.getURL('').split('/')[2];
114 debuggeeExtension = {extensionId: ownExtensionId};
111 chrome.debugger.attach(debuggeeExtension, protocolVersion, 115 chrome.debugger.attach(debuggeeExtension, protocolVersion,
112 fail("Cannot attach to an extension unless " + 116 fail(SILENT_FLAG_REQUIRED));
113 "'silent-debugger-extension-api' flag is enabled.")); 117 },
118
119 function createAndDiscoverTab() {
120 chrome.test.listenOnce(chrome.tabs.onUpdated, function () {
121 chrome.debugger.getTargets(function(targets) {
122 var page = targets.filter(
123 function(t) {
124 return t.type == 'page' && t.title == 'Test page';
125 })[0];
126 if (page) {
127 chrome.debugger.attach(
128 {targetId: page.id}, protocolVersion, pass());
129 } else {
130 chrome.test.fail("Cannot discover a newly created tab");
131 }
132 });
133 });
134 chrome.tabs.create({url: "inspected.html"});
135 },
136
137 function discoverBackgroundPageWithNoSilentFlag() {
138 chrome.debugger.getTargets(function(targets) {
139 var target = targets.filter(
140 function(target) { return target.type == 'background_page'})[0];
141 if (target) {
142 chrome.debugger.attach({targetId: target.id}, protocolVersion,
143 fail(SILENT_FLAG_REQUIRED));
144 } else {
145 chrome.test.succeed();
146 }
147 });
114 } 148 }
115 ]); 149 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698