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, opt_path) { |
22 getUrlFromConfig(function(url) { | 22 var path = opt_path || 'index.html'; |
| 23 getUrlFromConfig(path, function(url) { |
23 createTab(url, function(unused_tab) { | 24 createTab(url, function(unused_tab) { |
24 chrome.automation.getTree(function (returnedRootNode) { | 25 chrome.automation.getTree(function (returnedRootNode) { |
25 rootNode = returnedRootNode; | 26 rootNode = returnedRootNode; |
26 if (rootNode.attributes.docLoaded) { | 27 if (rootNode.attributes.docLoaded) { |
27 chrome.test.runTests(allTests); | 28 chrome.test.runTests(allTests); |
28 return; | 29 return; |
29 } | 30 } |
30 rootNode.addEventListener('loadComplete', function() { | 31 rootNode.addEventListener('loadComplete', function() { |
31 chrome.test.runTests(allTests); | 32 chrome.test.runTests(allTests); |
32 }); | 33 }); |
33 }); | 34 }); |
34 }); | 35 }); |
35 }); | 36 }); |
36 } | 37 } |
37 | 38 |
38 function getUrlFromConfig(callback) { | 39 function getUrlFromConfig(path, callback) { |
39 chrome.test.getConfig(function(config) { | 40 chrome.test.getConfig(function(config) { |
40 assertTrue('testServer' in config, 'Expected testServer in config'); | 41 assertTrue('testServer' in config, 'Expected testServer in config'); |
41 var url = 'http://a.com:PORT/index.html' | 42 var url = ('http://a.com:PORT/' + path) |
42 .replace(/PORT/, config.testServer.port); | 43 .replace(/PORT/, config.testServer.port); |
43 callback(url) | 44 callback(url) |
44 }); | 45 }); |
45 } | 46 } |
OLD | NEW |