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 function requestUrl(url, callback) {
6 var req = new XMLHttpRequest();
7 req.open('GET', url, true);
8 req.onload = function() {
10 callback(req.responseText);
14 req.onerror = function() {
15 chrome.test.fail('XHR failed: ' + req.status);
20 var REMOTE_DEBUGGER_HOST = 'localhost:9222';
22 function checkTarget(targets, url, type, opt_title, opt_faviconUrl) {
24 targets.filter(function(t) { return t.url == url }) [0];
26 chrome.test.fail('Cannot find a target with url ' + url);
28 var wsAddress = REMOTE_DEBUGGER_HOST + '/devtools/page/' + target.id;
31 '/devtools/devtools.html?ws=' + wsAddress,
32 target.devtoolsFrontendUrl);
33 // On some platforms (e.g. Chrome OS) target.faviconUrl might be empty for
34 // a freshly created tab. Ignore the check then.
35 if (target.faviconUrl && opt_faviconUrl)
36 chrome.test.assertEq(opt_faviconUrl, target.faviconUrl);
37 // Sometimes thumbnailUrl is not available for a freshly loaded tab.
38 if (target.thumbnailUrl)
39 chrome.test.assertEq('/thumb/' + target.id, target.thumbnailUrl);
40 chrome.test.assertEq(opt_title || target.url, target.title);
41 chrome.test.assertEq(type, target.type);
42 chrome.test.assertEq('ws://' + wsAddress, target.webSocketDebuggerUrl);
45 chrome.test.runTests([
46 function discoverTargets() {
47 var testPageUrl = chrome.extension.getURL('test_page.html');
49 function onUpdated() {
50 chrome.tabs.onUpdated.removeListener(onUpdated);
51 requestUrl('http://' + REMOTE_DEBUGGER_HOST + '/json', function(text) {
52 var targets = JSON.parse(text);
54 checkTarget(targets, 'about:blank', 'page');
55 checkTarget(targets, testPageUrl, 'page', 'Test page',
56 chrome.extension.getURL('favicon.png'));
58 chrome.extension.getURL('_generated_background_page.html'),
60 'Remote Debugger Test');
62 chrome.test.succeed();
65 chrome.tabs.onUpdated.addListener(onUpdated);
66 chrome.tabs.create({url: testPageUrl});