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
3 // found in the LICENSE file.
5 var assertEq = chrome.test.assertEq;
6 var assertFalse = chrome.test.assertFalse;
7 var assertTrue = chrome.test.assertTrue;
9 var EventType = chrome.automation.EventType;
10 var RoleType = chrome.automation.RoleType;
11 var StateType = chrome.automation.StateType;
15 function findAutomationNode(root, condition) {
19 var children = root.children;
20 for (var i = 0; i < children.length; i++) {
21 var result = findAutomationNode(children[i], condition);
28 function runWithDocument(docString, callback) {
29 var url = 'data:text/html,<!doctype html>' + docString;
34 chrome.tabs.create(createParams, function(tab) {
35 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
36 if (tabId == tab.id && changeInfo.status == 'complete') {
44 function setupAndRunTests(allTests, opt_docString) {
45 function runTestInternal() {
46 chrome.test.runTests(allTests);
49 chrome.automation.getDesktop(function(rootNodeArg) {
50 rootNode = rootNodeArg;
52 // Only run the test when the window containing the new tab loads.
53 rootNodeArg.addEventListener(
54 chrome.automation.EventType.childrenChanged,
56 var subroot = evt.target.firstChild;
57 if (!opt_docString || !subroot)
60 if (subroot.role == 'rootWebArea' &&
61 subroot.docUrl.indexOf(opt_docString) != -1)
66 runWithDocument(opt_docString, null);