| 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; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 function runWithDocument(docString, callback) { | 28 function runWithDocument(docString, callback) { |
| 29 var url = 'data:text/html,<!doctype html>' + docString; | 29 var url = 'data:text/html,<!doctype html>' + docString; |
| 30 var createParams = { | 30 var createParams = { |
| 31 active: true, | 31 active: true, |
| 32 url: url | 32 url: url |
| 33 }; | 33 }; |
| 34 chrome.tabs.create(createParams, function(tab) { | 34 chrome.tabs.create(createParams, function(tab) { |
| 35 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) { | 35 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) { |
| 36 if (tabId == tab.id && changeInfo.status == 'complete') { | 36 if (tabId == tab.id && changeInfo.status == 'complete') { |
| 37 if (callback) | 37 chrome.automation.getTree(tab.id, callback); |
| 38 callback(); | |
| 39 } | 38 } |
| 40 }); | 39 }); |
| 41 }); | 40 }); |
| 42 } | 41 } |
| 43 | 42 |
| 44 function setupAndRunTests(allTests, opt_docString) { | 43 function listenOnce(node, eventType, callback, capture) { |
| 45 function runTestInternal() { | 44 var innerCallback = function(evt) { |
| 46 chrome.test.runTests(allTests); | 45 node.removeEventListener(eventType, innerCallback, capture); |
| 47 } | 46 callback(evt); |
| 47 }; |
| 48 node.addEventListener(eventType, innerCallback, capture); |
| 49 } |
| 48 | 50 |
| 51 function setupAndRunTests(allTests) { |
| 49 chrome.automation.getDesktop(function(rootNodeArg) { | 52 chrome.automation.getDesktop(function(rootNodeArg) { |
| 50 rootNode = rootNodeArg; | 53 rootNode = rootNodeArg; |
| 51 | 54 chrome.test.runTests(allTests); |
| 52 // Only run the test when the window containing the new tab loads. | |
| 53 rootNodeArg.addEventListener( | |
| 54 chrome.automation.EventType.childrenChanged, | |
| 55 function(evt) { | |
| 56 var subroot = evt.target.firstChild; | |
| 57 if (!opt_docString || !subroot) | |
| 58 return; | |
| 59 | |
| 60 if (subroot.role == 'rootWebArea' && | |
| 61 subroot.docUrl.indexOf(opt_docString) != -1) | |
| 62 runTestInternal(); | |
| 63 }, | |
| 64 true); | |
| 65 if (opt_docString) | |
| 66 runWithDocument(opt_docString, null); | |
| 67 else | |
| 68 runTestInternal(); | |
| 69 }); | 55 }); |
| 70 } | 56 } |
| OLD | NEW |