OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var assertEq = chrome.test.assertEq; | 5 var assertEq = chrome.test.assertEq; |
6 var assertFalse = chrome.test.assertFalse; | 6 var assertFalse = chrome.test.assertFalse; |
7 var assertTrue = chrome.test.assertTrue; | 7 var assertTrue = chrome.test.assertTrue; |
8 var callbackFail = chrome.test.callbackFail; | 8 var callbackFail = chrome.test.callbackFail; |
9 var callbackPass = chrome.test.callbackPass; | 9 var callbackPass = chrome.test.callbackPass; |
10 | 10 |
11 var RoleType = chrome.automation.RoleType; | 11 var RoleType = chrome.automation.RoleType; |
12 | 12 |
13 var url = null; | |
14 | |
15 function canXhr() { | |
16 assertFalse(url == null); | |
17 var xhr = new XMLHttpRequest(); | |
18 xhr.open('GET', url, false); | |
19 var success = true; | |
20 try { | |
21 xhr.send(); | |
22 } catch(e) { | |
23 success = false; | |
24 } | |
25 return success; | |
26 } | |
27 | |
13 chrome.browserAction.onClicked.addListener(function() { | 28 chrome.browserAction.onClicked.addListener(function() { |
14 chrome.tabs.executeScript({ code: 'true' }, callbackPass()); | 29 chrome.tabs.executeScript({ code: 'true' }, callbackPass()); |
30 | |
31 assertTrue(canXhr(url)); | |
not at google - send to devlin
2015/02/03 19:29:12
canXhr() doesn't take a URL, but it seems like thi
Devlin
2015/02/04 22:26:02
It was my circumvention around doing an async tabs
| |
32 | |
15 chrome.automation.getTree(callbackPass(function(rootNode) { | 33 chrome.automation.getTree(callbackPass(function(rootNode) { |
16 assertFalse(rootNode == undefined); | 34 assertFalse(rootNode == undefined); |
17 assertEq(RoleType.rootWebArea, rootNode.role); | 35 assertEq(RoleType.rootWebArea, rootNode.role); |
18 chrome.test.succeed(); | 36 chrome.test.succeed(); |
19 })); | 37 })); |
20 }); | 38 }); |
21 | 39 |
22 chrome.webNavigation.onCompleted.addListener(function(details) { | 40 chrome.webNavigation.onCompleted.addListener(function(details) { |
23 chrome.tabs.executeScript({ code: 'true' }, callbackFail( | 41 chrome.tabs.executeScript({ code: 'true' }, callbackFail( |
24 'Cannot access contents of url "' + details.url + | 42 'Cannot access contents of url "' + details.url + |
25 '". Extension manifest must request permission to access this host.')); | 43 '". Extension manifest must request permission to access this host.')); |
26 | 44 |
27 chrome.automation.getTree(callbackFail( | 45 chrome.automation.getTree(callbackFail( |
28 'Cannot request automation tree on url "' + details.url + | 46 'Cannot request automation tree on url "' + details.url + |
29 '". Extension manifest must request permission to access this host.')); | 47 '". Extension manifest must request permission to access this host.')); |
48 | |
49 url = details.url; | |
50 assertFalse(canXhr()); | |
30 }); | 51 }); |
OLD | NEW |