From d0917b9009b343ebd39b69427d8f9093c0e99ba3 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Thu, 8 Nov 2018 13:11:26 +0000 Subject: [PATCH] bug 1492499: marionette: wait for last event on resizing window; r=automatedtester,whimboo My delegating to the main thread, waiting for the last DOM resize event to fire, and requesting an animation frame from the ChromeWindow, we can ensure the window is (more) synchronously resized. This ensures better reliability when setting a window's dimensions. All this means we can get rid of the heuristics we use for "waiting for a window resize" to occur by checking if the outerWidth/outerHeight has changed. These were obviously bug ridden. Depends on D8417 Differential Revision: https://phabricator.services.mozilla.com/D8418 --HG-- extra : moz-landing-system : lando --- testing/marionette/driver.js | 45 +++++++++++++----------------------- 1 file changed, 16 insertions(+), 29 deletions(-) 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) {