Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/test/data/extensions/api_test/content_scripts/permissions/background.js

Issue 1414223005: Remove URLs from chrome.tabs.executeScript permission warning. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 assertTrue = chrome.test.assertTrue; 6 var assertTrue = chrome.test.assertTrue;
7 var pass = chrome.test.callbackPass; 7 var pass = chrome.test.callbackPass;
8 var callbackFail = chrome.test.callbackFail; 8 var callbackFail = chrome.test.callbackFail;
9 var listenForever = chrome.test.listenForever; 9 var listenForever = chrome.test.listenForever;
10 10
11 var testTabId; 11 var testTabId;
12 var port; 12 var port;
13 13
14 function testUrl(domain) { 14 function testUrl(domain) {
15 return 'http://' + domain + ':' + port + 15 return 'http://' + domain + ':' + port +
16 '/extensions/test_file.html'; 16 '/extensions/test_file.html';
17 } 17 }
18 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|. 19 // Creates a new tab, navigated to the specified |domain|.
25 function createTestTab(domain, callback) { 20 function createTestTab(domain, callback) {
26 var createdTabId = -1; 21 var createdTabId = -1;
27 var done = listenForever( 22 var done = listenForever(
28 chrome.tabs.onUpdated, 23 chrome.tabs.onUpdated,
29 function(tabId, changeInfo, tab) { 24 function(tabId, changeInfo, tab) {
30 if (tabId == createdTabId && changeInfo.status != 'loading') { 25 if (tabId == createdTabId && changeInfo.status != 'loading') {
31 callback(tab); 26 callback(tab);
32 done(); 27 done();
33 } 28 }
34 }); 29 });
35 30
36 chrome.tabs.create({url: testUrl(domain)}, pass(function(tab) { 31 chrome.tabs.create({url: testUrl(domain)}, pass(function(tab) {
37 createdTabId = tab.id; 32 createdTabId = tab.id;
38 })); 33 }));
39 } 34 }
40 35
41 chrome.test.getConfig(function(config) { 36 chrome.test.getConfig(function(config) {
42 port = config.testServer.port; 37 port = config.testServer.port;
43 chrome.test.runTests([ 38 chrome.test.runTests([
44 39
45 // Before enabling the optional host permission, we shouldn't be able to 40 // Before enabling the optional host permission, we shouldn't be able to
46 // inject content scripts. 41 // inject content scripts.
47 function noAccess() { 42 function noAccess() {
48 createTestTab('a.com', pass(function(tab) { 43 createTestTab('a.com', pass(function(tab) {
49 testTabId = tab.id; 44 testTabId = tab.id;
50 chrome.tabs.executeScript( 45 chrome.tabs.executeScript(
51 tab.id, {code: 'document.title = "success"'}, 46 tab.id, {code: 'document.title = "success"'},
52 callbackFail(error('a.com'))); 47 callbackFail('Cannot access contents of a page. ' +
48 'Extension manifest must request permission to access ' +
49 'the respective host.'));
53 })); 50 }));
54 }, 51 },
55 52
56 // Add the host permission and see if we can inject a content script into 53 // Add the host permission and see if we can inject a content script into
57 // existing and new tabs. 54 // existing and new tabs.
58 function addPermission() { 55 function addPermission() {
59 chrome.permissions.request( 56 chrome.permissions.request(
60 {origins: ["http://*/*"]}, 57 {origins: ["http://*/*"]},
61 pass(function(granted) { 58 pass(function(granted) {
62 assertTrue(granted); 59 assertTrue(granted);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 tab.id, {code: 'document.title = "success"'}, 100 tab.id, {code: 'document.title = "success"'},
104 pass(function() { 101 pass(function() {
105 chrome.tabs.get(tab.id, pass(function(tab) { 102 chrome.tabs.get(tab.id, pass(function(tab) {
106 assertEq('success', tab.title); 103 assertEq('success', tab.title);
107 })); 104 }));
108 })); 105 }));
109 })); 106 }));
110 } 107 }
111 ]); 108 ]);
112 }); 109 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698