Bug 985815 - fix customtoolbars test so it doesn't break subsequent tests, r=jaws, a=sledru.
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 26 Mar 2014 12:10:08 -0400
changeset 192326 a1cd9c6a28dbe89374cd1f9ea34dc13d37b74546
parent 192325 88e7ab08a67e5e64ad57841d6953fbe12808eba9
child 192327 953d64862b9bf50dcb9616c761bc20469a61df69
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, sledru
bugs985815
milestone30.0a2
Bug 985815 - fix customtoolbars test so it doesn't break subsequent tests, r=jaws, a=sledru.
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser_975719_customtoolbars_behaviour.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -2141,25 +2141,25 @@ let CustomizableUIInternal = {
     gSavedState = null;
     // Restore the state for each area to its defaults
     for (let [areaId,] of gAreas) {
       this.restoreStateForArea(areaId);
     }
   },
 
   _resetExtraToolbars: function(aFilter = null) {
-    let firstWindow = true; // Only need to persist once
+    let firstWindow = true; // Only need to unregister and persist once
     for (let [win, ] of gBuildWindows) {
       let toolbox = win.gNavToolbox;
       for (let child of toolbox.children) {
         let matchesFilter = !aFilter || aFilter == child.id;
         if (child.hasAttribute("customindex") && matchesFilter) {
+          let toolbarId = "toolbar" + child.getAttribute("customindex");
+          toolbox.toolbarset.removeAttribute(toolbarId);
           if (firstWindow) {
-            let toolbarId = "toolbar" + child.getAttribute("customindex");
-            toolbox.toolbarset.removeAttribute(toolbarId);
             win.document.persist(toolbox.toolbarset.id, toolbarId);
             // We have to unregister it properly to ensure we don't kill
             // XUL widgets which might be in here
             this.unregisterArea(child.id, true);
           }
           child.remove();
         }
       }
--- a/browser/components/customizableui/test/browser_975719_customtoolbars_behaviour.js
+++ b/browser/components/customizableui/test/browser_975719_customtoolbars_behaviour.js
@@ -25,41 +25,56 @@ add_task(function customizeToolbarAndKee
     toolbarElement.remove();
     return;
   }
   ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet.");
   CustomizableUI.addWidgetToArea("open-file-button", toolbarDOMID, 0);
   ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button.");
   assertAreaPlacements(toolbarDOMID, ["open-file-button"]);
 
+  gNavToolbox.toolbarset.setAttribute("toolbar1", toolbarID + ":open-file-button");
+  document.persist(gNavToolbox.toolbarset.id, "toolbar1");
+
   yield startCustomizing();
   // First, exit customize mode without doing anything, and verify the toolbar doesn't get removed.
   yield endCustomizing();
   ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state, the toolbar should still be there.");
   cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID);
   is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR,
      "CustomizableUI should still know the area and think it's a toolbar");
   ok(toolbarElement.parentNode, "Toolbar should still be in the DOM.");
   ok(toolbarElement.hasChildNodes(), "Toolbar should still have items in it.");
   assertAreaPlacements(toolbarDOMID, ["open-file-button"]);
 
+  let newWindow = yield openAndLoadWindow({}, true);
+  is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar1"),
+     gNavToolbox.toolbarset.getAttribute("toolbar1"),
+     "Attribute should be the same in new window");
+  yield promiseWindowClosed(newWindow);
+
   // Then customize again, and this time empty out the toolbar and verify it *does* get removed.
   yield startCustomizing();
   let openFileButton = document.getElementById("open-file-button");
   let palette = document.getElementById("customization-palette");
   simulateItemDrag(openFileButton, palette);
   ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's still a non-collapsed toolbar.");
   ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes.");
 
   toolbarElement.collapsed = true;
   ok(CustomizableUI.inDefaultState, "Should be in default state because there's now just a collapsed toolbar.");
   toolbarElement.collapsed = false;
   ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's a non-collapsed toolbar again.");
   yield endCustomizing();
   ok(CustomizableUI.inDefaultState, "Should be in default state because the toolbar should have been removed.");
+
+  newWindow = yield openAndLoadWindow({}, true);
+  ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar1"),
+     "Attribute should be gone in new window");
+  yield promiseWindowClosed(newWindow);
+
   ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM.");
   cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID);
   is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area");
 });
 
 add_task(function resetShouldDealWithCustomToolbars() {
   ok(gNavToolbox.toolbarset, "There should be a toolbarset");
   let toolbarID = "testAustralisCustomToolbar";
@@ -81,20 +96,41 @@ add_task(function resetShouldDealWithCus
     toolbarElement.remove();
     return;
   }
   ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet.");
   CustomizableUI.addWidgetToArea("sync-button", toolbarDOMID, 0);
   ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button.");
   assertAreaPlacements(toolbarDOMID, ["sync-button"]);
 
+  gNavToolbox.toolbarset.setAttribute("toolbar2", toolbarID + ":sync-button");
+  document.persist(gNavToolbox.toolbarset.id, "toolbar2");
+
+  let newWindow = yield openAndLoadWindow({}, true);
+  is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar2"),
+     gNavToolbox.toolbarset.getAttribute("toolbar2"),
+     "Attribute should be the same in new window");
+  yield promiseWindowClosed(newWindow);
+
   CustomizableUI.reset();
 
+  newWindow = yield openAndLoadWindow({}, true);
+  ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar2"),
+     "Attribute should be gone in new window");
+  yield promiseWindowClosed(newWindow);
+
   ok(CustomizableUI.inDefaultState, "Should be in default state after reset.");
   let syncButton = document.getElementById("sync-button");
   ok(!syncButton, "Sync button shouldn't be in the document anymore.");
   ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button should be in the palette");
   ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes.");
   ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM.");
   cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID);
   is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area");
 });
 
+
+add_task(function() {
+  let newWin = yield openAndLoadWindow({}, true);
+  ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar1"), "New window shouldn't have attribute toolbar1");
+  ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar2"), "New window shouldn't have attribute toolbar2");
+  yield promiseWindowClosed(newWin);
+});