diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index 3a38cea8953a..b3ceb0d5591b 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -1443,31 +1443,6 @@ GeckoDriver.prototype.setWindowRect = async function(cmd) { await this._handleUserPrompts(); let {x, y, width, height} = cmd.parameters; - let origRect = this.curBrowser.rect; - - // Synchronous resize to |width| and |height| dimensions. - async function resizeWindow(width, height) { - await new Promise(resolve => { - win.addEventListener("resize", resolve, {once: true}); - win.resizeTo(width, height); - }); - await new IdlePromise(win); - } - - // Wait until window size has changed. We can't wait for the - // user-requested window size as this may not be achievable on the - // current system. - const windowResizeChange = async () => { - return new PollPromise((resolve, reject) => { - let curRect = this.curBrowser.rect; - if (curRect.width != origRect.width && - curRect.height != origRect.height) { - resolve(); - } else { - reject(); - } - }); - }; switch (WindowState.from(win.windowState)) { case WindowState.Fullscreen: @@ -1483,10 +1458,22 @@ GeckoDriver.prototype.setWindowRect = async function(cmd) { assert.positiveInteger(height); assert.positiveInteger(width); - if (win.outerWidth != width || win.outerHeight != height) { - await resizeWindow(width, height); - await windowResizeChange(); - } + let debounce = new DebounceCallback(() => { + win.dispatchEvent(new win.CustomEvent("resizeEnd")); + }); + + await new TimedPromise(async resolve => { + if (win.outerWidth == width && win.outerHeight == height) { + resolve(); + return; + } + + win.addEventListener("resize", debounce); + win.addEventListener("resizeEnd", resolve, {once: true}); + win.resizeTo(width, height); + }, {timeout: 5000}); + + win.removeEventListener("resize", debounce); } if (x != null && y != null) {