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
--- 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");
+});