Bug 944887 - Australis' destroyWidget functionality should also remove the node if it's in the palette, r=jaws

This commit is contained in:
Gijs Kruitbosch 2013-12-03 11:20:11 +01:00
parent 513a8e1cc7
commit 8a705801f0
3 changed files with 44 additions and 22 deletions

View File

@ -636,7 +636,7 @@ let CustomizableUIInternal = {
}
LOG("No node for " + aWidgetId + " found.");
return [];
return [null, null];
},
registerMenuPanel: function(aPanel) {
@ -1877,27 +1877,23 @@ let CustomizableUIInternal = {
// This will not remove the widget from gPlacements - we want to keep the
// setting so the widget gets put back in it's old position if/when it
// returns.
let area = widget.currentArea;
let buildAreaNodes = area && gBuildAreas.get(area);
if (buildAreaNodes) {
for (let buildNode of buildAreaNodes) {
let widgetNode = buildNode.ownerDocument.getElementById(aWidgetId);
let windowCache = gSingleWrapperCache.get(buildNode.ownerDocument.defaultView);
if (windowCache) {
windowCache.delete(aWidgetId);
}
if (widgetNode) {
widgetNode.parentNode.removeChild(widgetNode);
}
if (widget.type == "view") {
let viewNode = buildNode.ownerDocument.getElementById(widget.viewId);
if (viewNode) {
for (let eventName of kSubviewEvents) {
let handler = "on" + eventName;
if (typeof widget[handler] == "function") {
viewNode.removeEventListener(eventName, widget[handler], false);
}
for (let [window, ] of gBuildWindows) {
let windowCache = gSingleWrapperCache.get(window);
if (windowCache) {
windowCache.delete(aWidgetId);
}
let widgetNode = window.document.getElementById(aWidgetId) ||
window.gNavToolbox.palette.querySelector(idToSelector(aWidgetId));
if (widgetNode) {
widgetNode.remove();
}
if (widget.type == "view") {
let viewNode = window.document.getElementById(widget.viewId);
if (viewNode) {
for (let eventName of kSubviewEvents) {
let handler = "on" + eventName;
if (typeof widget[handler] == "function") {
viewNode.removeEventListener(eventName, widget[handler], false);
}
}
}

View File

@ -43,4 +43,5 @@ skip-if = os == "mac"
[browser_941083_invalidate_wrapper_cache_createWidget.js]
[browser_942581_unregisterArea_keeps_placements.js]
[browser_943683_migration_test.js]
[browser_944887_destroyWidget_should_destroy_in_palette.js]
[browser_panel_toggle.js]

View File

@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const kWidgetId = "test-destroy-in-palette";
let gTests = [
{
desc: "Check destroyWidget destroys the node if it's in the palette",
run: function() {
CustomizableUI.createWidget({id: kWidgetId, label: "Test destroying widgets in palette."});
yield startCustomizing();
yield endCustomizing();
ok(gNavToolbox.palette.querySelector("#" + kWidgetId), "Widget still exists in palette.");
CustomizableUI.destroyWidget(kWidgetId);
ok(!gNavToolbox.palette.querySelector("#" + kWidgetId), "Widget no longer exists in palette.");
},
},
];
function test() {
waitForExplicitFinish();
runTests(gTests);
}