OLD | NEW |
---|---|
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 pass = chrome.test.callbackPass; | 5 var pass = chrome.test.callbackPass; |
6 var fail = chrome.test.callbackFail; | 6 var fail = chrome.test.callbackFail; |
7 var assertEq = chrome.test.assertEq; | 7 var assertEq = chrome.test.assertEq; |
8 var assertTrue = chrome.test.assertTrue; | 8 var assertTrue = chrome.test.assertTrue; |
9 var relativePath = | 9 var relativePath = |
10 '/extensions/api_test/executescript/in_frame/test_executescript.html'; | 10 '/extensions/api_test/executescript/in_frame/test_executescript.html'; |
11 var testUrl = 'http://a.com:PORT' + relativePath; | 11 var testUrl = 'http://a.com:PORT' + relativePath; |
12 | 12 |
13 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | 13 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { |
14 if (changeInfo.status != 'complete') | 14 if (changeInfo.status != 'complete') |
15 return; | 15 return; |
16 | 16 |
17 chrome.test.runTests([ | 17 chrome.test.runTests([ |
18 function executeJavaScriptCodeInAllFramesShouldSucceed() { | 18 function executeJavaScriptCodeInAllFramesShouldSucceed() { |
19 var script_file = {}; | 19 var script_file = {}; |
20 script_file.code = "var extensionPort = chrome.runtime.connect();"; | 20 script_file.code = "var extensionPort = chrome.runtime.connect();"; |
21 script_file.code = script_file.code + | 21 script_file.code = script_file.code + |
22 "extensionPort.postMessage({message: document.title});"; | 22 "extensionPort.postMessage({message: document.title});"; |
23 script_file.allFrames = true; | 23 script_file.allFrames = true; |
24 var counter = 0; | 24 var counter = 0; |
25 var totalTitles = ''; | 25 var totalTitles = ''; |
26 var done = pass(); | |
27 function verifyAndFinish() { | |
28 assertEq(counter, 5); | |
29 assertEq(totalTitles, 'frametest0test1test2test3'); | |
30 chrome.runtime.onConnect.removeListener(eventListener); | |
31 done(); | |
32 } | |
26 function eventListener(port) { | 33 function eventListener(port) { |
27 port.onMessage.addListener(function(data) { | 34 port.onMessage.addListener(function(data) { |
28 counter++; | 35 counter++; |
lazyboy
2016/09/08 21:59:16
asertTrue(counter<=5), i.e. catch if it gets calle
Devlin
2016/09/09 16:10:34
Done.
| |
29 totalTitles += data.message; | 36 totalTitles += data.message; |
37 if (counter == 5) | |
38 verifyAndFinish(); | |
30 }); | 39 }); |
31 }; | 40 }; |
32 chrome.runtime.onConnect.addListener(eventListener); | 41 chrome.runtime.onConnect.addListener(eventListener); |
33 chrome.tabs.executeScript(tabId, script_file, pass(function() { | 42 chrome.tabs.executeScript(tabId, script_file); |
34 assertEq(counter, 5); | |
35 assertEq(totalTitles, 'frametest0test1test2test3'); | |
36 chrome.runtime.onConnect.removeListener(eventListener); | |
37 })); | |
38 }, | 43 }, |
39 | 44 |
40 function insertCSSTextInAllFramesShouldSucceed() { | 45 function insertCSSTextInAllFramesShouldSucceed() { |
41 var css_file = {}; | 46 var css_file = {}; |
42 css_file.code = "p {display:none;}"; | 47 css_file.code = "p {display:none;}"; |
43 css_file.allFrames = true; | 48 css_file.allFrames = true; |
44 var newStyle = ''; | 49 var newStyle = ''; |
45 var counter = 0; | 50 var counter = 0; |
51 var done = pass(); | |
52 function verifyAndFinish() { | |
53 assertEq(newStyle, 'nonenonenonenone'); | |
54 assertEq(counter, 4); | |
55 chrome.runtime.onConnect.removeListener(eventListener); | |
56 done(); | |
57 } | |
46 function eventListener(port) { | 58 function eventListener(port) { |
47 port.onMessage.addListener(function(data) { | 59 port.onMessage.addListener(function(data) { |
48 counter++; | 60 counter++; |
49 newStyle += data.message; | 61 newStyle += data.message; |
62 if (counter == 4) | |
63 verifyAndFinish(); | |
50 }); | 64 }); |
51 }; | 65 }; |
52 chrome.runtime.onConnect.addListener(eventListener); | 66 chrome.runtime.onConnect.addListener(eventListener); |
53 chrome.tabs.insertCSS(tabId, css_file, function() { | 67 chrome.tabs.insertCSS(tabId, css_file, function() { |
54 var script_file = {}; | 68 var script_file = {}; |
55 script_file.file = 'script.js'; | 69 script_file.file = 'script.js'; |
56 script_file.allFrames = true; | 70 script_file.allFrames = true; |
57 chrome.tabs.executeScript(tabId, script_file, | 71 chrome.tabs.executeScript(tabId, script_file); |
58 pass(function() { | |
59 assertEq(newStyle, 'nonenonenonenone'); | |
60 assertEq(counter, 4); | |
61 chrome.runtime.onConnect.removeListener(eventListener); | |
62 })); | |
63 }); | 72 }); |
64 } | 73 } |
65 ]); | 74 ]); |
66 }); | 75 }); |
67 | 76 |
68 chrome.test.getConfig(function(config) { | 77 chrome.test.getConfig(function(config) { |
69 testUrl = testUrl.replace(/PORT/, config.testServer.port); | 78 testUrl = testUrl.replace(/PORT/, config.testServer.port); |
70 chrome.tabs.create({ url: testUrl }); | 79 chrome.tabs.create({ url: testUrl }); |
71 }); | 80 }); |
OLD | NEW |