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 | 14 |
15 function createTab(url, callback) { | 15 function createTab(url, callback) { |
16 chrome.tabs.create({"url": url}, function(tab) { | 16 chrome.tabs.create({"url": url}, function(tab) { |
17 callback(tab); | 17 callback(tab); |
18 }); | 18 }); |
19 } | 19 } |
20 | 20 |
21 function setUpAndRunTests(allTests) { | 21 function setUpAndRunTests(allTests) { |
22 getUrlFromConfig(function(url) { | 22 getUrlFromConfig(function(url) { |
23 createTab(url, function(unused_tab) { | 23 createTab(url, function(unused_tab) { |
24 chrome.automation.getTree(function (returnedRootNode) { | 24 chrome.automation.getTree(function (returnedRootNode) { |
25 rootNode = returnedRootNode; | 25 rootNode = returnedRootNode; |
26 if (rootNode.attributes.docLoaded) { | 26 if (rootNode.attributes.docLoaded) { |
27 console.log('In getTree() callback: ' + | |
28 'docLoaded attr already true; running tests'); | |
29 chrome.test.runTests(allTests); | 27 chrome.test.runTests(allTests); |
30 return; | 28 return; |
31 } | 29 } |
32 console.log('In getTree() callback: ' + | |
33 'docLoaded false; waiting for loadComplete'); | |
34 rootNode.addEventListener('loadComplete', function() { | 30 rootNode.addEventListener('loadComplete', function() { |
35 console.log('loadComplete received; running tests.'); | |
36 chrome.test.runTests(allTests); | 31 chrome.test.runTests(allTests); |
37 }); | 32 }); |
38 }); | 33 }); |
39 }); | 34 }); |
40 }); | 35 }); |
41 } | 36 } |
42 | 37 |
43 function getUrlFromConfig(callback) { | 38 function getUrlFromConfig(callback) { |
44 chrome.test.getConfig(function(config) { | 39 chrome.test.getConfig(function(config) { |
45 assertTrue('testServer' in config, 'Expected testServer in config'); | 40 assertTrue('testServer' in config, 'Expected testServer in config'); |
46 var url = 'http://a.com:PORT/index.html' | 41 var url = 'http://a.com:PORT/index.html' |
47 .replace(/PORT/, config.testServer.port); | 42 .replace(/PORT/, config.testServer.port); |
48 callback(url) | 43 callback(url) |
49 }); | 44 }); |
50 } | 45 } |
OLD | NEW |