OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 8 |
9 var EventType = chrome.automation.EventType; | 9 var EventType = chrome.automation.EventType; |
10 var RoleType = chrome.automation.RoleType; | 10 var RoleType = chrome.automation.RoleType; |
11 var StateType = chrome.automation.StateType; | 11 var StateType = chrome.automation.StateType; |
12 | 12 |
13 var rootNode = null; | 13 var rootNode = null; |
14 var url = ''; | 14 var url = ''; |
15 | 15 |
16 function createTab(url, callback) { | 16 function createTab(url, callback) { |
17 chrome.tabs.create({"url": url}, function(tab) { | 17 chrome.tabs.create({"url": url}, function(tab) { |
18 callback(tab); | 18 callback(tab); |
19 }); | 19 }); |
20 } | 20 } |
21 | 21 |
| 22 function listenOnce(node, eventType, callback, capture) { |
| 23 var innerCallback = function(evt) { |
| 24 node.removeEventListener(eventType, innerCallback, capture); |
| 25 callback(evt); |
| 26 }; |
| 27 node.addEventListener(eventType, innerCallback, capture); |
| 28 } |
| 29 |
22 function setUpAndRunTests(allTests, opt_path) { | 30 function setUpAndRunTests(allTests, opt_path) { |
23 var path = opt_path || 'index.html'; | 31 var path = opt_path || 'index.html'; |
24 getUrlFromConfig(path, function(url) { | 32 getUrlFromConfig(path, function(url) { |
25 createTab(url, function(unused_tab) { | 33 createTab(url, function(unused_tab) { |
26 chrome.automation.getTree(function (returnedRootNode) { | 34 chrome.automation.getTree(function (returnedRootNode) { |
27 rootNode = returnedRootNode; | 35 rootNode = returnedRootNode; |
28 if (rootNode.docLoaded) { | 36 if (rootNode.docLoaded) { |
29 chrome.test.runTests(allTests); | 37 chrome.test.runTests(allTests); |
30 return; | 38 return; |
31 } | 39 } |
32 rootNode.addEventListener('loadComplete', function() { | 40 rootNode.addEventListener('loadComplete', function() { |
33 chrome.test.runTests(allTests); | 41 chrome.test.runTests(allTests); |
34 }); | 42 }); |
35 }); | 43 }); |
36 }); | 44 }); |
37 }); | 45 }); |
38 } | 46 } |
39 | 47 |
40 function getUrlFromConfig(path, callback) { | 48 function getUrlFromConfig(path, callback) { |
41 chrome.test.getConfig(function(config) { | 49 chrome.test.getConfig(function(config) { |
42 assertTrue('testServer' in config, 'Expected testServer in config'); | 50 assertTrue('testServer' in config, 'Expected testServer in config'); |
43 url = ('http://a.com:PORT/' + path) | 51 url = ('http://a.com:PORT/' + path) |
44 .replace(/PORT/, config.testServer.port); | 52 .replace(/PORT/, config.testServer.port); |
45 callback(url) | 53 callback(url) |
46 }); | 54 }); |
47 } | 55 } |
OLD | NEW |