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

Unified 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: Added test. Fixed comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/devtools/target_list/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/devtools/target_list/background.js
diff --git a/chrome/test/data/devtools/target_list/background.js b/chrome/test/data/devtools/target_list/background.js
index 60a6ca072c988215a837529dee7f90968daecd00..946909de439bca2bac488e69afc28b23141a6815 100644
--- a/chrome/test/data/devtools/target_list/background.js
+++ b/chrome/test/data/devtools/target_list/background.js
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-function requestUrl(url, callback) {
+var REMOTE_DEBUGGER_HOST = 'localhost:9222';
+
+function requestUrl(path, callback) {
var req = new XMLHttpRequest();
- req.open('GET', url, true);
+ req.open('GET', 'http://' + REMOTE_DEBUGGER_HOST + path, true);
Vladislav Kaznacheev 2013/11/01 14:00:52 Lets move '/json/' in here as well
Dmitry Zvorygin 2013/11/01 14:48:37 Decided to leave it as is.
req.onload = function() {
if (req.status == 200)
callback(req.responseText);
@@ -17,7 +19,6 @@ function requestUrl(url, callback) {
req.send(null);
}
-var REMOTE_DEBUGGER_HOST = 'localhost:9222';
function checkTarget(targets, url, type, opt_title, opt_faviconUrl) {
var target =
@@ -32,7 +33,7 @@ function checkTarget(targets, url, type, opt_title, opt_faviconUrl) {
target.devtoolsFrontendUrl);
// On some platforms (e.g. Chrome OS) target.faviconUrl might be empty for
// a freshly created tab. Ignore the check then.
- if (target.faviconUrl && opt_faviconUrl)
+ if (opt_faviconUrl)
chrome.test.assertEq(opt_faviconUrl, target.faviconUrl);
// Sometimes thumbnailUrl is not available for a freshly loaded tab.
if (target.thumbnailUrl)
@@ -40,29 +41,158 @@ function checkTarget(targets, url, type, opt_title, opt_faviconUrl) {
chrome.test.assertEq(opt_title || target.url, target.title);
chrome.test.assertEq(type, target.type);
chrome.test.assertEq('ws://' + wsAddress, target.webSocketDebuggerUrl);
+
+ return target;
+}
+
+function waitForTab(filter, callback) {
+ var fired = false;
+ function onUpdated(updatedTabId, changeInfo, updatedTab) {
+ if (!filter(updatedTab) && !fired)
+ return;
+
+ chrome.tabs.onUpdated.removeListener(onUpdated);
+ if (!fired) {
+ fired = true;
+ callback(updatedTab);
+ }
+ }
+
+ chrome.tabs.onUpdated.addListener(onUpdated);
+
+ chrome.tabs.query({}, function(tabs) {
+ if (!fired) {
+ for (var i = 0; i < tabs.length; ++i)
+ if (filter(tabs[i])) {
+ fired = true;
+ callback(tabs[i]);
+ }
+ }
+ })
Vladislav Kaznacheev 2013/11/01 14:00:52 ; after the statement
Dmitry Zvorygin 2013/11/01 14:48:37 Done.
}
+function listenOnce(event, func) {
+ var listener = function() {
+ event.removeListener(listener);
+ func.apply(null, arguments)
+ };
+ event.addListener(listener);
+}
+
+function runNewPageTest(devtoolsUrl, expectedUrl) {
+ var json;
+ var newTab;
+ var pendingCount = 2;
+
+ function checkResult() {
+ if (--pendingCount)
+ return;
+ chrome.test.assertEq(newTab.url, expectedUrl);
+ chrome.test.assertEq(json.url, expectedUrl);
+ chrome.test.assertTrue(newTab.active);
+ chrome.test.succeed();
+ }
+
+ function onCreated(createdTab) {
+ waitForTab(
+ function(tab) {
+ return tab.id == createdTab.id &&
+ tab.active &&
+ tab.status == "complete";
+ },
+ function(tab) {
+ newTab = tab;
+ checkResult();
+ });
+ }
+
+ listenOnce(chrome.tabs.onCreated, onCreated);
+
+ requestUrl(devtoolsUrl,
+ function(text) {
+ json = JSON.parse(text);
+ checkResult();
+ });
+}
+
+var extensionTarget;
Vladislav Kaznacheev 2013/11/01 14:00:52 you forgot to change this to extensionTargetId
Dmitry Zvorygin 2013/11/01 14:48:37 Done.
+var extensionTabId;
+
chrome.test.runTests([
function discoverTargets() {
var testPageUrl = chrome.extension.getURL('test_page.html');
- function onUpdated() {
- chrome.tabs.onUpdated.removeListener(onUpdated);
- requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json', function(text) {
+ function onUpdated(updatedTabId) {
+ requestUrl('/json', function(text) {
var targets = JSON.parse(text);
+ waitForTab(
+ function(tab) {
+ return tab.id == updatedTabId && tab.status == "complete"
+ },
+ function() {
+ checkTarget(targets, 'about:blank', 'page');
+ checkTarget(targets,
+ chrome.extension.getURL('_generated_background_page.html'),
+ 'background_page',
+ 'Remote Debugger Test');
+ extensionTarget = checkTarget(targets,
+ testPageUrl, 'page', 'Test page',
+ chrome.extension.getURL('favicon.png'));
+ chrome.test.succeed();
+ });
+ });
+ }
+ listenOnce(chrome.tabs.onUpdated, onUpdated);
+ chrome.tabs.create({url: testPageUrl});
+ },
- checkTarget(targets, 'about:blank', 'page');
- checkTarget(targets, testPageUrl, 'page', 'Test page',
- chrome.extension.getURL('favicon.png'));
- checkTarget(targets,
- chrome.extension.getURL('_generated_background_page.html'),
- 'background_page',
- 'Remote Debugger Test');
+ function versionInfo() {
+ requestUrl('/json/version',
+ function(text) {
+ var versionInfo = JSON.parse(text);
+ chrome.test.assertTrue(/^Chrome\//.test(versionInfo["Browser"]));
+ chrome.test.assertTrue("Protocol-Version" in versionInfo);
+ chrome.test.assertTrue("User-Agent" in versionInfo);
+ chrome.test.assertTrue("WebKit-Version" in versionInfo);
+ chrome.test.succeed();
+ });
+ },
- chrome.test.succeed();
- });
+ function newSpecificPage() {
+ runNewPageTest('/json/new?chrome://version/', "chrome://version/");
+ },
+
+ function newDefaultPage() {
+ runNewPageTest('/json/new', "about:blank");
+ },
+
+ function activatePage() {
+ requestUrl('/json/activate/' + extensionTarget.id,
+ function(text) {
+ chrome.test.assertEq(text, "Target activated");
+ waitForTab(
+ function(tab) {
+ return tab.active &&
+ tab.status == "complete" &&
+ tab.title == 'Test page';
+ },
+ function (tab) {
+ extensionTabId = tab.id;
+ chrome.test.succeed();
+ });
+ });
+ },
+
+ function closePage() {
+ function onRemoved(tabId) {
+ chrome.test.assertEq(tabId, extensionTabId);
+ chrome.test.succeed();
}
- chrome.tabs.onUpdated.addListener(onUpdated);
- chrome.tabs.create({url: testPageUrl});
+
+ listenOnce(chrome.tabs.onRemoved, onRemoved);
+
+ requestUrl('/json/close/' + extensionTarget.id, function(text) {
+ chrome.test.assertEq(text, "Target is closing");
+ });
}
]);
« 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