Commit d0917b90 authored by Andreas Tolfsen's avatar Andreas Tolfsen
Browse files

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
parent b85c42be
Loading
Loading
Loading
Loading
+16 −29
Original line number Diff line number Diff line
@@ -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) {