Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/content_scripts/policy/background.js |
| diff --git a/chrome/test/data/extensions/api_test/content_scripts/policy/background.js b/chrome/test/data/extensions/api_test/content_scripts/policy/background.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e036376056267d44da0b130b7d03d4c4b5dee1f3 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/content_scripts/policy/background.js |
| @@ -0,0 +1,57 @@ |
| +// 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.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var assertEq = chrome.test.assertEq; |
|
Devlin
2017/04/07 00:40:27
needed?
nrpeter
2017/04/12 23:35:45
Done.
|
| +var assertTrue = chrome.test.assertTrue; |
|
Devlin
2017/04/07 00:40:27
needed?
nrpeter
2017/04/12 23:35:45
Done.
|
| +var pass = chrome.test.callbackPass; |
| +var callbackFail = chrome.test.callbackFail; |
| +var listenForever = chrome.test.listenForever; |
| + |
| +var testTabId; |
|
Devlin
2017/04/07 00:40:27
needed?
nrpeter
2017/04/12 23:35:45
Done.
|
| +var port; |
| + |
| +function testUrl(domain) { |
| + return 'http://' + domain + ':' + port + |
| + '/extensions/test_file.html'; |
| +} |
| + |
| +function error(domain) { |
| + return 'Cannot access contents of url "' + testUrl(domain) + '".' + |
| + ' Extension manifest must request permission to access this host.'; |
| +} |
| + |
| +// Creates a new tab, navigated to the specified |domain|. |
| +function createTestTab(domain, callback) { |
| + var createdTabId = -1; |
| + var done = listenForever( |
| + chrome.tabs.onUpdated, |
| + function(tabId, changeInfo, tab) { |
| + if (tabId == createdTabId && changeInfo.status != 'loading') { |
| + callback(tab); |
| + done(); |
| + } |
| + }); |
| + |
| + chrome.tabs.create({url: testUrl(domain)}, pass(function(tab) { |
| + createdTabId = tab.id; |
| + })); |
| +} |
| + |
| +chrome.test.getConfig(function(config) { |
| + port = config.testServer.port; |
| + chrome.test.runTests([ |
| + |
| + // Make sure we can't inject a script into a policy blocked host. |
| + function policyBlocksInjection() { |
| + createTestTab('example.com', pass(function(tab) { |
| + testTabId = tab.id; |
| + chrome.tabs.executeScript( |
| + tab.id, {code: 'document.title = "success"'}, |
| + callbackFail( |
| + 'This page cannot be scripted due to ' + |
| + 'an ExtensionsSettings policy.')); |
| + })); |
| + }, |
| + ]); |
| +}); |