Bug 1018066 - Reset in-content preference scroll position when switching panes. r=Unfocused
authorJared Wein <jwein@mozilla.com>
Fri, 24 Oct 2014 02:23:27 -0400
changeset 212501 4fe988eea3820b0f5e285355a8336490526be9ba
parent 212500 eb681a24b755f3f03851a82f260a835453343016
child 212502 eac86090909c7f819a2d8bce1b38580ffb222b29
push id27717
push userkwierso@gmail.com
push dateTue, 28 Oct 2014 00:49:29 +0000
treeherdermozilla-central@a255a234946e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs1018066
milestone36.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 1018066 - Reset in-content preference scroll position when switching panes. r=Unfocused
browser/components/preferences/in-content/preferences.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_bug1018066_resetScrollPosition.js
browser/components/preferences/in-content/tests/browser_bug1020245_openPreferences_to_paneContent.js
browser/components/preferences/in-content/tests/head.js
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -90,16 +90,18 @@ function gotoPref(aCategory) {
     document.location.hash = newHash;
   }
   // Need to set the gLastHash before setting categories.selectedItem since
   // the categories 'select' event will re-enter the gotoPref codepath.
   gLastHash = category;
   categories.selectedItem = item;
   window.history.replaceState(category, document.title);
   search(category, "data-category");
+  let mainContent = document.querySelector(".main-content");
+  mainContent.scrollTop = 0;
 }
 
 function search(aQuery, aAttribute) {
   let elements = document.getElementById("mainPrefPane").children;
   for (let element of elements) {
     let attributeValue = element.getAttribute(aAttribute);
     element.hidden = (attributeValue != aQuery);
   }
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -2,18 +2,19 @@
 skip-if = buildapp == "mulet"
 support-files =
   head.js
   privacypane_tests_perwindow.js
 
 [browser_advanced_update.js]
 [browser_bug410900.js]
 [browser_bug731866.js]
+[browser_bug795764_cachedisabled.js]
+[browser_bug1018066_resetScrollPosition.js]
 [browser_bug1020245_openPreferences_to_paneContent.js]
-[browser_bug795764_cachedisabled.js]
 [browser_connection.js]
 [browser_connection_bug388287.js]
 [browser_healthreport.js]
 skip-if = !healthreport || (os == 'linux' && debug)
 [browser_proxy_backup.js]
 [browser_privacypane_1.js]
 [browser_privacypane_3.js]
 [browser_privacypane_4.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_bug1018066_resetScrollPosition.js
@@ -0,0 +1,27 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+Services.prefs.setBoolPref("browser.preferences.inContent", true);
+
+let originalWindowHeight;
+registerCleanupFunction(function() {
+  Services.prefs.clearUserPref("browser.preferences.inContent");
+  window.resizeTo(window.outerWidth, originalWindowHeight);
+  while (gBrowser.tabs[1])
+    gBrowser.removeTab(gBrowser.tabs[1]);
+});
+
+add_task(function() {
+  originalWindowHeight = window.outerHeight;
+  window.resizeTo(window.outerWidth, 300);
+  let prefs = yield openPreferencesViaOpenPreferencesAPI("paneApplications", undefined, {leaveOpen: true});
+  is(prefs.selectedPane, "paneApplications", "Applications pane was selected");
+  let mainContent = gBrowser.contentDocument.querySelector(".main-content");
+  mainContent.scrollTop = 50;
+  is(mainContent.scrollTop, 50, "main-content should be scrolled 50 pixels");
+
+  gBrowser.contentWindow.gotoPref("paneGeneral");
+  is(mainContent.scrollTop, 0,
+     "Switching to a different category should reset the scroll position");
+});
+
--- a/browser/components/preferences/in-content/tests/browser_bug1020245_openPreferences_to_paneContent.js
+++ b/browser/components/preferences/in-content/tests/browser_bug1020245_openPreferences_to_paneContent.js
@@ -20,38 +20,16 @@ add_task(function() {
   prefs = yield openPreferencesViaOpenPreferencesAPI("nonexistant-category");
   is(prefs.selectedPane, "paneGeneral", "General pane is selected by default when a nonexistant-category is requested");
   prefs = yield openPreferencesViaHash("nonexistant-category");
   is(prefs.selectedPane, "paneGeneral", "General pane is selected when hash is a nonexistant-category");
   prefs = yield openPreferencesViaHash();
   is(prefs.selectedPane, "paneGeneral", "General pane is selected by default");
 });
 
-function openPreferencesViaOpenPreferencesAPI(aPane, aAdvancedTab) {
-  let deferred = Promise.defer();
-  gBrowser.selectedTab = gBrowser.addTab("about:blank");
-  openPreferences(aPane, aAdvancedTab ? {advancedTab: aAdvancedTab} : undefined);
-  let newTabBrowser = gBrowser.selectedBrowser;
-
-  newTabBrowser.addEventListener("Initialized", function PrefInit() {
-    newTabBrowser.removeEventListener("Initialized", PrefInit, true);
-    newTabBrowser.contentWindow.addEventListener("load", function prefLoad() {
-      newTabBrowser.contentWindow.removeEventListener("load", prefLoad);
-      let win = gBrowser.contentWindow;
-      let selectedPane = win.history.state;
-      let doc = win.document;
-      let selectedAdvancedTab = aAdvancedTab && doc.getElementById("advancedPrefs").selectedTab.id;
-      gBrowser.removeCurrentTab();
-      deferred.resolve({selectedPane: selectedPane, selectedAdvancedTab: selectedAdvancedTab});
-    });
-  }, true);
-
-  return deferred.promise;
-}
-
 function openPreferencesViaHash(aPane) {
   let deferred = Promise.defer();
   gBrowser.selectedTab = gBrowser.addTab("about:preferences" + (aPane ? "#" + aPane : ""));
   let newTabBrowser = gBrowser.selectedBrowser;
 
   newTabBrowser.addEventListener("Initialized", function PrefInit() {
     newTabBrowser.removeEventListener("Initialized", PrefInit, true);
     newTabBrowser.contentWindow.addEventListener("load", function prefLoad() {
--- a/browser/components/preferences/in-content/tests/head.js
+++ b/browser/components/preferences/in-content/tests/head.js
@@ -112,8 +112,30 @@ function waitForEvent(aSubject, aEventNa
     // unhook listener in case of success or failure
     aSubject.removeEventListener(aEventName, listener);
     return aEventOrError;
   }
   aSubject.addEventListener(aEventName, listener, false);
   return eventDeferred.promise.then(cleanup, cleanup);
 }
 
+function openPreferencesViaOpenPreferencesAPI(aPane, aAdvancedTab, aOptions) {
+  let deferred = Promise.defer();
+  gBrowser.selectedTab = gBrowser.addTab("about:blank");
+  openPreferences(aPane, aAdvancedTab ? {advancedTab: aAdvancedTab} : undefined);
+  let newTabBrowser = gBrowser.selectedBrowser;
+
+  newTabBrowser.addEventListener("Initialized", function PrefInit() {
+    newTabBrowser.removeEventListener("Initialized", PrefInit, true);
+    newTabBrowser.contentWindow.addEventListener("load", function prefLoad() {
+      newTabBrowser.contentWindow.removeEventListener("load", prefLoad);
+      let win = gBrowser.contentWindow;
+      let selectedPane = win.history.state;
+      let doc = win.document;
+      let selectedAdvancedTab = aAdvancedTab && doc.getElementById("advancedPrefs").selectedTab.id;
+      if (!aOptions || !aOptions.leaveOpen)
+        gBrowser.removeCurrentTab();
+      deferred.resolve({selectedPane: selectedPane, selectedAdvancedTab: selectedAdvancedTab});
+    });
+  }, true);
+
+  return deferred.promise;
+}