1 // Copyright (c) 2012 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 var assertEq = chrome.test.assertEq;
6 var assertFalse = chrome.test.assertFalse;
7 var assertTrue = chrome.test.assertTrue;
8 var callbackFail = chrome.test.callbackFail;
9 var callbackPass = chrome.test.callbackPass;
11 var RoleType = chrome.automation.RoleType;
13 function canXhr(url) {
14 assertFalse(url == null);
15 var xhr = new XMLHttpRequest();
16 xhr.open('GET', url, false);
21 assertEq('NetworkError', e.name);
28 var iframeDone = null;
30 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
31 if (request.message == 'xhr') {
32 sendResponse({url: cachedUrl});
34 assertTrue(request.success);
39 var iframeUrl = chrome.extension.getURL('iframe.html');
41 'var iframe = document.createElement("iframe");\n' +
42 'iframe.src = "' + iframeUrl + '";\n' +
43 'document.body.appendChild(iframe);\n';
45 chrome.browserAction.onClicked.addListener(function(tab) {
46 iframeDone = chrome.test.callbackAdded();
48 chrome.tabs.executeScript({ code: injectIframe }, callbackPass());
49 assertTrue(canXhr(tab.url));
51 chrome.automation.getTree(callbackPass(function(rootNode) {
52 assertFalse(rootNode == undefined);
53 assertEq(RoleType.rootWebArea, rootNode.role);
57 chrome.webNavigation.onCompleted.addListener(function(details) {
58 chrome.tabs.executeScript({ code: 'true' }, callbackFail(
59 'Cannot access contents of url "' + details.url +
60 '". Extension manifest must request permission to access this host.'));
62 chrome.automation.getTree(callbackFail(
63 'Cannot request automation tree on url "' + details.url +
64 '". Extension manifest must request permission to access this host.'));
66 assertFalse(canXhr(details.url));