Chromium Code Reviews| 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 function canXhr(url) { | |
|
not at google - send to devlin
2015/02/05 00:16:13
Would be good to test iframes in here somewhere as
Devlin
2015/02/05 19:54:50
Done.
| |
| 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; | |
| 22 } | |
| 23 return success; | |
| 24 } | |
| 25 | |
| 13 chrome.browserAction.onClicked.addListener(function() { | 26 chrome.browserAction.onClicked.addListener(function() { |
| 14 chrome.tabs.executeScript({ code: 'true' }, callbackPass()); | 27 chrome.tabs.executeScript({ code: 'true' }, callbackPass()); |
| 15 chrome.automation.getTree(callbackPass(function(rootNode) { | 28 |
| 16 assertFalse(rootNode == undefined); | 29 chrome.tabs.query({active:true}, function(tabs) { |
|
not at google - send to devlin
2015/02/05 00:16:13
no need for query, browserAction.onClicked takes t
Devlin
2015/02/05 19:54:50
Done.
| |
| 17 assertEq(RoleType.rootWebArea, rootNode.role); | 30 assertTrue(canXhr(tabs[0].url)); |
| 18 chrome.test.succeed(); | 31 |
| 19 })); | 32 chrome.automation.getTree(callbackPass(function(rootNode) { |
| 33 assertFalse(rootNode == undefined); | |
| 34 assertEq(RoleType.rootWebArea, rootNode.role); | |
| 35 chrome.test.succeed(); | |
| 36 })); | |
| 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 assertFalse(canXhr(details.url)); | |
| 30 }); | 50 }); |
| OLD | NEW |