Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
|
Devlin
2017/04/07 00:40:27
no (c)
nrpeter
2017/04/12 23:35:45
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var assertEq = chrome.test.assertEq; | |
|
Devlin
2017/04/07 00:40:27
needed?
nrpeter
2017/04/12 23:35:45
Done.
| |
| 6 var assertTrue = chrome.test.assertTrue; | |
|
Devlin
2017/04/07 00:40:27
needed?
nrpeter
2017/04/12 23:35:45
Done.
| |
| 7 var pass = chrome.test.callbackPass; | |
| 8 var callbackFail = chrome.test.callbackFail; | |
| 9 var listenForever = chrome.test.listenForever; | |
| 10 | |
| 11 var testTabId; | |
|
Devlin
2017/04/07 00:40:27
needed?
nrpeter
2017/04/12 23:35:45
Done.
| |
| 12 var port; | |
| 13 | |
| 14 function testUrl(domain) { | |
| 15 return 'http://' + domain + ':' + port + | |
| 16 '/extensions/test_file.html'; | |
| 17 } | |
| 18 | |
| 19 function error(domain) { | |
| 20 return 'Cannot access contents of url "' + testUrl(domain) + '".' + | |
| 21 ' Extension manifest must request permission to access this host.'; | |
| 22 } | |
| 23 | |
| 24 // Creates a new tab, navigated to the specified |domain|. | |
| 25 function createTestTab(domain, callback) { | |
| 26 var createdTabId = -1; | |
| 27 var done = listenForever( | |
| 28 chrome.tabs.onUpdated, | |
| 29 function(tabId, changeInfo, tab) { | |
| 30 if (tabId == createdTabId && changeInfo.status != 'loading') { | |
| 31 callback(tab); | |
| 32 done(); | |
| 33 } | |
| 34 }); | |
| 35 | |
| 36 chrome.tabs.create({url: testUrl(domain)}, pass(function(tab) { | |
| 37 createdTabId = tab.id; | |
| 38 })); | |
| 39 } | |
| 40 | |
| 41 chrome.test.getConfig(function(config) { | |
| 42 port = config.testServer.port; | |
| 43 chrome.test.runTests([ | |
| 44 | |
| 45 // Make sure we can't inject a script into a policy blocked host. | |
| 46 function policyBlocksInjection() { | |
| 47 createTestTab('example.com', pass(function(tab) { | |
| 48 testTabId = tab.id; | |
| 49 chrome.tabs.executeScript( | |
| 50 tab.id, {code: 'document.title = "success"'}, | |
| 51 callbackFail( | |
| 52 'This page cannot be scripted due to ' + | |
| 53 'an ExtensionsSettings policy.')); | |
| 54 })); | |
| 55 }, | |
| 56 ]); | |
| 57 }); | |
| OLD | NEW |