Bug 1196341 - Check if VariablesView has a controller before trying to use it. r=ochameau
authorSami Jaktholm <sjakthol@outlook.com>
Sat, 22 Aug 2015 17:13:58 +0300
changeset 259138 731d8351c98d9b11ff62e654833a0776ecd182ce
parent 259137 6aea2f75ee3068897159d68b1395bf4092dfc63e
child 259139 01129d58304ec48338dc4b248b9bd7205347f9b2
push id29269
push userryanvm@gmail.com
push dateTue, 25 Aug 2015 00:57:59 +0000
treeherdermozilla-central@04b8c412d9f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1196341
milestone43.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 1196341 - Check if VariablesView has a controller before trying to use it. r=ochameau
browser/devtools/shared/test/unit/test_VariablesView_filtering-without-controller.js
browser/devtools/shared/test/unit/xpcshell.ini
browser/devtools/shared/widgets/VariablesView.jsm
new file mode 100644
--- /dev/null
+++ b/browser/devtools/shared/test/unit/test_VariablesView_filtering-without-controller.js
@@ -0,0 +1,34 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test that VariablesView._doSearch() works even without an attached
+// VariablesViewController (bug 1196341).
+
+const Cu = Components.utils;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const DOMParser = Cc["@mozilla.org/xmlextras/domparser;1"]
+                    .createInstance(Ci.nsIDOMParser);
+const { VariablesView } =
+  Cu.import("resource:///modules/devtools/VariablesView.jsm", {});
+
+function run_test() {
+  let doc = DOMParser.parseFromString("<div>", "text/html");
+  let container = doc.body.firstChild;
+  ok(container, "Got a container.");
+
+  let vv = new VariablesView(container, { searchEnabled: true });
+  let scope = vv.addScope("Test scope");
+  let item1 = scope.addItem("a", { value: "1" });
+  let item2 = scope.addItem("b", { value: "2" });
+
+  do_print("Performing a search without a controller.");
+  vv._doSearch("a");
+
+  equal(item1.target.hasAttribute("unmatched"), false,
+    "First item that matched the filter is visible.");
+  equal(item2.target.hasAttribute("unmatched"), true,
+    "The second item that did not match the filter is hidden.");
+}
--- a/browser/devtools/shared/test/unit/xpcshell.ini
+++ b/browser/devtools/shared/test/unit/xpcshell.ini
@@ -6,9 +6,10 @@ firefox-appdir = browser
 skip-if = toolkit == 'android' || toolkit == 'gonk'
 
 [test_advanceValidate.js]
 [test_attribute-parsing-01.js]
 [test_attribute-parsing-02.js]
 [test_bezierCanvas.js]
 [test_cubicBezier.js]
 [test_undoStack.js]
+[test_VariablesView_filtering-without-controller.js]
 [test_VariablesView_getString_promise.js]
--- a/browser/devtools/shared/widgets/VariablesView.jsm
+++ b/browser/devtools/shared/widgets/VariablesView.jsm
@@ -542,17 +542,17 @@ VariablesView.prototype = {
    * If aToken is falsy, then all the scopes are unhidden and expanded,
    * while the available variables and properties inside those scopes are
    * just unhidden.
    *
    * @param string aToken
    *        The variable or property to search for.
    */
   _doSearch: function(aToken) {
-    if (this.controller.supportsSearch()) {
+    if (this.controller && this.controller.supportsSearch()) {
       // Retrieve the main Scope in which we add attributes
       let scope = this._store[0]._store.get("");
       if (!aToken) {
         // Prune the view from old previous content
         // so that we delete the intermediate search results
         // we created in previous searches
         for (let property of scope._store.values()) {
           property.remove();