Index: chrome/test/data/extensions/api_test/automation/tests/desktop/common.js |
diff --git a/chrome/test/data/extensions/api_test/automation/tests/desktop/common.js b/chrome/test/data/extensions/api_test/automation/tests/desktop/common.js |
index a6d3d9afb09ae040e9b16185b7e4a3c46e37654d..7a2b9030472ac9587823a04673312e3bca9fc306 100644 |
--- a/chrome/test/data/extensions/api_test/automation/tests/desktop/common.js |
+++ b/chrome/test/data/extensions/api_test/automation/tests/desktop/common.js |
@@ -42,14 +42,28 @@ function runWithDocument(docString, callback) { |
function setupAndRunTests(allTests, opt_docString) { |
function runTestInternal() { |
- chrome.automation.getDesktop(function(rootNodeArg) { |
- rootNode = rootNodeArg; |
- chrome.test.runTests(allTests); |
- }); |
+ chrome.test.runTests(allTests); |
} |
- if (opt_docString) |
- runWithDocument(opt_docString, runTestInternal); |
- else |
- runTestInternal(); |
+ chrome.automation.getDesktop(function(rootNodeArg) { |
+ rootNode = rootNodeArg; |
+ |
+ // Only run the test when the window containing the new tab loads. |
+ rootNodeArg.addEventListener( |
+ chrome.automation.EventType.childrenChanged, |
+ function(evt) { |
+ var subroot = evt.target.firstChild; |
+ if (!opt_docString || !subroot) |
+ return; |
+ |
+ if (subroot.role == 'rootWebArea' && |
+ subroot.attributes.docUrl.indexOf(opt_docString) != -1) |
+ runTestInternal(); |
+ }, |
+ true); |
+ if (opt_docString) |
+ runWithDocument(opt_docString, null); |
+ else |
+ runTestInternal(); |
+ }); |
} |