| 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..7376923be897ad8ac4d4e62f4b6e76580e3973b7
|
| --- /dev/null
|
| +++ b/chrome/test/data/extensions/api_test/content_scripts/policy/background.js
|
| @@ -0,0 +1,53 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +var pass = chrome.test.callbackPass;
|
| +var callbackFail = chrome.test.callbackFail;
|
| +var listenForever = chrome.test.listenForever;
|
| +
|
| +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) {
|
| + chrome.tabs.executeScript(
|
| + tab.id, {code: 'document.title = "success"'},
|
| + callbackFail(
|
| + 'This page cannot be scripted due to ' +
|
| + 'an ExtensionsSettings policy.'));
|
| + }));
|
| + },
|
| + ]);
|
| +});
|
|
|