Bug 877006 - A widget with an invalid view should not break all of CustomizableUI, r=Unfocused

This commit is contained in:
Gijs Kruitbosch 2013-07-10 17:57:54 +02:00
parent 83f0ab86c9
commit 6d52958bde
3 changed files with 65 additions and 14 deletions

View File

@ -826,11 +826,7 @@ let CustomizableUIInternal = {
LOG("Widget " + aWidget.id + " has a view with showing and hiding events. Auto-registering event handlers.");
let viewNode = aDocument.getElementById(aWidget.viewId);
if (!viewNode) {
ERROR("Could not find the view node with id: " + aWidget.viewId);
throw new Error("Could not find the view node with id: " + aWidget.viewId);
}
if (viewNode) {
// PanelUI relies on the .PanelUI-subView class to be able to show only
// one sub-view at a time.
viewNode.classList.add("PanelUI-subView");
@ -843,6 +839,10 @@ let CustomizableUIInternal = {
}
LOG("Widget " + aWidget.id + " showing and hiding event handlers set.");
} else {
ERROR("Could not find the view node with id: " + aWidget.viewId +
", for widget: " + aWidget.id + ".");
}
}
if (aWidget.onCreated) {

View File

@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk
MOCHITEST_BROWSER_FILES = \
browser_873501_handle_specials.js \
browser_877006_missing_view.js \
browser_877178_unregisterArea.js \
browser_877447_skip_missing_ids.js \
browser_878452_drag_to_panel.js \

View File

@ -0,0 +1,50 @@
/* 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/. */
let gTests = [
{
desc: "Should be able to add broken view widget",
run: function() {
const kWidgetId = 'test-877006-broken-widget';
let widgetSpec = {
id: kWidgetId,
type: 'view',
viewId: 'idontexist',
/* Empty handler so we try to attach it maybe? */
onViewShowing: function() {
},
};
let noError = true;
try {
CustomizableUI.createWidget(widgetSpec);
CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_NAVBAR);
} catch (ex) {
Cu.reportError(ex);
noError = false;
}
ok(noError, "Should not throw an exception trying to add a broken view widget.");
noError = true;
try {
CustomizableUI.destroyWidget(kWidgetId);
} catch (ex) {
Cu.reportError(ex);
noError = false;
}
ok(noError, "Should not throw an exception trying to remove the broken view widget.");
}
}
];
function asyncCleanup() {
yield resetCustomization();
}
function test() {
waitForExplicitFinish();
runTests(gTests, asyncCleanup);
}