OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 listenOnce = chrome.test.listenOnce; | 5 var listenOnce = chrome.test.listenOnce; |
6 var listenForever = chrome.test.listenForever; | 6 var listenForever = chrome.test.listenForever; |
7 | 7 |
8 JSON.parse = function() { | 8 JSON.parse = function() { |
9 return "JSON.parse clobbered by extension."; | 9 return "JSON.parse clobbered by extension."; |
10 }; | 10 }; |
(...skipping 10 matching lines...) Expand all Loading... |
21 return "Object.prototype.toJSON clobbered by extension."; | 21 return "Object.prototype.toJSON clobbered by extension."; |
22 }; | 22 }; |
23 | 23 |
24 // Keep track of the tab that we're running tests in, for simplicity. | 24 // Keep track of the tab that we're running tests in, for simplicity. |
25 var testTab = null; | 25 var testTab = null; |
26 | 26 |
27 chrome.test.getConfig(function(config) { | 27 chrome.test.getConfig(function(config) { |
28 chrome.test.runTests([ | 28 chrome.test.runTests([ |
29 function setupTestTab() { | 29 function setupTestTab() { |
30 chrome.test.log("Creating tab..."); | 30 chrome.test.log("Creating tab..."); |
| 31 var newTab = null; |
| 32 var doneListening = listenForever(chrome.tabs.onUpdated, |
| 33 function(_, info, tab) { |
| 34 if (newTab && tab.id == newTab.id && info.status == 'complete') { |
| 35 chrome.test.log("Created tab: " + tab.url); |
| 36 testTab = tab; |
| 37 doneListening(); |
| 38 } |
| 39 }); |
31 chrome.tabs.create({ | 40 chrome.tabs.create({ |
32 url: "http://localhost:PORT/extensions/test_file.html" | 41 url: "http://localhost:PORT/extensions/test_file.html" |
33 .replace(/PORT/, config.testServer.port) | 42 .replace(/PORT/, config.testServer.port) |
34 }, function(newTab) { | 43 }, function(tab) { |
35 var doneListening = listenForever(chrome.tabs.onUpdated, | 44 newTab = tab; |
36 function(_, info, tab) { | |
37 if (tab.id == newTab.id && info.status == 'complete') { | |
38 chrome.test.log("Created tab: " + tab.url); | |
39 testTab = tab; | |
40 doneListening(); | |
41 } | |
42 }); | |
43 }); | 45 }); |
44 }, | 46 }, |
45 | 47 |
46 // Tests that postMessage to the tab and its response works. | 48 // Tests that postMessage to the tab and its response works. |
47 function postMessage() { | 49 function postMessage() { |
48 var port = chrome.tabs.connect(testTab.id); | 50 var port = chrome.tabs.connect(testTab.id); |
49 port.postMessage({testPostMessage: true}); | 51 port.postMessage({testPostMessage: true}); |
50 listenOnce(port.onMessage, function(msg) { | 52 listenOnce(port.onMessage, function(msg) { |
51 port.disconnect(); | 53 port.disconnect(); |
52 }); | 54 }); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } catch(e) { | 205 } catch(e) { |
204 error = e; | 206 error = e; |
205 } | 207 } |
206 chrome.test.assertTrue(error != undefined); | 208 chrome.test.assertTrue(error != undefined); |
207 | 209 |
208 chrome.test.succeed(); | 210 chrome.test.succeed(); |
209 }, | 211 }, |
210 | 212 |
211 ]); | 213 ]); |
212 }); | 214 }); |
OLD | NEW |