Bug 1292128 - Regenerate XBL binding for page style menu at the end of the browser_bug422590 mochitest. draft
authorZibi Braniecki <gandalf@mozilla.com>
Wed, 16 Nov 2016 15:45:20 -0800
changeset 440049 e6474ea2be0cb5ba517a3b06f3bcf6b53eb55f97
parent 440048 c0ac2b41e254882bacebc8fccebefce41b28b6bb
child 537300 c7f7c46b564e8db2af9d3c9319e1a93af8c72b5e
push id36147
push userzbraniecki@mozilla.com
push dateWed, 16 Nov 2016 23:45:50 +0000
bugs1292128, 422590
milestone53.0a1
Bug 1292128 - Regenerate XBL binding for page style menu at the end of the browser_bug422590 mochitest. MozReview-Commit-ID: JwmTyTt6EFL
browser/base/content/test/general/browser_bug422590.js
--- a/browser/base/content/test/general/browser_bug422590.js
+++ b/browser/base/content/test/general/browser_bug422590.js
@@ -1,14 +1,31 @@
 function test() {
   waitForExplicitFinish();
   // test the main (normal) browser window
   testCustomize(window, testChromeless);
 }
 
+function triggerShowingMenu() {
+  let menubarToolbar = document.getElementById("toolbar-menubar");
+  if (AppConstants.platform != "macosx" &&
+      menubarToolbar.getAttribute("autohide") == "true") {
+    registerCleanupFunction(() => setToolbarVisibility(menubarToolbar, false));
+    // show the menu toolbar
+    setToolbarVisibility(menubarToolbar, true);
+  }
+
+  let viewMenu = document.getElementById("view-menu");
+  let popupShownPromise =
+    BrowserTestUtils.waitForEvent(viewMenu.menupopup, "popupshown");
+  // and open the file menu
+  viewMenu.open = true;
+  return popupShownPromise;
+}
+
 function testChromeless() {
   // test a chromeless window
   var newWin = openDialog(getBrowserURL(), "_blank",
                           "chrome,dialog=no,location=yes,toolbar=no", "about:blank");
   ok(newWin, "got new window");
 
   whenDelayedStartupFinished(newWin, function () {
     // Check that the search bar is hidden
@@ -39,12 +56,23 @@ function testCustomize(aWindow, aCallbac
 
     closeToolbarCustomizationUI(onClose, aWindow);
   }, aWindow);
 
   function onClose() {
     is(fileMenu.getAttribute("disabled"), "false",
        "file menu is enabled after toolbar customization");
 
-    if (aCallback)
-      aCallback();
+    // When this test removes the menu from the document, Gecko removes
+    // the associated XBL binding.
+    //
+    // Although the test adds the menu back, the XBL bindings are not
+    // reinstalled until its painted again.
+    //
+    // In order to *really* cleanup here, we need to force painting
+    // of the menu.
+    triggerShowingMenu().then(() => {
+      if (aCallback) {
+        aCallback();
+      }
+    });
   }
 }