Bug 877006 - A widget with an invalid view should not break all of CustomizableUI, r=Unfocused
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 10 Jul 2013 17:57:54 +0200
changeset 155541 56af4ca8e542d5c5e25ee317622502921751036a
parent 155540 4136556fa252dd7f48e72efb557574dceb8b381e
child 155542 3cbfe0d6e5ee2945e85f517bcc82a294b613b403
push id25666
push userjwein@mozilla.com
push dateMon, 18 Nov 2013 15:56:58 +0000
treeherdermozilla-central@f2adb62d07eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs877006
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 877006 - A widget with an invalid view should not break all of CustomizableUI, r=Unfocused
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/Makefile.in
browser/components/customizableui/test/browser_877006_missing_view.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -821,33 +821,33 @@ let CustomizableUIInternal = {
 
       // If the widget has a view, and has view showing / hiding listeners,
       // hook those up to this widget.
       if (aWidget.type == "view" &&
           (aWidget.onViewShowing || aWidget.onViewHiding)) {
         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);
-        }
-
-        // PanelUI relies on the .PanelUI-subView class to be able to show only
-        // one sub-view at a time.
-        viewNode.classList.add("PanelUI-subView");
+        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");
 
-        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.");
+        } else {
+          ERROR("Could not find the view node with id: " + aWidget.viewId +
+                ", for widget: " + aWidget.id + ".");
         }
-
-        LOG("Widget " + aWidget.id + " showing and hiding event handlers set.");
       }
 
       if (aWidget.onCreated) {
         aWidget.onCreated(node);
       }
     }
 
     aWidget.instances.set(aDocument, node);
--- a/browser/components/customizableui/test/Makefile.in
+++ b/browser/components/customizableui/test/Makefile.in
@@ -7,16 +7,17 @@ topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 relativesrcdir  = @relativesrcdir@
 
 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 \
   browser_880382_drag_wide_widgets_in_panel.js \
   browser_885530_showInPrivateBrowsing.js \
   browser_887438_currentset_shim.js \
   browser_890262_destroyWidget_after_add_to_panel.js \
   head.js \
new file mode 100644
--- /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);
+}
+