OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 var responsesReceived = 0; | |
not at google - send to devlin
2015/06/29 18:28:11
Can we avoid global variables? Worst case it'll be
Devlin
2015/06/29 19:41:44
Not sure I follow. This count is used in both tes
not at google - send to devlin
2015/06/29 20:09:07
It seems like it's reset to 0 in each test. Why do
Devlin
2015/06/29 20:43:13
chrome.runtime.onMessage listener is global to avo
not at google - send to devlin
2015/06/29 21:24:35
I don't think it's excessive. You can listen to th
Devlin
2015/06/29 21:51:20
Done.
| |
6 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | |
7 if (request == 'fail') { | |
8 chrome.test.fail(); | |
9 } else { | |
10 chrome.test.assertEq('complete', request); | |
11 ++responsesReceived; | |
12 } | |
13 }); | |
14 | |
15 var waitForCommittedAndRun = function(functionToRun, numCommits, url) { | |
16 responsesReceived = 0; | |
17 var committedCount = 0; | |
18 var onCommitted = function(details) { | |
19 if (++committedCount == numCommits) { | |
20 functionToRun(details.tabId); | |
21 chrome.webNavigation.onCommitted.removeListener(onCommitted); | |
22 } | |
23 }; | |
24 chrome.webNavigation.onCommitted.addListener(onCommitted); | |
25 chrome.tabs.create({url: url}); | |
26 }; | |
27 | |
28 chrome.test.getConfig(function(config) { | |
29 var url = ('http://a.com:PORT/extensions/api_test/executescript/' + | |
30 'removed_frames/outer.html').replace(/PORT/, | |
31 config.testServer.port); | |
not at google - send to devlin
2015/06/29 18:28:11
I find this pattern pretty weird, and I've seen it
Devlin
2015/06/29 19:41:44
I don't know either (copied). Changed.
| |
32 // Regression tests for crbug.com/500574. | |
33 chrome.test.runTests([ | |
34 function() { | |
35 waitForCommittedAndRun(injectAndDeleteIframeFromMainFrame, 2, url); | |
not at google - send to devlin
2015/06/29 21:24:35
Err, why is the tab ID 2? Can you make it not depe
Devlin
2015/06/29 21:51:20
Tab id is not 2. The number of commits to wait fo
| |
36 } | |
37 // This is another great test to have, but currently it crashes in blink. | |
38 // TODO(devlin): Fix the crash in blink and enable this! | |
Devlin
2015/06/25 21:12:27
This will be done soon.
| |
39 // function() { | |
40 // waitForCommittedAndRun(injectAndDeleteIframeFromIframe, 2, url); | |
41 // } | |
42 ]); | |
43 }); | |
44 | |
45 function injectAndDeleteIframeFromMainFrame(tabId) { | |
46 // Inject code into each frame. If it's the parent frame, it removes the child | |
47 // frame from the DOM (invalidating it). The child frame's code shouldn't | |
48 // finish executing, since it's been removed. | |
49 var injectFrameCode = | |
50 'if (window !== window.top) {' + | |
not at google - send to devlin
2015/06/29 18:28:11
nit (sorta): the problem with this is that the lin
Devlin
2015/06/29 19:41:44
Done.
| |
51 // There's a (good) chance the child frame reaches "idle" first, since it | |
52 // is a subresource of the main frame. But it shouldn't stick around for | |
53 // more than 200ms or so, since that's the max delay for idle. If the | |
54 // script still tries to execute, it's probably bad. | |
55 ' window.setTimeout(function() {' + | |
56 ' chrome.runtime.sendMessage("fail");' + | |
not at google - send to devlin
2015/06/29 18:28:11
Why does it matter? The way I read this (?) withou
Devlin
2015/06/29 19:41:44
Well, even if that were the case, failing is a lot
not at google - send to devlin
2015/06/29 20:09:07
That is beside the point, but I disagree, and will
Devlin
2015/06/29 20:43:13
But the point is that this code will *not* run. I
| |
57 ' }, 250);' + | |
58 '} else {' + | |
59 ' iframe = document.getElementsByTagName("iframe")[0];' + | |
60 ' iframe.parentElement.removeChild(iframe);' + | |
61 ' chrome.runtime.sendMessage("complete");' + | |
62 '}'; | |
63 chrome.tabs.executeScript( | |
64 tabId, | |
65 {code: injectFrameCode, allFrames: true, runAt: 'document_idle'}, | |
66 function() { | |
67 chrome.test.assertEq(1, responsesReceived); | |
68 chrome.test.succeed(); | |
69 }); | |
70 }; | |
71 | |
72 function injectAndDeleteIframeFromIframe(tabId) { | |
73 responsesReceived = 0; | |
74 // Inject code into each frame. Have the child frame remove itself, deleting | |
75 // the frame while it's still executing. | |
76 var injectFrameCode = | |
77 'if (window.self !== window.top) {' + | |
78 ' var iframe = window.top.document.getElementsByTagName("iframe")[0];' + | |
79 ' if (!iframe || iframe.contentWindow !== window)' + | |
80 ' chrome.runtime.sendMessage("fail");' + | |
81 ' else' + | |
82 ' window.top.document.body.removeChild(iframe);' + | |
83 '} else {' + | |
84 ' chrome.runtime.sendMessage("complete");' + | |
85 '}'; | |
86 // We also use two "executeScript" calls here so that we have a pending script | |
87 // execution on a frame that gets deleted. | |
88 chrome.tabs.executeScript( | |
89 tabId, | |
90 {code: injectFrameCode, allFrames: true, runAt: 'document_idle'}); | |
91 chrome.tabs.executeScript( | |
92 tabId, | |
93 {code: injectFrameCode, allFrames: true, runAt: 'document_idle'}, | |
94 function() { | |
95 // Script execution, all other things equal, should happen in the order it | |
96 // was received, so we only need a check in the second callback. | |
97 chrome.test.assertEq(2, responsesReceived); | |
98 chrome.test.succeed(); | |
99 }); | |
100 } | |
OLD | NEW |