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 chrome.browserAction.onClicked.addListener(function() { | 13 function canXhr(url) { |
14 chrome.tabs.executeScript({ code: 'true' }, callbackPass()); | 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 success = false; | |
not at google - send to devlin
2015/02/05 22:40:22
Okie could you also assert that e.name == 'Network
Devlin
2015/02/06 18:59:53
Good idea. Done.
| |
22 } | |
23 return success; | |
24 } | |
25 | |
26 var cachedUrl = null; | |
27 var iframeDone = null; | |
28 | |
29 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | |
30 if (request.message == 'xhr') { | |
31 sendResponse({url: cachedUrl}); | |
32 } else { | |
33 assertTrue(request.success); | |
34 iframeDone(); | |
35 } | |
36 }); | |
37 | |
38 var iframeUrl = chrome.extension.getURL('iframe.html'); | |
39 var injectIframe = | |
not at google - send to devlin
2015/02/05 22:40:22
CSP SchmeeSP
| |
40 'var iframe = document.createElement("iframe");\n' + | |
41 'iframe.src = "' + iframeUrl + '";\n' + | |
42 'document.body.appendChild(iframe);\n'; | |
43 | |
44 chrome.browserAction.onClicked.addListener(function(tab) { | |
45 iframeDone = chrome.test.callbackAdded(); | |
46 cachedUrl = tab.url; | |
47 chrome.tabs.executeScript({ code: injectIframe }, callbackPass()); | |
48 assertTrue(canXhr(tab.url)); | |
49 | |
15 chrome.automation.getTree(callbackPass(function(rootNode) { | 50 chrome.automation.getTree(callbackPass(function(rootNode) { |
16 assertFalse(rootNode == undefined); | 51 assertFalse(rootNode == undefined); |
17 assertEq(RoleType.rootWebArea, rootNode.role); | 52 assertEq(RoleType.rootWebArea, rootNode.role); |
18 chrome.test.succeed(); | |
19 })); | 53 })); |
20 }); | 54 }); |
21 | 55 |
22 chrome.webNavigation.onCompleted.addListener(function(details) { | 56 chrome.webNavigation.onCompleted.addListener(function(details) { |
23 chrome.tabs.executeScript({ code: 'true' }, callbackFail( | 57 chrome.tabs.executeScript({ code: 'true' }, callbackFail( |
24 'Cannot access contents of url "' + details.url + | 58 'Cannot access contents of url "' + details.url + |
25 '". Extension manifest must request permission to access this host.')); | 59 '". Extension manifest must request permission to access this host.')); |
26 | 60 |
27 chrome.automation.getTree(callbackFail( | 61 chrome.automation.getTree(callbackFail( |
28 'Cannot request automation tree on url "' + details.url + | 62 'Cannot request automation tree on url "' + details.url + |
29 '". Extension manifest must request permission to access this host.')); | 63 '". Extension manifest must request permission to access this host.')); |
64 | |
65 assertFalse(canXhr(details.url)); | |
30 }); | 66 }); |
OLD | NEW |