Bug 1420583 - fix new tab adjacency logic when using "restore defaults", r?jaws draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 27 Nov 2017 15:23:42 +0000
changeset 703713 42201b479f87bffbdb3f11e9dd1b06da11c94d25
parent 703662 cad9c9573579698c223b4b6cb53ca723cd930ad2
child 741882 aee7b067424e2974c269fee0c1c52af64d3c77d0
push id90937
push usergijskruitbosch@gmail.com
push dateMon, 27 Nov 2017 15:24:44 +0000
reviewersjaws
bugs1420583
milestone59.0a1
Bug 1420583 - fix new tab adjacency logic when using "restore defaults", r?jaws When using "restore defaults", Customize mode unwraps all elements. The previous implementation of _updateNewTabVisibility assumed that elements were wrapped in <toolbarpaletteitem>s when in customize mode, but this isn't true during a reset. The new implementation just looks for the <toolbarpaletteitem>s and their children as necessary. MozReview-Commit-ID: FjNJ1n8foGi
browser/base/content/tabbrowser.xml
browser/components/customizableui/test/browser_newtab_button_customizemode.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -5858,32 +5858,24 @@
               break;
             }
           }
         ]]></body>
       </method>
 
       <method name="_updateNewTabVisibility">
         <body><![CDATA[
-          let isCustomizing = this.tabContainer.parentNode.getAttribute("customizing") == "true";
-
-          // Confusingly, the <tabs> are never wrapped in <toolbarpaletteitem>s in customize mode,
-          // but the other items will be.
-          let sib = this.tabContainer.nextElementSibling;
-          if (isCustomizing) {
-            sib = sib && sib.firstElementChild;
-          }
-          while (sib && sib.hidden) {
-            if (isCustomizing) {
-              sib = sib.parentNode.nextElementSibling;
-              sib = sib && sib.firstElementChild;
-            } else {
-              sib = sib.nextElementSibling;
-            }
-          }
+          // Helper functions to help deal with customize mode wrapping some items
+          let wrap = n => n.parentNode.localName == "toolbarpaletteitem" ? n.parentNode : n;
+          let unwrap = n => n && n.localName == "toolbarpaletteitem" ? n.firstElementChild : n;
+
+          let sib = this.tabContainer;
+          do {
+            sib = unwrap(wrap(sib).nextElementSibling);
+          } while (sib && sib.hidden);
 
           const kAttr = "hasadjacentnewtabbutton";
           if (sib && sib.id == "new-tab-button") {
             this.tabContainer.setAttribute(kAttr, "true");
           } else {
             this.tabContainer.removeAttribute(kAttr);
           }
         ]]></body>
--- a/browser/components/customizableui/test/browser_newtab_button_customizemode.js
+++ b/browser/components/customizableui/test/browser_newtab_button_customizemode.js
@@ -99,8 +99,27 @@ add_task(async function addremove_before
   CustomizableUI.removeWidgetFromArea("home-button");
   ok(gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
     "tabs should have the adjacent newtab attribute again");
   assertNewTabButton("inner");
 
   CustomizableUI.reset();
   ok(CustomizableUI.inDefaultState, "Should be in default state");
 });
+
+/**
+  * Reset to defaults in customize mode to see if that doesn't break things.
+  */
+add_task(async function reset_before_newtab_customizemode() {
+  await startCustomizing();
+  simulateItemDrag(document.getElementById("home-button"), kGlobalNewTabButton);
+  ok(!gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
+    "tabs should no longer have the adjacent newtab attribute");
+  await endCustomizing();
+  assertNewTabButton("global");
+  await startCustomizing();
+  await gCustomizeMode.reset();
+  ok(gBrowser.tabContainer.hasAttribute("hasadjacentnewtabbutton"),
+    "tabs should have the adjacent newtab attribute again");
+  await endCustomizing();
+  assertNewTabButton("inner");
+  ok(CustomizableUI.inDefaultState, "Should be in default state");
+});