Commit 2f67264a authored by Henrik Skupin's avatar Henrik Skupin
Browse files

Bug 1663429 - [marionette] Only throw NoSuchWindow error in...

Bug 1663429 - [marionette] Only throw NoSuchWindow error in "WebDriver:SwitchToWindow". r=jgraham, a=RyanVM

There is a race condition in the "WebDriver:SwitchToWindow" command
that would throw an UnknownError instead of NoSuchWindowError when
the window gets closed at the same time as the command gets called.

Differential Revision: https://phabricator.services.mozilla.com/D89377
parent 8b2c99ab
......@@ -1630,6 +1630,9 @@ GeckoDriver.prototype.setWindowRect = async function(cmd) {
* @param {boolean=} focus
* A boolean value which determines whether to focus
* the window. Defaults to true.
*
* @throws {NoSuchWindowError}
* Top-level browsing context has been discarded.
*/
GeckoDriver.prototype.switchToWindow = async function(cmd) {
const { focus = true, handle } = cmd.parameters;
......@@ -1642,9 +1645,18 @@ GeckoDriver.prototype.switchToWindow = async function(cmd) {
const id = parseInt(handle);
const found = this.findWindow(this.windows, (win, winId) => id == winId);
let selected = false;
if (found) {
await this.setWindowHandle(found, focus);
} else {
try {
await this.setWindowHandle(found, focus);
selected = true;
} catch (e) {
logger.error(e);
}
}
if (!selected) {
throw new NoSuchWindowError(`Unable to locate window: ${handle}`);
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment