OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 var pass = chrome.test.callbackPass; |
| 6 var callbackFail = chrome.test.callbackFail; |
| 7 var listenForever = chrome.test.listenForever; |
| 8 |
| 9 var port; |
| 10 |
| 11 function testUrl(domain) { |
| 12 return 'http://' + domain + ':' + port + |
| 13 '/extensions/test_file.html'; |
| 14 } |
| 15 |
| 16 function error(domain) { |
| 17 return 'Cannot access contents of url "' + testUrl(domain) + '".' + |
| 18 ' Extension manifest must request permission to access this host.'; |
| 19 } |
| 20 |
| 21 // Creates a new tab, navigated to the specified |domain|. |
| 22 function createTestTab(domain, callback) { |
| 23 var createdTabId = -1; |
| 24 var done = listenForever( |
| 25 chrome.tabs.onUpdated, |
| 26 function(tabId, changeInfo, tab) { |
| 27 if (tabId == createdTabId && changeInfo.status != 'loading') { |
| 28 callback(tab); |
| 29 done(); |
| 30 } |
| 31 }); |
| 32 |
| 33 chrome.tabs.create({url: testUrl(domain)}, pass(function(tab) { |
| 34 createdTabId = tab.id; |
| 35 })); |
| 36 } |
| 37 |
| 38 chrome.test.getConfig(function(config) { |
| 39 port = config.testServer.port; |
| 40 chrome.test.runTests([ |
| 41 |
| 42 // Make sure we can't inject a script into a policy blocked host. |
| 43 function policyBlocksInjection() { |
| 44 createTestTab('example.com', pass(function(tab) { |
| 45 chrome.tabs.executeScript( |
| 46 tab.id, {code: 'document.title = "success"'}, |
| 47 callbackFail( |
| 48 'This page cannot be scripted due to ' + |
| 49 'an ExtensionsSettings policy.')); |
| 50 })); |
| 51 }, |
| 52 ]); |
| 53 }); |
OLD | NEW |