Bug 741047 - Implement opening in-content preferences to a given view. r=Gijs
☠☠ backed out by 9ec1824900eb ☠ ☠
authorJared Wein <jwein@mozilla.com>
Sun, 11 May 2014 15:52:33 -0400
changeset 183197 49859608dbb8165cfd757269551da4d5c19a03f1
parent 183196 fa6489a53b497568b662035228208dcd3709dc64
child 183198 25fa9e0e5b06a72134aa7cd626cea70519b4210e
push idunknown
push userunknown
push dateunknown
reviewersGijs
bugs741047
milestone32.0a1
Bug 741047 - Implement opening in-content preferences to a given view. r=Gijs
browser/base/content/utilityOverlay.js
browser/components/preferences/in-content/advanced.js
browser/components/preferences/in-content/preferences.js
toolkit/mozapps/extensions/test/browser/browser_experiments.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -500,20 +500,23 @@ function openPreferences(paneID, extraAr
     function switchToPane() {
       if (paneID) {
         browser.contentWindow.selectCategory(paneID);
       }
       switchToAdvancedSubPane(browser.contentDocument);
     }
 
     if (newLoad) {
-      browser.addEventListener("load", function onload() {
-        browser.removeEventListener("load", onload, true);
+      Services.obs.addObserver(function advancedPaneLoadedObs(prefWin, topic, data) {
+        if (prefWin != browser.contentWindow) {
+          return;
+        }
+        Services.obs.removeObserver(advancedPaneLoadedObs, "advanced-pane-loaded");
         switchToPane();
-      }, true);
+      }, "advanced-pane-loaded", false);
     } else {
       switchToPane();
     }
   } else {
     var instantApply = getBoolPref("browser.preferences.instantApply", false);
     var features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
 
     var win = Services.wm.getMostRecentWindow("Browser:Preferences");
--- a/browser/components/preferences/in-content/advanced.js
+++ b/browser/components/preferences/in-content/advanced.js
@@ -66,16 +66,19 @@ var gAdvancedPane = {
     this.initSubmitCrashes();
 #endif
     this.initTelemetry();
 #ifdef MOZ_SERVICES_HEALTHREPORT
     this.initSubmitHealthReport();
 #endif
     this.updateActualCacheSize();
     this.updateActualAppCacheSize();
+
+    // Notify observers that the UI is now ready
+    Services.obs.notifyObservers(window, "advanced-pane-loaded", null);
   },
 
   /**
    * Stores the identity of the current tab in preferences so that the selected
    * tab can be persisted between openings of the preferences window.
    */
   tabSelectionChanged: function ()
   {
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -39,16 +39,17 @@ function init_all() {
     history.replaceState("paneGeneral", document.title);
   }
 }
 
 function selectCategory(name) {
   let categories = document.getElementById("categories");
   let item = categories.querySelector(".category[value=" + name + "]");
   categories.selectedItem = item;
+  gotoPref(name);
 }
 
 function gotoPref(page) {
   window.history.replaceState(page, document.title);
   search(page, "data-category");
 }
 
 function search(aQuery, aAttribute) {
--- a/toolkit/mozapps/extensions/test/browser/browser_experiments.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_experiments.js
@@ -180,27 +180,27 @@ add_task(function* testOpenPreferences()
     return;
   }
 
   is_element_visible(btn, "Change telemetry button visible in in-content UI.");
 
   let deferred = Promise.defer();
   Services.obs.addObserver(function observer(prefWin, topic, data) {
     Services.obs.removeObserver(observer, "advanced-pane-loaded");
-
     info("Advanced preference pane opened.");
+    executeSoon(function() {
+      // We want this test to fail if the preferences pane changes.
+      let el = prefWin.document.getElementById("dataChoicesPanel");
+      is_element_visible(el);
 
-    // We want this test to fail if the preferences pane changes.
-    let el = prefWin.document.getElementById("dataChoicesPanel");
-    is_element_visible(el);
+      prefWin.close();
+      info("Closed preferences pane.");
 
-    prefWin.close();
-    info("Closed preferences pane.");
-
-    deferred.resolve();
+      deferred.resolve();
+    });
   }, "advanced-pane-loaded", false);
 
   info("Loading preferences pane.");
   EventUtils.synthesizeMouseAtCenter(btn, {}, gManagerWindow);
 
   yield deferred.promise;
 });
 
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -427,22 +427,22 @@ function is_hidden(aElement) {
   if (aElement.parentNode != aElement.ownerDocument)
     return is_hidden(aElement.parentNode);
 
   return false;
 }
 
 function is_element_visible(aElement, aMsg) {
   isnot(aElement, null, "Element should not be null, when checking visibility");
-  ok(!is_hidden(aElement), aMsg);
+  ok(!is_hidden(aElement), aMsg || (aElement + " should be visible"));
 }
 
 function is_element_hidden(aElement, aMsg) {
   isnot(aElement, null, "Element should not be null, when checking visibility");
-  ok(is_hidden(aElement), aMsg);
+  ok(is_hidden(aElement), aMsg || (aElement + " should be hidden"));
 }
 
 /**
  * Install an add-on and call a callback when complete.
  *
  * The callback will receive the Addon for the installed add-on.
  */
 function install_addon(path, cb, pathPrefix=TESTROOT) {