Bug 1483701 - Split and re-enable browser_ext_browserAction_popup_resize.js. r=mixedpuppy
☠☠ backed out by 5b918623055e ☠ ☠
authorLuca Greco <lgreco@mozilla.com>
Wed, 23 Jan 2019 17:24:07 +0000
changeset 515328 5852bd6e33d2dd79007c86fba5ac7a10df6e72b9
parent 515327 287d99a8f9a78e2d6b3f7dc1b4314c92dc30534e
child 515329 3f8aeb316a5ce9fd7aea4889eb2c361d6f262b88
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1483701
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1483701 - Split and re-enable browser_ext_browserAction_popup_resize.js. r=mixedpuppy This patch applies the following changes: - Reduce the chances of retrieving the initial popup panel size while it is resizing, by comparing the content dimensions retrieved before and after the delay (which is already set to a value comparable to the time used by the resize debouncing timer), and wait until both the dimensions collected are the same - split browser_ext_browserAction_popup_resize.js into two test files (as it seems, based on the investigations I did by reproducing this intermittent locally, that the part that can still fail intermittently from time to time with the change describe above is related to the testBrowserActionMenuResizeBottomArrow test case) - move the test helpers shared between the two test files into a new head_browserAction.js support file - re-enabled browser_ext_browserAction_popup_resize.js - mark the new browser_ext_browserAction_popup_resize_bottom.js as disabled on debug build, because it is consistently triggering a "shutdown leak" failure when running locally Differential Revision: https://phabricator.services.mozilla.com/D17267
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize_bottom.js
browser/components/extensions/test/browser/head.js
browser/components/extensions/test/browser/head_browserAction.js
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 prefs =
     dom.animations-api.core.enabled=true
     dom.animations-api.timelines.enabled=true
 support-files =
   silence.ogg
+  head_browserAction.js
   head_pageAction.js
   head_sessions.js
   head_webNavigation.js
   context.html
   context_frame.html
   ctxmenu-image.png
   context_tabs_onUpdated_page.html
   context_tabs_onUpdated_iframe.html
@@ -55,17 +56,18 @@ skip-if = os == 'linux'
 [browser_ext_browserAction_pageAction_icon.js]
 [browser_ext_browserAction_pageAction_icon_permissions.js]
 [browser_ext_browserAction_popup.js]
 skip-if = (debug && os == 'linux' && bits == 32) || (os == 'win' && !debug) # Bug 1313372, win: Bug 1285500
 [browser_ext_browserAction_popup_port.js]
 [browser_ext_browserAction_popup_preload.js]
 skip-if = (os == 'win' && !debug) || (verify && debug && (os == 'mac')) # bug 1352668
 [browser_ext_browserAction_popup_resize.js]
-skip-if = (os == 'mac' || os == 'win' || os == 'linux') || (verify && debug) #Bug 1482004,1483701
+[browser_ext_browserAction_popup_resize_bottom.js]
+skip-if = debug # Bug 1522164
 [browser_ext_browserAction_simple.js]
 [browser_ext_browserAction_telemetry.js]
 [browser_ext_browserAction_theme_icons.js]
 [browser_ext_browsingData_formData.js]
 [browser_ext_browsingData_history.js]
 [browser_ext_browsingData_indexedDB.js]
 [browser_ext_browsingData_localStorage.js]
 [browser_ext_browsingData_pluginData.js]
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
@@ -1,17 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-function openPanel(extension, win = window, awaitLoad = false) {
-  clickBrowserAction(extension, win);
-
-  return awaitExtensionPanel(extension, win, awaitLoad);
-}
+Services.scriptloader.loadSubScript(new URL("head_browserAction.js", gTestPath).href,
+                                    this);
 
 add_task(async function testSetup() {
   Services.prefs.setBoolPref("toolkit.cosmeticAnimations.enabled", false);
 });
 
 add_task(async function testBrowserActionPopupResize() {
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
@@ -23,17 +20,17 @@ add_task(async function testBrowserActio
 
     files: {
       "popup.html": '<!DOCTYPE html><html><head><meta charset="utf-8"></head></html>',
     },
   });
 
   await extension.startup();
 
-  let browser = await openPanel(extension, undefined, true);
+  let browser = await openBrowserActionPanel(extension, undefined, true);
 
   async function checkSize(expected) {
     let dims = await promiseContentDimensions(browser);
 
     Assert.lessOrEqual(Math.abs(dims.window.innerHeight - expected), 1,
                        `Panel window should be ${expected}px tall (was ${dims.window.innerHeight})`);
     is(dims.body.clientHeight, dims.body.scrollHeight,
        "Panel body should be tall enough to fit its contents");
@@ -56,267 +53,27 @@ add_task(async function testBrowserActio
     300,
   ];
 
   for (let size of sizes) {
     await alterContent(browser, setSize, size);
     await checkSize(size);
   }
 
+  let popup = getBrowserActionPopup(extension);
   await closeBrowserAction(extension);
+  is(popup.state, "closed", "browserAction popup has been closed");
+
   await extension.unload();
 });
 
-async function testPopupSize(standardsMode, browserWin = window, arrowSide = "top") {
-  let docType = standardsMode ? "<!DOCTYPE html>" : "";
-
-  let extension = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "browser_action": {
-        "default_popup": "popup.html",
-        "browser_style": false,
-      },
-    },
-
-    files: {
-      "popup.html": `${docType}
-        <html>
-          <head>
-            <meta charset="utf-8">
-            <style type="text/css">
-              body > span {
-                display: inline-block;
-                width: 10px;
-                height: 150px;
-                border: 2px solid black;
-              }
-              .big > span {
-                width: 300px;
-                height: 100px;
-              }
-              .bigger > span {
-                width: 150px;
-                height: 150px;
-              }
-              .huge > span {
-                height: ${2 * screen.height}px;
-              }
-            </style>
-          </head>
-          <body>
-            <span></span>
-            <span></span>
-            <span></span>
-            <span></span>
-          </body>
-        </html>`,
-    },
-  });
-
-  await extension.startup();
-
-  if (arrowSide == "top") {
-    // Test the standalone panel for a toolbar button.
-    let browser = await openPanel(extension, browserWin, true);
-
-    let dims = await promiseContentDimensions(browser);
-
-    is(dims.isStandards, standardsMode, "Document has the expected compat mode");
-
-    let {innerWidth, innerHeight} = dims.window;
-
-    dims = await alterContent(browser, () => {
-      content.document.body.classList.add("bigger");
-    });
-
-    let win = dims.window;
-    is(win.innerHeight, innerHeight, "Window height should not change");
-    ok(win.innerWidth > innerWidth, `Window width should increase (${win.innerWidth} > ${innerWidth})`);
-
-
-    dims = await alterContent(browser, () => {
-      content.document.body.classList.remove("bigger");
-    });
-
-    win = dims.window;
-    is(win.innerHeight, innerHeight, "Window height should not change");
-
-    // The getContentSize calculation is not always reliable to single-pixel
-    // precision.
-    ok(Math.abs(win.innerWidth - innerWidth) <= 1,
-       `Window width should return to approximately its original value (${win.innerWidth} ~= ${innerWidth})`);
-
-    await closeBrowserAction(extension, browserWin);
-  }
-
-
-  // Test the PanelUI panel for a menu panel button.
-  let widget = getBrowserActionWidget(extension);
-  CustomizableUI.addWidgetToArea(widget.id, getCustomizableUIPanelID());
-
-  let panel = browserWin.PanelUI.overflowPanel;
-  panel.setAttribute("animate", "false");
-
-  let panelMultiView = panel.firstElementChild;
-  let widgetId = makeWidgetId(extension.id);
-  // The 'ViewShown' event is the only way to correctly determine when the extensions'
-  // panelview has finished transitioning and is fully in view.
-  let shownPromise = BrowserTestUtils.waitForEvent(panelMultiView, "ViewShown",
-                                                   e => (e.originalTarget.id || "").includes(widgetId));
-  let browser = await openPanel(extension, browserWin);
-  let origPanelRect = panel.getBoundingClientRect();
-
-  // Check that the panel is still positioned as expected.
-  let checkPanelPosition = () => {
-    is(panel.getAttribute("side"), arrowSide, "Panel arrow is positioned as expected");
-
-    let panelRect = panel.getBoundingClientRect();
-    if (arrowSide == "top") {
-      is(panelRect.top, origPanelRect.top, "Panel has not moved downwards");
-      ok(panelRect.bottom >= origPanelRect.bottom, `Panel has not shrunk from original size (${panelRect.bottom} >= ${origPanelRect.bottom})`);
-
-      let screenBottom = browserWin.screen.availTop + browserWin.screen.availHeight;
-      let panelBottom = browserWin.mozInnerScreenY + panelRect.bottom;
-      ok(Math.round(panelBottom) <= screenBottom, `Bottom of popup should be on-screen. (${panelBottom} <= ${screenBottom})`);
-    } else {
-      is(panelRect.bottom, origPanelRect.bottom, "Panel has not moved upwards");
-      ok(panelRect.top <= origPanelRect.top, `Panel has not shrunk from original size (${panelRect.top} <= ${origPanelRect.top})`);
-
-      let panelTop = browserWin.mozInnerScreenY + panelRect.top;
-      ok(panelTop >= browserWin.screen.availTop, `Top of popup should be on-screen. (${panelTop} >= ${browserWin.screen.availTop})`);
-    }
-  };
-
-  await awaitBrowserLoaded(browser);
-  await shownPromise;
-
-  // Wait long enough to make sure the initial resize debouncing timer has
-  // expired.
-  await delay(500);
-
-  let dims = await promiseContentDimensions(browser);
-
-  is(dims.isStandards, standardsMode, "Document has the expected compat mode");
-
-  // If the browser's preferred height is smaller than the initial height of the
-  // panel, then it will still take up the full available vertical space. Even
-  // so, we need to check that we've gotten the preferred height calculation
-  // correct, so check that explicitly.
-  let getHeight = () => parseFloat(browser.style.height);
-
-  let {innerWidth, innerHeight} = dims.window;
-  let height = getHeight();
-
-
-  let setClass = className => {
-    content.document.body.className = className;
-  };
-
-  info("Increase body children's width. " +
-       "Expect them to wrap, and the frame to grow vertically rather than widen.");
-
-  dims = await alterContent(browser, setClass, "big");
-  let win = dims.window;
-
-  ok(getHeight() > height, `Browser height should increase (${getHeight()} > ${height})`);
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  ok(win.innerHeight >= innerHeight, `Window height should increase (${win.innerHeight} >= ${innerHeight})`);
-  Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
-
-  checkPanelPosition();
-
-
-  info("Increase body children's width and height. " +
-       "Expect them to wrap, and the frame to grow vertically rather than widen.");
-
-  dims = await alterContent(browser, setClass, "bigger");
-  win = dims.window;
-
-  ok(getHeight() > height, `Browser height should increase (${getHeight()} > ${height})`);
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  ok(win.innerHeight >= innerHeight, `Window height should increase (${win.innerHeight} >= ${innerHeight})`);
-  Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
-
-  checkPanelPosition();
-
-
-  info("Increase body height beyond the height of the screen. " +
-       "Expect the panel to grow to accommodate, but not larger than the height of the screen.");
-
-  dims = await alterContent(browser, setClass, "huge");
-  win = dims.window;
-
-  ok(getHeight() > height, `Browser height should increase (${getHeight()} > ${height})`);
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  ok(win.innerHeight > innerHeight, `Window height should increase (${win.innerHeight} > ${innerHeight})`);
-  // Commented out check for the window height here which mysteriously breaks
-  // on infra but not locally. bug 1396843 covers re-enabling this.
-  // ok(win.innerHeight < screen.height, `Window height be less than the screen height (${win.innerHeight} < ${screen.height})`);
-  ok(win.scrollMaxY > 0, `Document should be vertically scrollable (${win.scrollMaxY} > 0)`);
-
-  checkPanelPosition();
-
-
-  info("Restore original styling. Expect original dimensions.");
-  dims = await alterContent(browser, setClass, "");
-  win = dims.window;
-
-  is(getHeight(), height, "Browser height should return to its original value");
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  is(win.innerHeight, innerHeight, "Window height should return to its original value");
-  Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
-
-  checkPanelPosition();
-
-  await closeBrowserAction(extension, browserWin);
-
-  await extension.unload();
-}
 
 add_task(async function testBrowserActionMenuResizeStandards() {
   await testPopupSize(true);
 });
 
 add_task(async function testBrowserActionMenuResizeQuirks() {
   await testPopupSize(false);
 });
 
-// Test that we still make reasonable maximum size calculations when the window
-// is close enough to the bottom of the screen that the menu panel opens above,
-// rather than below, its button.
-add_task(async function testBrowserActionMenuResizeBottomArrow() {
-  const WIDTH = 800;
-  const HEIGHT = 80;
-
-  let left = screen.availLeft + screen.availWidth - WIDTH;
-  let top = screen.availTop + screen.availHeight - HEIGHT;
-
-  let win = await BrowserTestUtils.openNewBrowserWindow();
-
-  win.resizeTo(WIDTH, HEIGHT);
-
-  // Sometimes we run into problems on Linux with resizing being asynchronous
-  // and window managers not allowing us to move the window so that any part of
-  // it is off-screen, so we need to try more than once.
-  for (let i = 0; i < 20; i++) {
-    win.moveTo(left, top);
-
-    if (win.screenX == left && win.screenY == top) {
-      break;
-    }
-
-    await delay(100);
-  }
-
-  await SimpleTest.promiseFocus(win);
-
-  await testPopupSize(true, win, "bottom");
-
-  await BrowserTestUtils.closeWindow(win);
-});
-
 add_task(async function testTeardown() {
   Services.prefs.clearUserPref("toolkit.cosmeticAnimations.enabled");
 });
copy from browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
copy to browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize_bottom.js
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize_bottom.js
@@ -1,293 +1,19 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-function openPanel(extension, win = window, awaitLoad = false) {
-  clickBrowserAction(extension, win);
-
-  return awaitExtensionPanel(extension, win, awaitLoad);
-}
+Services.scriptloader.loadSubScript(new URL("head_browserAction.js", gTestPath).href,
+                                    this);
 
 add_task(async function testSetup() {
   Services.prefs.setBoolPref("toolkit.cosmeticAnimations.enabled", false);
 });
 
-add_task(async function testBrowserActionPopupResize() {
-  let extension = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "browser_action": {
-        "default_popup": "popup.html",
-        "browser_style": true,
-      },
-    },
-
-    files: {
-      "popup.html": '<!DOCTYPE html><html><head><meta charset="utf-8"></head></html>',
-    },
-  });
-
-  await extension.startup();
-
-  let browser = await openPanel(extension, undefined, true);
-
-  async function checkSize(expected) {
-    let dims = await promiseContentDimensions(browser);
-
-    Assert.lessOrEqual(Math.abs(dims.window.innerHeight - expected), 1,
-                       `Panel window should be ${expected}px tall (was ${dims.window.innerHeight})`);
-    is(dims.body.clientHeight, dims.body.scrollHeight,
-       "Panel body should be tall enough to fit its contents");
-
-    // Tolerate if it is 1px too wide, as that may happen with the current resizing method.
-    Assert.lessOrEqual(Math.abs(dims.window.innerWidth - expected), 1,
-                       `Panel window should be ${expected}px wide`);
-    is(dims.body.clientWidth, dims.body.scrollWidth,
-       "Panel body should be wide enough to fit its contents");
-  }
-
-  function setSize(size) {
-    content.document.body.style.height = `${size}px`;
-    content.document.body.style.width = `${size}px`;
-  }
-
-  let sizes = [
-    200,
-    400,
-    300,
-  ];
-
-  for (let size of sizes) {
-    await alterContent(browser, setSize, size);
-    await checkSize(size);
-  }
-
-  await closeBrowserAction(extension);
-  await extension.unload();
-});
-
-async function testPopupSize(standardsMode, browserWin = window, arrowSide = "top") {
-  let docType = standardsMode ? "<!DOCTYPE html>" : "";
-
-  let extension = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "browser_action": {
-        "default_popup": "popup.html",
-        "browser_style": false,
-      },
-    },
-
-    files: {
-      "popup.html": `${docType}
-        <html>
-          <head>
-            <meta charset="utf-8">
-            <style type="text/css">
-              body > span {
-                display: inline-block;
-                width: 10px;
-                height: 150px;
-                border: 2px solid black;
-              }
-              .big > span {
-                width: 300px;
-                height: 100px;
-              }
-              .bigger > span {
-                width: 150px;
-                height: 150px;
-              }
-              .huge > span {
-                height: ${2 * screen.height}px;
-              }
-            </style>
-          </head>
-          <body>
-            <span></span>
-            <span></span>
-            <span></span>
-            <span></span>
-          </body>
-        </html>`,
-    },
-  });
-
-  await extension.startup();
-
-  if (arrowSide == "top") {
-    // Test the standalone panel for a toolbar button.
-    let browser = await openPanel(extension, browserWin, true);
-
-    let dims = await promiseContentDimensions(browser);
-
-    is(dims.isStandards, standardsMode, "Document has the expected compat mode");
-
-    let {innerWidth, innerHeight} = dims.window;
-
-    dims = await alterContent(browser, () => {
-      content.document.body.classList.add("bigger");
-    });
-
-    let win = dims.window;
-    is(win.innerHeight, innerHeight, "Window height should not change");
-    ok(win.innerWidth > innerWidth, `Window width should increase (${win.innerWidth} > ${innerWidth})`);
-
-
-    dims = await alterContent(browser, () => {
-      content.document.body.classList.remove("bigger");
-    });
-
-    win = dims.window;
-    is(win.innerHeight, innerHeight, "Window height should not change");
-
-    // The getContentSize calculation is not always reliable to single-pixel
-    // precision.
-    ok(Math.abs(win.innerWidth - innerWidth) <= 1,
-       `Window width should return to approximately its original value (${win.innerWidth} ~= ${innerWidth})`);
-
-    await closeBrowserAction(extension, browserWin);
-  }
-
-
-  // Test the PanelUI panel for a menu panel button.
-  let widget = getBrowserActionWidget(extension);
-  CustomizableUI.addWidgetToArea(widget.id, getCustomizableUIPanelID());
-
-  let panel = browserWin.PanelUI.overflowPanel;
-  panel.setAttribute("animate", "false");
-
-  let panelMultiView = panel.firstElementChild;
-  let widgetId = makeWidgetId(extension.id);
-  // The 'ViewShown' event is the only way to correctly determine when the extensions'
-  // panelview has finished transitioning and is fully in view.
-  let shownPromise = BrowserTestUtils.waitForEvent(panelMultiView, "ViewShown",
-                                                   e => (e.originalTarget.id || "").includes(widgetId));
-  let browser = await openPanel(extension, browserWin);
-  let origPanelRect = panel.getBoundingClientRect();
-
-  // Check that the panel is still positioned as expected.
-  let checkPanelPosition = () => {
-    is(panel.getAttribute("side"), arrowSide, "Panel arrow is positioned as expected");
-
-    let panelRect = panel.getBoundingClientRect();
-    if (arrowSide == "top") {
-      is(panelRect.top, origPanelRect.top, "Panel has not moved downwards");
-      ok(panelRect.bottom >= origPanelRect.bottom, `Panel has not shrunk from original size (${panelRect.bottom} >= ${origPanelRect.bottom})`);
-
-      let screenBottom = browserWin.screen.availTop + browserWin.screen.availHeight;
-      let panelBottom = browserWin.mozInnerScreenY + panelRect.bottom;
-      ok(Math.round(panelBottom) <= screenBottom, `Bottom of popup should be on-screen. (${panelBottom} <= ${screenBottom})`);
-    } else {
-      is(panelRect.bottom, origPanelRect.bottom, "Panel has not moved upwards");
-      ok(panelRect.top <= origPanelRect.top, `Panel has not shrunk from original size (${panelRect.top} <= ${origPanelRect.top})`);
-
-      let panelTop = browserWin.mozInnerScreenY + panelRect.top;
-      ok(panelTop >= browserWin.screen.availTop, `Top of popup should be on-screen. (${panelTop} >= ${browserWin.screen.availTop})`);
-    }
-  };
-
-  await awaitBrowserLoaded(browser);
-  await shownPromise;
-
-  // Wait long enough to make sure the initial resize debouncing timer has
-  // expired.
-  await delay(500);
-
-  let dims = await promiseContentDimensions(browser);
-
-  is(dims.isStandards, standardsMode, "Document has the expected compat mode");
-
-  // If the browser's preferred height is smaller than the initial height of the
-  // panel, then it will still take up the full available vertical space. Even
-  // so, we need to check that we've gotten the preferred height calculation
-  // correct, so check that explicitly.
-  let getHeight = () => parseFloat(browser.style.height);
-
-  let {innerWidth, innerHeight} = dims.window;
-  let height = getHeight();
-
-
-  let setClass = className => {
-    content.document.body.className = className;
-  };
-
-  info("Increase body children's width. " +
-       "Expect them to wrap, and the frame to grow vertically rather than widen.");
-
-  dims = await alterContent(browser, setClass, "big");
-  let win = dims.window;
-
-  ok(getHeight() > height, `Browser height should increase (${getHeight()} > ${height})`);
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  ok(win.innerHeight >= innerHeight, `Window height should increase (${win.innerHeight} >= ${innerHeight})`);
-  Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
-
-  checkPanelPosition();
-
-
-  info("Increase body children's width and height. " +
-       "Expect them to wrap, and the frame to grow vertically rather than widen.");
-
-  dims = await alterContent(browser, setClass, "bigger");
-  win = dims.window;
-
-  ok(getHeight() > height, `Browser height should increase (${getHeight()} > ${height})`);
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  ok(win.innerHeight >= innerHeight, `Window height should increase (${win.innerHeight} >= ${innerHeight})`);
-  Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
-
-  checkPanelPosition();
-
-
-  info("Increase body height beyond the height of the screen. " +
-       "Expect the panel to grow to accommodate, but not larger than the height of the screen.");
-
-  dims = await alterContent(browser, setClass, "huge");
-  win = dims.window;
-
-  ok(getHeight() > height, `Browser height should increase (${getHeight()} > ${height})`);
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  ok(win.innerHeight > innerHeight, `Window height should increase (${win.innerHeight} > ${innerHeight})`);
-  // Commented out check for the window height here which mysteriously breaks
-  // on infra but not locally. bug 1396843 covers re-enabling this.
-  // ok(win.innerHeight < screen.height, `Window height be less than the screen height (${win.innerHeight} < ${screen.height})`);
-  ok(win.scrollMaxY > 0, `Document should be vertically scrollable (${win.scrollMaxY} > 0)`);
-
-  checkPanelPosition();
-
-
-  info("Restore original styling. Expect original dimensions.");
-  dims = await alterContent(browser, setClass, "");
-  win = dims.window;
-
-  is(getHeight(), height, "Browser height should return to its original value");
-
-  is(win.innerWidth, innerWidth, "Window width should not change");
-  is(win.innerHeight, innerHeight, "Window height should return to its original value");
-  Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
-
-  checkPanelPosition();
-
-  await closeBrowserAction(extension, browserWin);
-
-  await extension.unload();
-}
-
-add_task(async function testBrowserActionMenuResizeStandards() {
-  await testPopupSize(true);
-});
-
-add_task(async function testBrowserActionMenuResizeQuirks() {
-  await testPopupSize(false);
-});
-
 // Test that we still make reasonable maximum size calculations when the window
 // is close enough to the bottom of the screen that the menu panel opens above,
 // rather than below, its button.
 add_task(async function testBrowserActionMenuResizeBottomArrow() {
   const WIDTH = 800;
   const HEIGHT = 80;
 
   let left = screen.availLeft + screen.availWidth - WIDTH;
@@ -295,25 +21,22 @@ add_task(async function testBrowserActio
 
   let win = await BrowserTestUtils.openNewBrowserWindow();
 
   win.resizeTo(WIDTH, HEIGHT);
 
   // Sometimes we run into problems on Linux with resizing being asynchronous
   // and window managers not allowing us to move the window so that any part of
   // it is off-screen, so we need to try more than once.
-  for (let i = 0; i < 20; i++) {
+  await BrowserTestUtils.waitForCondition(async () => {
     win.moveTo(left, top);
+    await delay(100);
 
-    if (win.screenX == left && win.screenY == top) {
-      break;
-    }
-
-    await delay(100);
-  }
+    return win.screenX == left && win.screenY == top;
+  }, "Wait the new browser window to be positioned correctly");
 
   await SimpleTest.promiseFocus(win);
 
   await testPopupSize(true, win, "bottom");
 
   await BrowserTestUtils.closeWindow(win);
 });
 
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -1,16 +1,17 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 /* exported CustomizableUI makeWidgetId focusWindow forceGC
  *          getBrowserActionWidget
  *          clickBrowserAction clickPageAction
  *          getBrowserActionPopup getPageActionPopup getPageActionButton
+ *          openBrowserActionPanel
  *          closeBrowserAction closePageAction
  *          promisePopupShown promisePopupHidden
  *          toggleBookmarksToolbar
  *          openContextMenu closeContextMenu
  *          openContextMenuInSidebar openContextMenuInPopup
  *          openExtensionContextMenu closeExtensionContextMenu
  *          openActionContextMenu openSubmenu closeActionContextMenu
  *          openTabContextMenu closeTabContextMenu
@@ -283,16 +284,22 @@ function closeBrowserAction(extension, w
   let group = getBrowserActionWidget(extension);
 
   let node = win.document.getElementById(group.viewId);
   CustomizableUI.hidePanelForNode(node);
 
   return Promise.resolve();
 }
 
+function openBrowserActionPanel(extension, win = window, awaitLoad = false) {
+  clickBrowserAction(extension, win);
+
+  return awaitExtensionPanel(extension, win, awaitLoad);
+}
+
 async function toggleBookmarksToolbar(visible = true) {
   let bookmarksToolbar = document.getElementById("PersonalToolbar");
   let transitionPromise =
     BrowserTestUtils.waitForEvent(bookmarksToolbar, "transitionend",
                                   e => e.propertyName == "max-height");
 
   setToolbarVisibility(bookmarksToolbar, visible);
   await transitionPromise;
copy from browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
copy to browser/components/extensions/test/browser/head_browserAction.js
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
+++ b/browser/components/extensions/test/browser/head_browserAction.js
@@ -1,74 +1,17 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-function openPanel(extension, win = window, awaitLoad = false) {
-  clickBrowserAction(extension, win);
-
-  return awaitExtensionPanel(extension, win, awaitLoad);
-}
-
-add_task(async function testSetup() {
-  Services.prefs.setBoolPref("toolkit.cosmeticAnimations.enabled", false);
-});
-
-add_task(async function testBrowserActionPopupResize() {
-  let extension = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "browser_action": {
-        "default_popup": "popup.html",
-        "browser_style": true,
-      },
-    },
-
-    files: {
-      "popup.html": '<!DOCTYPE html><html><head><meta charset="utf-8"></head></html>',
-    },
-  });
-
-  await extension.startup();
-
-  let browser = await openPanel(extension, undefined, true);
-
-  async function checkSize(expected) {
-    let dims = await promiseContentDimensions(browser);
+/* exported testPopupSize */
 
-    Assert.lessOrEqual(Math.abs(dims.window.innerHeight - expected), 1,
-                       `Panel window should be ${expected}px tall (was ${dims.window.innerHeight})`);
-    is(dims.body.clientHeight, dims.body.scrollHeight,
-       "Panel body should be tall enough to fit its contents");
-
-    // Tolerate if it is 1px too wide, as that may happen with the current resizing method.
-    Assert.lessOrEqual(Math.abs(dims.window.innerWidth - expected), 1,
-                       `Panel window should be ${expected}px wide`);
-    is(dims.body.clientWidth, dims.body.scrollWidth,
-       "Panel body should be wide enough to fit its contents");
-  }
+// This file is imported into the same scope as head.js.
 
-  function setSize(size) {
-    content.document.body.style.height = `${size}px`;
-    content.document.body.style.width = `${size}px`;
-  }
-
-  let sizes = [
-    200,
-    400,
-    300,
-  ];
-
-  for (let size of sizes) {
-    await alterContent(browser, setSize, size);
-    await checkSize(size);
-  }
-
-  await closeBrowserAction(extension);
-  await extension.unload();
-});
+/* import-globals-from head.js */
 
 async function testPopupSize(standardsMode, browserWin = window, arrowSide = "top") {
   let docType = standardsMode ? "<!DOCTYPE html>" : "";
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "browser_action": {
         "default_popup": "popup.html",
@@ -110,17 +53,17 @@ async function testPopupSize(standardsMo
         </html>`,
     },
   });
 
   await extension.startup();
 
   if (arrowSide == "top") {
     // Test the standalone panel for a toolbar button.
-    let browser = await openPanel(extension, browserWin, true);
+    let browser = await openBrowserActionPanel(extension, browserWin, true);
 
     let dims = await promiseContentDimensions(browser);
 
     is(dims.isStandards, standardsMode, "Document has the expected compat mode");
 
     let {innerWidth, innerHeight} = dims.window;
 
     dims = await alterContent(browser, () => {
@@ -156,17 +99,17 @@ async function testPopupSize(standardsMo
   panel.setAttribute("animate", "false");
 
   let panelMultiView = panel.firstElementChild;
   let widgetId = makeWidgetId(extension.id);
   // The 'ViewShown' event is the only way to correctly determine when the extensions'
   // panelview has finished transitioning and is fully in view.
   let shownPromise = BrowserTestUtils.waitForEvent(panelMultiView, "ViewShown",
                                                    e => (e.originalTarget.id || "").includes(widgetId));
-  let browser = await openPanel(extension, browserWin);
+  let browser = await openBrowserActionPanel(extension, browserWin);
   let origPanelRect = panel.getBoundingClientRect();
 
   // Check that the panel is still positioned as expected.
   let checkPanelPosition = () => {
     is(panel.getAttribute("side"), arrowSide, "Panel arrow is positioned as expected");
 
     let panelRect = panel.getBoundingClientRect();
     if (arrowSide == "top") {
@@ -185,32 +128,38 @@ async function testPopupSize(standardsMo
     }
   };
 
   await awaitBrowserLoaded(browser);
   await shownPromise;
 
   // Wait long enough to make sure the initial resize debouncing timer has
   // expired.
-  await delay(500);
+  await BrowserTestUtils.waitForCondition(async () => {
+    let oldDims = await promiseContentDimensions(browser);
+    await delay(500);
+    let newDims = await promiseContentDimensions(browser);
+
+    return oldDims.window.innerWidth === newDims.window.innerWidth &&
+      oldDims.window.innerHeight === newDims.window.innerHeight;
+  }, "Wait the popup resize to be completed");
 
   let dims = await promiseContentDimensions(browser);
 
   is(dims.isStandards, standardsMode, "Document has the expected compat mode");
 
   // If the browser's preferred height is smaller than the initial height of the
   // panel, then it will still take up the full available vertical space. Even
   // so, we need to check that we've gotten the preferred height calculation
   // correct, so check that explicitly.
   let getHeight = () => parseFloat(browser.style.height);
 
   let {innerWidth, innerHeight} = dims.window;
   let height = getHeight();
 
-
   let setClass = className => {
     content.document.body.className = className;
   };
 
   info("Increase body children's width. " +
        "Expect them to wrap, and the frame to grow vertically rather than widen.");
 
   dims = await alterContent(browser, setClass, "big");
@@ -269,54 +218,8 @@ async function testPopupSize(standardsMo
   Assert.lessOrEqual(win.scrollMaxY, 1, "Document should not be vertically scrollable");
 
   checkPanelPosition();
 
   await closeBrowserAction(extension, browserWin);
 
   await extension.unload();
 }
-
-add_task(async function testBrowserActionMenuResizeStandards() {
-  await testPopupSize(true);
-});
-
-add_task(async function testBrowserActionMenuResizeQuirks() {
-  await testPopupSize(false);
-});
-
-// Test that we still make reasonable maximum size calculations when the window
-// is close enough to the bottom of the screen that the menu panel opens above,
-// rather than below, its button.
-add_task(async function testBrowserActionMenuResizeBottomArrow() {
-  const WIDTH = 800;
-  const HEIGHT = 80;
-
-  let left = screen.availLeft + screen.availWidth - WIDTH;
-  let top = screen.availTop + screen.availHeight - HEIGHT;
-
-  let win = await BrowserTestUtils.openNewBrowserWindow();
-
-  win.resizeTo(WIDTH, HEIGHT);
-
-  // Sometimes we run into problems on Linux with resizing being asynchronous
-  // and window managers not allowing us to move the window so that any part of
-  // it is off-screen, so we need to try more than once.
-  for (let i = 0; i < 20; i++) {
-    win.moveTo(left, top);
-
-    if (win.screenX == left && win.screenY == top) {
-      break;
-    }
-
-    await delay(100);
-  }
-
-  await SimpleTest.promiseFocus(win);
-
-  await testPopupSize(true, win, "bottom");
-
-  await BrowserTestUtils.closeWindow(win);
-});
-
-add_task(async function testTeardown() {
-  Services.prefs.clearUserPref("toolkit.cosmeticAnimations.enabled");
-});