Bug 1008559 - setLocationAttributes, as called from buildArea, should remove anchor attribute if set. r=mconley, a=lsblakk
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 12 May 2014 19:12:06 +0100
changeset 192282 b927870d378d
parent 192281 504c3281b663
child 192283 542398357372
push id3557
push userryanvm@gmail.com
push date2014-05-14 16:23 +0000
Treeherderresults
reviewersmconley, lsblakk
bugs1008559
milestone30.0
Bug 1008559 - setLocationAttributes, as called from buildArea, should remove anchor attribute if set. r=mconley, a=lsblakk
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_1008559_anchor_undo_restore.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -893,16 +893,18 @@ let CustomizableUIInternal = {
       throw new Error("Expected area " + aArea + " to have a properties Map " +
                       "associated with it.");
     }
 
     aNode.setAttribute("cui-areatype", props.get("type") || "");
     let anchor = props.get("anchor");
     if (anchor) {
       aNode.setAttribute("cui-anchorid", anchor);
+    } else {
+      aNode.removeAttribute("cui-anchorid");
     }
   },
 
   removeLocationAttributes: function(aNode) {
     aNode.removeAttribute("cui-areatype");
     aNode.removeAttribute("cui-anchorid");
   },
 
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -91,10 +91,11 @@ skip-if = os == "linux"
 [browser_989751_subviewbutton_class.js]
 [browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
 [browser_987492_window_api.js]
 [browser_992747_toggle_noncustomizable_toolbar.js]
 [browser_993322_widget_notoolbar.js]
 [browser_995164_registerArea_during_customize_mode.js]
 [browser_996364_registerArea_different_properties.js]
+[browser_1008559_anchor_undo_restore.js]
 [browser_bootstrapped_custom_toolbar.js]
 [browser_panel_toggle.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_1008559_anchor_undo_restore.js
@@ -0,0 +1,71 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const kAnchorAttribute = "cui-anchorid";
+
+/**
+ * Check that anchor gets set correctly when moving an item from the panel to the toolbar
+ * using 'undo'
+ */
+add_task(function*() {
+  yield startCustomizing();
+  let button = document.getElementById("history-panelmenu");
+  is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
+     "Button (" + button.id + ") starts out with correct anchor");
+
+  let navbar = document.getElementById("nav-bar").customizationTarget;
+  simulateItemDrag(button, navbar);
+  is(CustomizableUI.getPlacementOfWidget(button.id).area, "nav-bar",
+     "Button (" + button.id + ") ends up in nav-bar");
+
+  ok(!button.hasAttribute(kAnchorAttribute),
+     "Button (" + button.id + ") has no anchor in toolbar");
+
+  let resetButton = document.getElementById("customization-reset-button");
+  ok(!resetButton.hasAttribute("disabled"), "Should be able to reset now.");
+  yield gCustomizeMode.reset();
+
+  is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
+     "Button (" + button.id + ") has anchor again");
+
+  let undoButton = document.getElementById("customization-undo-reset-button");
+  ok(!undoButton.hasAttribute("disabled"), "Should be able to undo now.");
+  yield gCustomizeMode.undoReset();
+
+  ok(!button.hasAttribute(kAnchorAttribute),
+     "Button (" + button.id + ") once again has no anchor in toolbar");
+
+  yield gCustomizeMode.reset();
+
+  yield endCustomizing();
+});
+
+
+/**
+ * Check that anchor gets set correctly when moving an item from the panel to the toolbar
+ * using 'reset'
+ */
+add_task(function*() {
+  yield startCustomizing();
+  let button = document.getElementById("bookmarks-menu-button");
+  ok(!button.hasAttribute(kAnchorAttribute),
+     "Button (" + button.id + ") has no anchor in toolbar");
+
+  let panel = document.getElementById("PanelUI-contents");
+  simulateItemDrag(button, panel);
+  is(CustomizableUI.getPlacementOfWidget(button.id).area, "PanelUI-contents",
+     "Button (" + button.id + ") ends up in panel");
+  is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
+     "Button (" + button.id + ") has correct anchor in the panel");
+
+  let resetButton = document.getElementById("customization-reset-button");
+  ok(!resetButton.hasAttribute("disabled"), "Should be able to reset now.");
+  yield gCustomizeMode.reset();
+
+  ok(!button.hasAttribute(kAnchorAttribute),
+     "Button (" + button.id + ") once again has no anchor in toolbar");
+
+  yield endCustomizing();
+});