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

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: Created 7 years, 2 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 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..02e43f2bc353dc495934a057bde655bac1c3848b 100644
--- a/chrome/test/data/devtools/target_list/background.js
+++ b/chrome/test/data/devtools/target_list/background.js
@@ -32,7 +32,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 +40,150 @@ 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(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.
+ var fired = false;
+ function onUpdated(updatedTabId, changeInfo, updatedTab) {
+ if (!pred(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 (pred(tabs[i])) {
+ fired = true;
+ callback(tabs[i]);
+ }
+ }
+ })
+}
+
+function listenOnce(event, func) {
+ var listener = function() {
+ event.removeListener(listener);
+ func.apply(null, arguments)
+ };
+ event.addListener(listener);
}
+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.
+var extension_tab;
+
chrome.test.runTests([
function discoverTargets() {
var testPageUrl = chrome.extension.getURL('test_page.html');
- function onUpdated() {
- chrome.tabs.onUpdated.removeListener(onUpdated);
+ function onUpdated(updatedTabId) {
requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/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');
+ extension_target = checkTarget(targets,
+ testPageUrl, 'page', 'Test page',
+ chrome.extension.getURL('favicon.png'));
+ chrome.test.succeed();
+ });
+ });
+ }
+ listenOnce(chrome.tabs.onUpdated, onUpdated);
+ chrome.tabs.create({url: testPageUrl});
+ },
+ function versionInfo() {
+ requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json/version',
+ function(text) {
+ var versionInfo = JSON.parse(text);
+ 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.
+ chrome.test.assertTrue("Protocol-Version" in versionInfo);
+ chrome.test.assertTrue("User-Agent" in versionInfo);
+ chrome.test.assertTrue("WebKit-Version" in versionInfo);
+ chrome.test.succeed();
+ });
+ },
+ 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.
+ var json;
+ var tab;
+ var pendingCount = 2;
- 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 checkResult() {
+ if (--pendingCount)
+ return;
+ chrome.test.assertEq(tab.url, "chrome://version/");
+ chrome.test.assertEq(json.url, "chrome://version/");
+ chrome.test.assertTrue(tab.active);
+ chrome.test.succeed();
+ }
- chrome.test.succeed();
- });
+ function onCreated(createdTab) {
+ waitForTab(
+ function(tab) {
+ return tab.id == createdTab.id &&
+ tab.active &&
+ tab.status == "complete";
+ },
+ function(waitedTab) {
Vladislav Kaznacheev 2013/11/01 11:48:19 waitedTab is poor English
Dmitry Zvorygin 2013/11/01 13:49:36 Done.
+ tab = waitedTab;
+ checkResult();
+ });
}
- chrome.tabs.onUpdated.addListener(onUpdated);
- chrome.tabs.create({url: testPageUrl});
+
+ listenOnce(chrome.tabs.onCreated, onCreated);
+
+ requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json/new?chrome://version/',
+ function(text) {
+ json = JSON.parse(text);
+ checkResult();
+ });
+ },
+ function activatePage() {
+ var activationUrl = 'http://' + REMOTE_DEBUGGER_HOST +
+ '/json/activate/' + extension_target.id;
+ requestUrl(activationUrl,
+ function(text) {
+ chrome.test.assertEq(text, "Target activated");
+ waitForTab(
+ function(tab) {
+ return tab.active &&
+ tab.status == "complete" &&
+ tab.title == 'Test page';
+ },
+ function (tab) {
+ 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.
+ chrome.test.succeed();
+ });
+ });
+ },
+ function closePage() {
+ function onRemoved(tabId) {
+ chrome.test.assertEq(tabId, extension_tab.id);
+ chrome.test.succeed();
+ }
+
+ listenOnce(chrome.tabs.onRemoved, onRemoved);
+
+ var closingUrl = 'http://' + REMOTE_DEBUGGER_HOST +
+ '/json/close/' + extension_target.id
+ requestUrl(closingUrl, 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