From 6d52958bde550d940929036cb59e6e3dc4a54114 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Wed, 10 Jul 2013 17:57:54 +0200 Subject: [PATCH] Bug 877006 - A widget with an invalid view should not break all of CustomizableUI, r=Unfocused --- .../customizableui/src/CustomizableUI.jsm | 28 +++++------ .../customizableui/test/Makefile.in | 1 + .../test/browser_877006_missing_view.js | 50 +++++++++++++++++++ 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 browser/components/customizableui/test/browser_877006_missing_view.js diff --git a/browser/components/customizableui/src/CustomizableUI.jsm b/browser/components/customizableui/src/CustomizableUI.jsm index 27876c6eee3..3c4112c8018 100644 --- a/browser/components/customizableui/src/CustomizableUI.jsm +++ b/browser/components/customizableui/src/CustomizableUI.jsm @@ -826,23 +826,23 @@ 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"); - // PanelUI relies on the .PanelUI-subView class to be able to show only - // one sub-view at a time. - viewNode.classList.add("PanelUI-subView"); - - for (let eventName of kSubviewEvents) { - let handler = "on" + eventName; - if (typeof aWidget[handler] == "function") { - viewNode.addEventListener(eventName, aWidget[handler], false); + for (let eventName of kSubviewEvents) { + let handler = "on" + eventName; + if (typeof aWidget[handler] == "function") { + viewNode.addEventListener(eventName, aWidget[handler], false); + } } - } - LOG("Widget " + aWidget.id + " showing and hiding event handlers set."); + 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) { diff --git a/browser/components/customizableui/test/Makefile.in b/browser/components/customizableui/test/Makefile.in index 9deae3a689b..7a9f3c5eb4c 100644 --- a/browser/components/customizableui/test/Makefile.in +++ b/browser/components/customizableui/test/Makefile.in @@ -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 \ diff --git a/browser/components/customizableui/test/browser_877006_missing_view.js b/browser/components/customizableui/test/browser_877006_missing_view.js new file mode 100644 index 00000000000..f65861d6314 --- /dev/null +++ b/browser/components/customizableui/test/browser_877006_missing_view.js @@ -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); +} +