Bug 622303 - Web Console should remember filter settings; r=msucan
authorSonny Piers <sonny.piers@gmail.com>
Fri, 18 Nov 2011 19:24:04 +0100
changeset 82337 eb101044cb01c6aa3286c16af982871c911f80c2
parent 82251 ea30e13fc978a6929683e174d0ac97a8618d385e
child 82338 192f8762963f94dd988911202261a312f942fd21
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmsucan
bugs622303
milestone11.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 622303 - Web Console should remember filter settings; r=msucan
browser/app/profile/firefox.js
browser/devtools/webconsole/HUDService.jsm
browser/devtools/webconsole/test/browser/Makefile.in
browser/devtools/webconsole/test/browser/browser_webconsole_bug_589162_css_filter.js
browser/devtools/webconsole/test/browser/browser_webconsole_bug_597460_filter_scroll.js
browser/devtools/webconsole/test/browser/browser_webconsole_bug_622303_persistent_filters.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1033,16 +1033,28 @@ pref("devtools.gcli.enable", false);
 pref("devtools.hud.height", 0);
 
 // Remember the Web Console position. Possible values:
 //   above - above the web page,
 //   below - below the web page,
 //   window - in a separate window/popup panel.
 pref("devtools.webconsole.position", "above");
 
+// Remember the Web Console filters
+pref("devtools.webconsole.filter.network", true);
+pref("devtools.webconsole.filter.networkinfo", true);
+pref("devtools.webconsole.filter.csserror", true);
+pref("devtools.webconsole.filter.cssparser", true);
+pref("devtools.webconsole.filter.exception", true);
+pref("devtools.webconsole.filter.jswarn", true);
+pref("devtools.webconsole.filter.error", true);
+pref("devtools.webconsole.filter.warn", true);
+pref("devtools.webconsole.filter.info", true);
+pref("devtools.webconsole.filter.log", true);
+
 // The number of lines that are displayed in the web console for the Net,
 // CSS, JS and Web Developer categories.
 pref("devtools.hud.loglimit.network", 200);
 pref("devtools.hud.loglimit.cssparser", 200);
 pref("devtools.hud.loglimit.exception", 200);
 pref("devtools.hud.loglimit.console", 200);
 
 // The developer tools editor configuration:
--- a/browser/devtools/webconsole/HUDService.jsm
+++ b/browser/devtools/webconsole/HUDService.jsm
@@ -1633,16 +1633,17 @@ HUD_SERVICE.prototype =
    * @param string aToggleType
    * @param boolean aState
    * @returns void
    */
   setFilterState: function HS_setFilterState(aHUDId, aToggleType, aState)
   {
     this.filterPrefs[aHUDId][aToggleType] = aState;
     this.adjustVisibilityForMessageType(aHUDId, aToggleType, aState);
+    Services.prefs.setBoolPref(PREFS_PREFIX + aToggleType, aState);
   },
 
   /**
    * Splits the given console messages into groups based on their timestamps.
    *
    * @param nsIDOMNode aOutputNode
    *        The output node to alter.
    * @returns void
@@ -6333,126 +6334,57 @@ HeadsUpDisplayUICommands = {
 
 //////////////////////////////////////////////////////////////////////////
 // ConsoleStorage
 //////////////////////////////////////////////////////////////////////////
 
 var prefs = Services.prefs;
 
 const GLOBAL_STORAGE_INDEX_ID = "GLOBAL_CONSOLE";
-const PREFS_BRANCH_PREF = "devtools.hud.display.filter";
-const PREFS_PREFIX = "devtools.hud.display.filter.";
+const PREFS_PREFIX = "devtools.webconsole.filter.";
 const PREFS = { network: PREFS_PREFIX + "network",
                 networkinfo: PREFS_PREFIX + "networkinfo",
                 csserror: PREFS_PREFIX + "csserror",
                 cssparser: PREFS_PREFIX + "cssparser",
                 exception: PREFS_PREFIX + "exception",
                 jswarn: PREFS_PREFIX + "jswarn",
                 error: PREFS_PREFIX + "error",
                 info: PREFS_PREFIX + "info",
                 warn: PREFS_PREFIX + "warn",
                 log: PREFS_PREFIX + "log",
-                global: PREFS_PREFIX + "global",
               };
 
 function ConsoleStorage()
 {
   this.sequencer = null;
   this.consoleDisplays = {};
   // each display will have an index that tracks each ConsoleEntry
   this.displayIndexes = {};
   this.globalStorageIndex = [];
   this.globalDisplay = {};
   this.createDisplay(GLOBAL_STORAGE_INDEX_ID);
   // TODO: need to create a method that truncates the message
   // see bug 570543
 
-  // store an index of display prefs
-  this.displayPrefs = {};
-
-  // check prefs for existence, create & load if absent, load them if present
-  let filterPrefs;
-  let defaultDisplayPrefs;
-
-  try {
-    filterPrefs = prefs.getBoolPref(PREFS_BRANCH_PREF);
-  }
-  catch (ex) {
-    filterPrefs = false;
-  }
-
-  // TODO: for FINAL release,
-  // use the sitePreferencesService to save specific site prefs
-  // see bug 570545
-
-  if (filterPrefs) {
-    defaultDisplayPrefs = {
-      network: (prefs.getBoolPref(PREFS.network) ? true: false),
-      networkinfo: (prefs.getBoolPref(PREFS.networkinfo) ? true: false),
-      csserror: (prefs.getBoolPref(PREFS.csserror) ? true: false),
-      cssparser: (prefs.getBoolPref(PREFS.cssparser) ? true: false),
-      exception: (prefs.getBoolPref(PREFS.exception) ? true: false),
-      jswarn: (prefs.getBoolPref(PREFS.jswarn) ? true: false),
-      error: (prefs.getBoolPref(PREFS.error) ? true: false),
-      info: (prefs.getBoolPref(PREFS.info) ? true: false),
-      warn: (prefs.getBoolPref(PREFS.warn) ? true: false),
-      log: (prefs.getBoolPref(PREFS.log) ? true: false),
-      global: (prefs.getBoolPref(PREFS.global) ? true: false),
-    };
-  }
-  else {
-    prefs.setBoolPref(PREFS_BRANCH_PREF, false);
-    // default prefs for each HeadsUpDisplay
-    prefs.setBoolPref(PREFS.network, true);
-    prefs.setBoolPref(PREFS.networkinfo, true);
-    prefs.setBoolPref(PREFS.csserror, true);
-    prefs.setBoolPref(PREFS.cssparser, true);
-    prefs.setBoolPref(PREFS.exception, true);
-    prefs.setBoolPref(PREFS.jswarn, true);
-    prefs.setBoolPref(PREFS.error, true);
-    prefs.setBoolPref(PREFS.info, true);
-    prefs.setBoolPref(PREFS.warn, true);
-    prefs.setBoolPref(PREFS.log, true);
-    prefs.setBoolPref(PREFS.global, false);
-
-    defaultDisplayPrefs = {
-      network: prefs.getBoolPref(PREFS.network),
-      networkinfo: prefs.getBoolPref(PREFS.networkinfo),
-      csserror: prefs.getBoolPref(PREFS.csserror),
-      cssparser: prefs.getBoolPref(PREFS.cssparser),
-      exception: prefs.getBoolPref(PREFS.exception),
-      jswarn: prefs.getBoolPref(PREFS.jswarn),
-      error: prefs.getBoolPref(PREFS.error),
-      info: prefs.getBoolPref(PREFS.info),
-      warn: prefs.getBoolPref(PREFS.warn),
-      log: prefs.getBoolPref(PREFS.log),
-      global: prefs.getBoolPref(PREFS.global),
-    };
-  }
-  this.defaultDisplayPrefs = defaultDisplayPrefs;
+  this.defaultDisplayPrefs = {
+    network: prefs.getBoolPref(PREFS.network),
+    networkinfo: prefs.getBoolPref(PREFS.networkinfo),
+    csserror: prefs.getBoolPref(PREFS.csserror),
+    cssparser: prefs.getBoolPref(PREFS.cssparser),
+    exception: prefs.getBoolPref(PREFS.exception),
+    jswarn: prefs.getBoolPref(PREFS.jswarn),
+    error: prefs.getBoolPref(PREFS.error),
+    info: prefs.getBoolPref(PREFS.info),
+    warn: prefs.getBoolPref(PREFS.warn),
+    log: prefs.getBoolPref(PREFS.log),
+  };
 }
 
 ConsoleStorage.prototype = {
 
-  updateDefaultDisplayPrefs:
-  function CS_updateDefaultDisplayPrefs(aPrefsObject) {
-    prefs.setBoolPref(PREFS.network, (aPrefsObject.network ? true : false));
-    prefs.setBoolPref(PREFS.networkinfo,
-                      (aPrefsObject.networkinfo ? true : false));
-    prefs.setBoolPref(PREFS.csserror, (aPrefsObject.csserror ? true : false));
-    prefs.setBoolPref(PREFS.cssparser, (aPrefsObject.cssparser ? true : false));
-    prefs.setBoolPref(PREFS.exception, (aPrefsObject.exception ? true : false));
-    prefs.setBoolPref(PREFS.jswarn, (aPrefsObject.jswarn ? true : false));
-    prefs.setBoolPref(PREFS.error, (aPrefsObject.error ? true : false));
-    prefs.setBoolPref(PREFS.info, (aPrefsObject.info ? true : false));
-    prefs.setBoolPref(PREFS.warn, (aPrefsObject.warn ? true : false));
-    prefs.setBoolPref(PREFS.log, (aPrefsObject.log ? true : false));
-    prefs.setBoolPref(PREFS.global, (aPrefsObject.global ? true : false));
-  },
-
   sequenceId: function CS_sequencerId()
   {
     if (!this.sequencer) {
       this.sequencer = this.createSequencer();
     }
     return this.sequencer.next();
   },
 
--- a/browser/devtools/webconsole/test/browser/Makefile.in
+++ b/browser/devtools/webconsole/test/browser/Makefile.in
@@ -145,16 +145,17 @@ include $(topsrcdir)/config/rules.mk
 	browser_webconsole_bug_659907_console_dir.js \
 	browser_webconsole_bug_678816.js \
 	browser_webconsole_bug_664131_console_group.js \
 	browser_gcli_inspect.js \
 	browser_gcli_integrate.js \
 	browser_gcli_require.js \
 	browser_gcli_web.js \
 	browser_webconsole_bug_658368_time_methods.js \
+	browser_webconsole_bug_622303_persistent_filters.js \
 	head.js \
 	$(NULL)
 
 _BROWSER_TEST_PAGES = \
 	test-console.html \
 	test-network.html \
 	test-network-request.html \
 	test-mutation.html \
--- a/browser/devtools/webconsole/test/browser/browser_webconsole_bug_589162_css_filter.js
+++ b/browser/devtools/webconsole/test/browser/browser_webconsole_bug_589162_css_filter.js
@@ -22,25 +22,24 @@ function onContentLoaded()
 
   let msg = "the unknown CSS property warning is displayed";
   testLogEntry(outputNode, "foobarCssParser", msg, true);
 
   HUDService.setFilterState(hudId, "cssparser", false);
 
   executeSoon(
     function (){
-      HUDService.setFilterState(hudId, "cssparser", false);
-
       let msg = "the unknown CSS property warning is not displayed, " +
                 "after filtering";
       testLogEntry(outputNode, "foobarCssParser", msg, true, true);
+
+      HUDService.setFilterState(hudId, "cssparser", true);
+      finishTest();
     }
   );
-
-  finishTest();
 }
 
 /**
  * Unit test for bug 589162:
  * CSS filtering on the console does not work
  */
 function test()
 {
--- a/browser/devtools/webconsole/test/browser/browser_webconsole_bug_597460_filter_scroll.js
+++ b/browser/devtools/webconsole/test/browser/browser_webconsole_bug_597460_filter_scroll.js
@@ -49,16 +49,19 @@ function tabReload(aEvent) {
   ok(scrollBox.scrollTop > 0, "scroll location is not at the top");
 
   // Make sure the Web Console output is scrolled as near as possible to the
   // bottom.
   let nodeHeight = hud.outputNode.querySelector(".hud-log").clientHeight;
   ok(scrollBox.scrollTop >= scrollBox.scrollHeight - scrollBox.clientHeight -
      nodeHeight * 2, "scroll location is correct");
 
+  HUDService.setFilterState(hud.hudId, "network", true);
+  HUDService.setFilterState(hud.hudId, "networkinfo", true);
+
   executeSoon(finishTest);
 }
 
 function test() {
   addTab(TEST_URI);
   browser.addEventListener("load", tabLoad, true);
 }
 
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser/browser_webconsole_bug_622303_persistent_filters.js
@@ -0,0 +1,59 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  let prefService = Services.prefs;
+  let prefs = [
+    "network",
+    "networkinfo",
+    "csserror",
+    "cssparser",
+    "exception",
+    "jswarn",
+    "error",
+    "warn",
+    "info",
+    "log"
+  ];
+
+  //Set all prefs to true
+  prefs.forEach(function(pref) {
+    prefService.setBoolPref("devtools.webconsole.filter." + pref, true);
+  });
+
+  addTab("about:blank");
+  openConsole();
+  
+  let hud = HUDService.getHudByWindow(content);
+  let hudId = HUDService.getHudIdByWindow(content);
+
+  //Check if the filters menuitems exists and is checked
+  prefs.forEach(function(pref) {
+    let checked = hud.HUDBox.querySelector("menuitem[prefKey=" + pref + "]").
+      getAttribute("checked");
+    is(checked, "true", "menuitem for " + pref + " exists and is checked");
+  });
+  
+  //Set all prefs to false
+  prefs.forEach(function(pref) {
+    HUDService.setFilterState(hudId, pref, false);
+  });
+
+  //Re-init the console
+  closeConsole();
+  openConsole();
+
+  hud = HUDService.getHudByWindow(content);
+  
+  //Check if filters menuitems exists and are unchecked
+  prefs.forEach(function(pref) {
+    let checked = hud.HUDBox.querySelector("menuitem[prefKey=" + pref + "]").
+      getAttribute("checked");
+    is(checked, "false", "menuitem for " + pref + " exists and is not checked");
+    prefService.clearUserPref("devtools.webconsole.filter." + pref);
+  });
+  
+  gBrowser.removeCurrentTab();
+  
+  finish();
+}