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

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

Issue 226663003: Allow content script insertion on about:-URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move GetEffectiveDocumentURL to ScriptContext Created 6 years, 7 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 chrome.test.getConfig(function(config) {
6 chrome.test.runTests([
7 function testAboutBlankInFrame() {
8 chrome.runtime.onMessage.addListener(function onMessageListener(message) {
9 chrome.runtime.onMessage.removeListener(onMessageListener);
10 chrome.test.assertEq('message from about:blank', message);
11 chrome.test.succeed();
12 });
13 chrome.test.log('Creating tab...');
14 var test_url =
15 ('http://localhost:PORT/extensions/' +
16 'test_file_with_about_blank_iframe.html')
17 .replace(/PORT/, config.testServer.port);
18 chrome.tabs.create({ url: test_url });
19 },
20 function testAboutSrcdocFrame() {
21 chrome.runtime.onMessage.addListener(function onMessageListener(message) {
22 chrome.runtime.onMessage.removeListener(onMessageListener);
23 chrome.test.assertEq('message from about:srcdoc', message);
24 chrome.test.succeed();
25 });
26 chrome.test.log('Creating tab...');
27 var test_url =
28 ('http://localhost:PORT/extensions/' +
29 'api_test/webnavigation/srcdoc/a.html')
30 .replace(/PORT/, config.testServer.port);
31 chrome.tabs.create({ url: test_url });
32 },
33 // Tests that content scripts are inserted in about:blank frames, even if
34 // they are embedded in another about:-frame.
35 function testAboutSrcdocNestedFrame() {
36 chrome.runtime.onMessage.addListener(function onMessageListener(message) {
37 chrome.runtime.onMessage.removeListener(onMessageListener);
38 // Child frame of srcdoc document
39 chrome.test.assertEq('message from about:blank', message);
40 chrome.runtime.onMessage.addListener(function secondListener(message) {
41 chrome.runtime.onMessage.removeListener(secondListener);
42 // Child frame of top-level document
43 chrome.test.assertEq('message from about:srcdoc', message);
44 chrome.test.succeed();
45 });
46 });
47 chrome.test.log('Creating tab...');
48 var test_url =
49 ('http://localhost:PORT/extensions/' +
50 'test_file_with_about_blank_in_srcdoc.html')
51 .replace(/PORT/, config.testServer.port);
52 chrome.tabs.create({ url: test_url });
53 },
54 function testAboutBlankInTopLevelFrame() {
55 chrome.runtime.onMessage.addListener(function onMessageListener(message) {
56 chrome.runtime.onMessage.removeListener(onMessageListener);
57 chrome.test.assertEq('message from about:blank', message);
58 chrome.test.succeed();
59 });
60
61 // Create tab using window.open on an existing page to inherit the origin
62 // of the document.
63 chrome.test.log('Creating tab using window.open("about:blank")...');
64 chrome.tabs.query({
65 url: '*://*/*test_file_with_about_blank_iframe*'
66 }, function(tabs) {
67 chrome.test.assertTrue(tabs.length > 0);
68 chrome.tabs.sendMessage(tabs[0].id, 'open about:blank popup');
69 });
70 },
71
72 // Request host permissions for chrome.tabs.executeScript. These permissions
73 // were declared as optional, to make sure that the permission check for
74 // about:blank is tested against the content_scripts[*].matches in the
75 // manifest file instead of the effective permissions.
76 function getHostPermissionsForFollowingTests() {
77 chrome.permissions.request({
78 origins: ['*://*/*']
79 }, function(granted) {
80 chrome.test.assertTrue(granted,
81 'Need *://*/* permissions for chrome.tabs.executeScript tests.');
82 chrome.test.succeed();
83 });
84 },
85
86 // chrome.tabs.executeScript should run in the frame
87 function testExecuteScriptInFrame() {
88 chrome.tabs.query({
89 url: '*://*/*test_file_with_about_blank_iframe*'
90 }, function(tabs) {
91 chrome.test.assertTrue(tabs.length > 0);
92 chrome.tabs.executeScript(tabs[0].id, {
93 code: 'frameElement && (frameElement.src || "about:blank")',
94 matchAboutBlank: true,
95 allFrames: true
96 }, function(results) {
97 chrome.test.assertNoLastError();
98 chrome.test.assertTrue(results.indexOf('about:blank') >= 0);
99 chrome.test.succeed();
100 });
101 });
102 },
103 // chrome.tabs.executeScript should run in about:srcdoc frames
104 function testExecuteScriptInSrcdocFrame() {
105 chrome.tabs.query({
106 url: '*://*/*srcdoc*'
107 }, function(tabs) {
108 chrome.test.assertTrue(tabs.length > 0);
109 chrome.tabs.executeScript(tabs[0].id, {
110 code: 'frameElement && frameElement.srcdoc && "srcdoc"',
111 matchAboutBlank: true,
112 allFrames: true
113 }, function(results) {
114 chrome.test.assertNoLastError();
115 chrome.test.assertTrue(results.indexOf('srcdoc') >= 0,
116 'contentscript should be able to run in srcdoc frame');
117 chrome.test.succeed();
118 });
119 });
120 }
121 ]);
122 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698