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

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

Issue 890083002: [Extensions] Propagate activeTab hosts to extension background pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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
11 var RoleType = chrome.automation.RoleType; 11 var RoleType = chrome.automation.RoleType;
12 12
13 chrome.browserAction.onClicked.addListener(function() { 13 function canXhr(url) {
14 chrome.tabs.executeScript({ code: 'true' }, callbackPass()); 14 assertFalse(url == null);
15 var xhr = new XMLHttpRequest();
16 xhr.open('GET', url, false);
17 var success = true;
18 try {
19 xhr.send();
20 } catch(e) {
21 assertEq('NetworkError', e.name);
22 success = false;
23 }
24 return success;
25 }
26
27 var cachedUrl = null;
28 var iframeDone = null;
29
30 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
31 if (request.message == 'xhr') {
32 sendResponse({url: cachedUrl});
33 } else {
34 assertTrue(request.success);
35 iframeDone();
36 }
37 });
38
39 var iframeUrl = chrome.extension.getURL('iframe.html');
40 var injectIframe =
41 'var iframe = document.createElement("iframe");\n' +
42 'iframe.src = "' + iframeUrl + '";\n' +
43 'document.body.appendChild(iframe);\n';
44
45 chrome.browserAction.onClicked.addListener(function(tab) {
46 iframeDone = chrome.test.callbackAdded();
47 cachedUrl = tab.url;
48 chrome.tabs.executeScript({ code: injectIframe }, callbackPass());
49 assertTrue(canXhr(tab.url));
50
15 chrome.automation.getTree(callbackPass(function(rootNode) { 51 chrome.automation.getTree(callbackPass(function(rootNode) {
16 assertFalse(rootNode == undefined); 52 assertFalse(rootNode == undefined);
17 assertEq(RoleType.rootWebArea, rootNode.role); 53 assertEq(RoleType.rootWebArea, rootNode.role);
18 chrome.test.succeed();
19 })); 54 }));
20 }); 55 });
21 56
22 chrome.webNavigation.onCompleted.addListener(function(details) { 57 chrome.webNavigation.onCompleted.addListener(function(details) {
23 chrome.tabs.executeScript({ code: 'true' }, callbackFail( 58 chrome.tabs.executeScript({ code: 'true' }, callbackFail(
24 'Cannot access contents of url "' + details.url + 59 'Cannot access contents of url "' + details.url +
25 '". Extension manifest must request permission to access this host.')); 60 '". Extension manifest must request permission to access this host.'));
26 61
27 chrome.automation.getTree(callbackFail( 62 chrome.automation.getTree(callbackFail(
28 'Cannot request automation tree on url "' + details.url + 63 'Cannot request automation tree on url "' + details.url +
29 '". Extension manifest must request permission to access this host.')); 64 '". Extension manifest must request permission to access this host.'));
65
66 assertFalse(canXhr(details.url));
30 }); 67 });
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/tab_finder.cc ('k') | chrome/test/data/extensions/api_test/active_tab/iframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698