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

Side by Side Diff: chrome/test/data/devtools/target_list/background.js

Issue 54333004: [DevTools] Extended RemoteDebuggingTest.RemoteDebugger with additional json protocol tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/data/devtools/target_list/manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 function requestUrl(url, callback) { 5 function requestUrl(url, callback) {
Vladislav Kaznacheev 2013/11/01 11:48:19 This method is always called with an url starting
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
6 var req = new XMLHttpRequest(); 6 var req = new XMLHttpRequest();
7 req.open('GET', url, true); 7 req.open('GET', url, true);
8 req.onload = function() { 8 req.onload = function() {
9 if (req.status == 200) 9 if (req.status == 200)
10 callback(req.responseText); 10 callback(req.responseText);
11 else 11 else
12 req.onerror(); 12 req.onerror();
13 }; 13 };
14 req.onerror = function() { 14 req.onerror = function() {
15 chrome.test.fail('XHR failed: ' + req.status); 15 chrome.test.fail('XHR failed: ' + req.status);
16 }; 16 };
17 req.send(null); 17 req.send(null);
18 } 18 }
19 19
20 var REMOTE_DEBUGGER_HOST = 'localhost:9222'; 20 var REMOTE_DEBUGGER_HOST = 'localhost:9222';
21 21
22 function checkTarget(targets, url, type, opt_title, opt_faviconUrl) { 22 function checkTarget(targets, url, type, opt_title, opt_faviconUrl) {
23 var target = 23 var target =
24 targets.filter(function(t) { return t.url == url }) [0]; 24 targets.filter(function(t) { return t.url == url }) [0];
25 if (!target) 25 if (!target)
26 chrome.test.fail('Cannot find a target with url ' + url); 26 chrome.test.fail('Cannot find a target with url ' + url);
27 27
28 var wsAddress = REMOTE_DEBUGGER_HOST + '/devtools/page/' + target.id; 28 var wsAddress = REMOTE_DEBUGGER_HOST + '/devtools/page/' + target.id;
29 29
30 chrome.test.assertEq( 30 chrome.test.assertEq(
31 '/devtools/devtools.html?ws=' + wsAddress, 31 '/devtools/devtools.html?ws=' + wsAddress,
32 target.devtoolsFrontendUrl); 32 target.devtoolsFrontendUrl);
33 // On some platforms (e.g. Chrome OS) target.faviconUrl might be empty for 33 // On some platforms (e.g. Chrome OS) target.faviconUrl might be empty for
34 // a freshly created tab. Ignore the check then. 34 // a freshly created tab. Ignore the check then.
35 if (target.faviconUrl && opt_faviconUrl) 35 if (opt_faviconUrl)
36 chrome.test.assertEq(opt_faviconUrl, target.faviconUrl); 36 chrome.test.assertEq(opt_faviconUrl, target.faviconUrl);
37 // Sometimes thumbnailUrl is not available for a freshly loaded tab. 37 // Sometimes thumbnailUrl is not available for a freshly loaded tab.
38 if (target.thumbnailUrl) 38 if (target.thumbnailUrl)
39 chrome.test.assertEq('/thumb/' + target.id, target.thumbnailUrl); 39 chrome.test.assertEq('/thumb/' + target.id, target.thumbnailUrl);
40 chrome.test.assertEq(opt_title || target.url, target.title); 40 chrome.test.assertEq(opt_title || target.url, target.title);
41 chrome.test.assertEq(type, target.type); 41 chrome.test.assertEq(type, target.type);
42 chrome.test.assertEq('ws://' + wsAddress, target.webSocketDebuggerUrl); 42 chrome.test.assertEq('ws://' + wsAddress, target.webSocketDebuggerUrl);
43
44 return target;
43 } 45 }
44 46
47 function waitForTab(pred, callback) {
Vladislav Kaznacheev 2013/11/01 11:48:19 'pred' name is cryptic. I needed to read the entir
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
48 var fired = false;
49 function onUpdated(updatedTabId, changeInfo, updatedTab) {
50 if (!pred(updatedTab) && !fired)
51 return;
52
53 chrome.tabs.onUpdated.removeListener(onUpdated);
54 if (!fired) {
55 fired = true;
56 callback(updatedTab);
57 }
58 }
59
60 chrome.tabs.onUpdated.addListener(onUpdated);
61
62 chrome.tabs.query({}, function(tabs) {
63 if (!fired) {
64 for (var i = 0; i < tabs.length; ++i)
65 if (pred(tabs[i])) {
66 fired = true;
67 callback(tabs[i]);
68 }
69 }
70 })
71 }
72
73 function listenOnce(event, func) {
74 var listener = function() {
75 event.removeListener(listener);
76 func.apply(null, arguments)
77 };
78 event.addListener(listener);
79 }
80
81 var extension_target;
Vladislav Kaznacheev 2013/11/01 11:48:19 JS naming convension is extensionTarget
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
82 var extension_tab;
83
45 chrome.test.runTests([ 84 chrome.test.runTests([
46 function discoverTargets() { 85 function discoverTargets() {
47 var testPageUrl = chrome.extension.getURL('test_page.html'); 86 var testPageUrl = chrome.extension.getURL('test_page.html');
48 87
49 function onUpdated() { 88 function onUpdated(updatedTabId) {
50 chrome.tabs.onUpdated.removeListener(onUpdated);
51 requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json', function(text) { 89 requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json', function(text) {
52 var targets = JSON.parse(text); 90 var targets = JSON.parse(text);
91 waitForTab(
92 function(tab) {
93 return tab.id == updatedTabId && tab.status == "complete"
94 },
95 function() {
96 checkTarget(targets, 'about:blank', 'page');
97 checkTarget(targets,
98 chrome.extension.getURL('_generated_background_page.html'),
99 'background_page',
100 'Remote Debugger Test');
101 extension_target = checkTarget(targets,
102 testPageUrl, 'page', 'Test page',
103 chrome.extension.getURL('favicon.png'));
104 chrome.test.succeed();
105 });
106 });
107 }
108 listenOnce(chrome.tabs.onUpdated, onUpdated);
109 chrome.tabs.create({url: testPageUrl});
110 },
111 function versionInfo() {
112 requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json/version',
113 function(text) {
114 var versionInfo = JSON.parse(text);
115 chrome.test.assertEq(versionInfo["Browser"].indexOf("Chrome/"), 0);
Vladislav Kaznacheev 2013/11/01 11:48:19 assert(versionInfo["Browser"].match(/^Chrome\//))
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
116 chrome.test.assertTrue("Protocol-Version" in versionInfo);
117 chrome.test.assertTrue("User-Agent" in versionInfo);
118 chrome.test.assertTrue("WebKit-Version" in versionInfo);
119 chrome.test.succeed();
120 });
121 },
122 function openNewPage() {
Vladislav Kaznacheev 2013/11/01 11:48:19 Insert blank lines between the functions
Vladislav Kaznacheev 2013/11/01 11:48:19 We also need a test for json/new with no url which
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
123 var json;
124 var tab;
125 var pendingCount = 2;
53 126
54 checkTarget(targets, 'about:blank', 'page'); 127 function checkResult() {
55 checkTarget(targets, testPageUrl, 'page', 'Test page', 128 if (--pendingCount)
56 chrome.extension.getURL('favicon.png')); 129 return;
57 checkTarget(targets, 130 chrome.test.assertEq(tab.url, "chrome://version/");
58 chrome.extension.getURL('_generated_background_page.html'), 131 chrome.test.assertEq(json.url, "chrome://version/");
59 'background_page', 132 chrome.test.assertTrue(tab.active);
60 'Remote Debugger Test'); 133 chrome.test.succeed();
134 }
61 135
62 chrome.test.succeed(); 136 function onCreated(createdTab) {
63 }); 137 waitForTab(
138 function(tab) {
139 return tab.id == createdTab.id &&
140 tab.active &&
141 tab.status == "complete";
142 },
143 function(waitedTab) {
Vladislav Kaznacheev 2013/11/01 11:48:19 waitedTab is poor English
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
144 tab = waitedTab;
145 checkResult();
146 });
64 } 147 }
65 chrome.tabs.onUpdated.addListener(onUpdated); 148
66 chrome.tabs.create({url: testPageUrl}); 149 listenOnce(chrome.tabs.onCreated, onCreated);
150
151 requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json/new?chrome://version/',
152 function(text) {
153 json = JSON.parse(text);
154 checkResult();
155 });
156 },
157 function activatePage() {
158 var activationUrl = 'http://' + REMOTE_DEBUGGER_HOST +
159 '/json/activate/' + extension_target.id;
160 requestUrl(activationUrl,
161 function(text) {
162 chrome.test.assertEq(text, "Target activated");
163 waitForTab(
164 function(tab) {
165 return tab.active &&
166 tab.status == "complete" &&
167 tab.title == 'Test page';
168 },
169 function (tab) {
170 extension_tab = tab;
Vladislav Kaznacheev 2013/11/01 11:48:19 Lets save the id only.
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
171 chrome.test.succeed();
172 });
173 });
174 },
175 function closePage() {
176 function onRemoved(tabId) {
177 chrome.test.assertEq(tabId, extension_tab.id);
178 chrome.test.succeed();
179 }
180
181 listenOnce(chrome.tabs.onRemoved, onRemoved);
182
183 var closingUrl = 'http://' + REMOTE_DEBUGGER_HOST +
184 '/json/close/' + extension_target.id
185 requestUrl(closingUrl, function(text) {
186 chrome.test.assertEq(text, "Target is closing");
187 });
67 } 188 }
68 ]); 189 ]);
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/devtools/target_list/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698