| 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 findAutomationNode(root, condition) { | 15 function findAutomationNode(root, condition) { |
| 16 if (condition(root)) | 16 if (condition(root)) |
| 17 return root; | 17 return root; |
| 18 | 18 |
| 19 var children = root.children(); | 19 var children = root.children(); |
| 20 for (var i = 0; i < children.length; i++) { | 20 for (var i = 0; i < children.length; i++) { |
| 21 var result = findAutomationNode(children[i], condition); | 21 var result = findAutomationNode(children[i], condition); |
| 22 if (result) | 22 if (result) |
| 23 return result; | 23 return result; |
| 24 } | 24 } |
| 25 return null; | 25 return null; |
| 26 } | 26 } |
| 27 | 27 |
| 28 function setupAndRunTests(allTests) { | 28 function runWithDocument(docString, callback) { |
| 29 chrome.automation.getDesktop(function(rootNodeArg) { | 29 var url = 'data:text/html,<!doctype html>' + docString; |
| 30 rootNode = rootNodeArg; | 30 var createParams = { |
| 31 chrome.test.runTests(allTests); | 31 active: true, |
| 32 url: url |
| 33 }; |
| 34 chrome.tabs.create(createParams, function(tab) { |
| 35 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) { |
| 36 if (tabId == tab.id && changeInfo.status == 'complete') { |
| 37 callback(); |
| 38 } |
| 39 }); |
| 32 }); | 40 }); |
| 33 } | 41 } |
| 42 |
| 43 function setupAndRunTests(allTests, opt_docString) { |
| 44 function runTestInternal() { |
| 45 chrome.automation.getDesktop(function(rootNodeArg) { |
| 46 rootNode = rootNodeArg; |
| 47 chrome.test.runTests(allTests); |
| 48 }); |
| 49 } |
| 50 |
| 51 if (opt_docString) |
| 52 runWithDocument(opt_docString, runTestInternal); |
| 53 else |
| 54 runTestInternal(); |
| 55 } |
| OLD | NEW |