| 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 // Include test fixture. | 5 // Include test fixture. |
| 6 GEN_INCLUDE(['chromevox_e2e_test_base.js']); | 6 GEN_INCLUDE(['chromevox_e2e_test_base.js']); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Base test fixture for ChromeVox Next end to end tests. | 9 * Base test fixture for ChromeVox Next end to end tests. |
| 10 * | 10 * |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 /** | 38 /** |
| 39 * Gets the desktop from the automation API and Launches a new tab with | 39 * Gets the desktop from the automation API and Launches a new tab with |
| 40 * the given document, and runs |callback| when a load complete fires. | 40 * the given document, and runs |callback| when a load complete fires. |
| 41 * Arranges to call |testDone()| after |callback| returns. | 41 * Arranges to call |testDone()| after |callback| returns. |
| 42 * NOTE: Callbacks creatd instide |opt_callback| must be wrapped with | 42 * NOTE: Callbacks creatd instide |opt_callback| must be wrapped with |
| 43 * |this.newCallback| if passed to asynchonous calls. Otherwise, the test | 43 * |this.newCallback| if passed to asynchonous calls. Otherwise, the test |
| 44 * will be finished prematurely. | 44 * will be finished prematurely. |
| 45 * @param {function() : void} doc Snippet wrapped inside of a function. | 45 * @param {function() : void} doc Snippet wrapped inside of a function. |
| 46 * @param {function(chrome.automation.AutomationNode)} callback | 46 * @param {function(chrome.automation.AutomationNode)} callback |
| 47 * Called once the document is ready. | 47 * Called once the document is ready. |
| 48 * @param {string=} opt_url Optional url to wait for. Defaults to undefined. |
| 48 */ | 49 */ |
| 49 runWithLoadedTree: function(doc, callback) { | 50 runWithLoadedTree: function(doc, callback, opt_url) { |
| 50 callback = this.newCallback(callback); | 51 callback = this.newCallback(callback); |
| 51 chrome.automation.getDesktop(function(r) { | 52 chrome.automation.getDesktop(function(r) { |
| 52 this.runWithTab(doc, function(newTabUrl) { | 53 var url = opt_url || TestUtils.createUrlForDoc(doc); |
| 53 var listener = function(evt) { | 54 var listener = function(evt) { |
| 54 if (!evt.target.docUrl || evt.target.docUrl != newTabUrl) | 55 if (evt.target.root.url != url) |
| 55 return; | 56 return; |
| 56 | 57 |
| 57 r.removeEventListener('loadComplete', listener, true); | 58 r.removeEventListener('focus', listener, true); |
| 58 global.backgroundObj.onGotCommand('nextObject'); | 59 r.removeEventListener('loadComplete', listener, true); |
| 59 callback && callback(evt.target); | 60 global.backgroundObj.onGotCommand('nextObject'); |
| 60 callback = null; | 61 callback && callback(evt.target); |
| 61 }; | 62 callback = null; |
| 62 r.addEventListener('loadComplete', listener, true); | 63 }; |
| 63 }.bind(this)); | 64 r.addEventListener('focus', listener, true); |
| 65 r.addEventListener('loadComplete', listener, true); |
| 66 var createParams = { |
| 67 active: true, |
| 68 url: url |
| 69 }; |
| 70 chrome.tabs.create(createParams); |
| 64 }.bind(this)); | 71 }.bind(this)); |
| 65 }, | 72 }, |
| 66 | 73 |
| 67 listenOnce: function(node, eventType, callback, capture) { | 74 listenOnce: function(node, eventType, callback, capture) { |
| 68 var innerCallback = this.newCallback(function() { | 75 var innerCallback = this.newCallback(function() { |
| 69 node.removeEventListener(eventType, innerCallback, capture); | 76 node.removeEventListener(eventType, innerCallback, capture); |
| 70 callback.apply(this, arguments); | 77 callback.apply(this, arguments); |
| 71 }); | 78 }); |
| 72 node.addEventListener(eventType, innerCallback, capture); | 79 node.addEventListener(eventType, innerCallback, capture); |
| 73 } | 80 } |
| 74 }; | 81 }; |
| OLD | NEW |