[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / active_tab / background.js
blob74e587b41ea73344d70493959c2fdddb1a9a9232
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);
17 var success = true;
18 try {
19 xhr.send();
20 } catch(e) {
21 assertEq('NetworkError', e.name);
22 success = false;
24 return success;
27 var cachedUrl = null;
28 var iframeDone = null;
30 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
31 if (request.message == 'xhr') {
32 sendResponse({url: cachedUrl});
33 } else {
34 assertTrue(request.success);
35 iframeDone();
37 });
39 var iframeUrl = chrome.extension.getURL('iframe.html');
40 var injectIframe =
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();
47 cachedUrl = tab.url;
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);
54 }));
55 });
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));
67 });