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

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

Issue 2871533002: [Test] Added a test for activeTab URL filtering (Closed)
Patch Set: Comments, nits, ScopedTestPublicSessionLoginState Created 3 years, 6 months 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
« no previous file with comments | « chrome/browser/extensions/active_tab_apitest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 assertFalse = chrome.test.assertFalse; 6 var assertFalse = chrome.test.assertFalse;
7 var assertTrue = chrome.test.assertTrue; 7 var assertTrue = chrome.test.assertTrue;
8 var callbackFail = chrome.test.callbackFail; 8 var callbackFail = chrome.test.callbackFail;
9 var callbackPass = chrome.test.callbackPass; 9 var callbackPass = chrome.test.callbackPass;
10 10
(...skipping 24 matching lines...) Expand all
35 iframeDone(); 35 iframeDone();
36 } 36 }
37 }); 37 });
38 38
39 var iframeUrl = chrome.extension.getURL('iframe.html'); 39 var iframeUrl = chrome.extension.getURL('iframe.html');
40 var injectIframe = 40 var injectIframe =
41 'var iframe = document.createElement("iframe");\n' + 41 'var iframe = document.createElement("iframe");\n' +
42 'iframe.src = "' + iframeUrl + '";\n' + 42 'iframe.src = "' + iframeUrl + '";\n' +
43 'document.body.appendChild(iframe);\n'; 43 'document.body.appendChild(iframe);\n';
44 44
45 var runCount = 0;
46
45 chrome.browserAction.onClicked.addListener(function(tab) { 47 chrome.browserAction.onClicked.addListener(function(tab) {
48 runCount++;
49 if (runCount == 1) {
50 // First pass is done without granting activeTab permission, the extension
51 // shouldn't have access to tab.url here.
52 assertFalse(!!tab.url);
53 chrome.test.succeed();
54 return;
55 } else if (runCount == 3) {
56 // Third pass is done in a public session, and activeTab permission is
57 // granted to the extension. URL should be scrubbed down to the origin here
58 // (tested at the C++ side).
59 chrome.test.sendMessage(tab.url);
60 chrome.test.succeed();
61 return;
62 }
63 // Second pass is done with granting activeTab permission, the extension
64 // should have full access to the page (and also to tab.url).
65
46 iframeDone = chrome.test.callbackAdded(); 66 iframeDone = chrome.test.callbackAdded();
47 cachedUrl = tab.url; 67 cachedUrl = tab.url;
48 chrome.tabs.executeScript({ code: injectIframe }, callbackPass()); 68 chrome.tabs.executeScript({ code: injectIframe }, callbackPass());
49 assertTrue(canXhr(tab.url)); 69 assertTrue(canXhr(tab.url));
50 70
51 chrome.automation.getTree(callbackPass(function(rootNode) { 71 chrome.automation.getTree(callbackPass(function(rootNode) {
52 assertFalse(rootNode == undefined); 72 assertFalse(rootNode == undefined);
53 assertEq(RoleType.ROOT_WEB_AREA, rootNode.role); 73 assertEq(RoleType.ROOT_WEB_AREA, rootNode.role);
54 })); 74 }));
55 }); 75 });
56 76
57 chrome.webNavigation.onCompleted.addListener(function(details) { 77 chrome.webNavigation.onCompleted.addListener(function(details) {
58 chrome.tabs.executeScript({ code: 'true' }, callbackFail( 78 chrome.tabs.executeScript({ code: 'true' }, callbackFail(
59 'Cannot access contents of the page. ' + 79 'Cannot access contents of the page. ' +
60 'Extension manifest must request permission to access the ' + 80 'Extension manifest must request permission to access the ' +
61 'respective host.')); 81 'respective host.'));
62 82
63 chrome.automation.getTree(callbackFail( 83 chrome.automation.getTree(callbackFail(
64 'Cannot request automation tree on url "' + details.url + 84 'Cannot request automation tree on url "' + details.url +
65 '". Extension manifest must request permission to access this host.')); 85 '". Extension manifest must request permission to access this host.'));
66 86
67 assertFalse(canXhr(details.url)); 87 assertFalse(canXhr(details.url));
68 }); 88 });
OLDNEW
« no previous file with comments | « chrome/browser/extensions/active_tab_apitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698