From 9e39a5fed7755ba20d81a6acff97f5a29e63ff1e Mon Sep 17 00:00:00 2001 From: Thomas de Grenier de Latour Date: Tue, 5 Jan 2010 13:28:00 -0800 Subject: [PATCH] Bug 506482 - Don't write sessionstore.js to disk for "read only" events [r=zpao] --HG-- extra : rebase_source : c1094d746ceaca07f75d49f3c3afb127d04b2ba0 --- .../sessionstore/src/nsSessionStore.js | 15 --- .../sessionstore/test/browser/Makefile.in | 1 + .../test/browser/browser_506482.js | 112 ++++++++++++++++++ 3 files changed, 113 insertions(+), 15 deletions(-) create mode 100644 browser/components/sessionstore/test/browser/browser_506482.js diff --git a/browser/components/sessionstore/src/nsSessionStore.js b/browser/components/sessionstore/src/nsSessionStore.js index b9e1c4762734..e600d245cc40 100644 --- a/browser/components/sessionstore/src/nsSessionStore.js +++ b/browser/components/sessionstore/src/nsSessionStore.js @@ -559,9 +559,6 @@ SessionStoreService.prototype = { case "DOMAutoComplete": this.onTabInput(win, aEvent.currentTarget); break; - case "scroll": - this.onTabScroll(win); - break; case "TabOpen": case "TabClose": let browser = aEvent.originalTarget.linkedBrowser; @@ -768,7 +765,6 @@ SessionStoreService.prototype = { aBrowser.addEventListener("change", this, true); aBrowser.addEventListener("input", this, true); aBrowser.addEventListener("DOMAutoComplete", this, true); - aBrowser.addEventListener("scroll", this, true); if (!aNoNotification) { this.saveStateDelayed(aWindow); @@ -792,7 +788,6 @@ SessionStoreService.prototype = { aBrowser.removeEventListener("change", this, true); aBrowser.removeEventListener("input", this, true); aBrowser.removeEventListener("DOMAutoComplete", this, true); - aBrowser.removeEventListener("scroll", this, true); delete aBrowser.__SS_data; @@ -880,15 +875,6 @@ SessionStoreService.prototype = { this.saveStateDelayed(aWindow, 3000); }, - /** - * Called when a browser sends a "scroll" notification - * @param aWindow - * Window reference - */ - onTabScroll: function sss_onTabScroll(aWindow) { - this.saveStateDelayed(aWindow, 3000); - }, - /** * When a tab is selected, save session data * @param aWindow @@ -897,7 +883,6 @@ SessionStoreService.prototype = { onTabSelect: function sss_onTabSelect(aWindow) { if (this._loadState == STATE_RUNNING) { this._windows[aWindow.__SSi].selected = aWindow.gBrowser.tabContainer.selectedIndex; - this.saveStateDelayed(aWindow); // attempt to update the current URL we send in a crash report this._updateCrashReportURL(aWindow); diff --git a/browser/components/sessionstore/test/browser/Makefile.in b/browser/components/sessionstore/test/browser/Makefile.in index 004b625f23b2..77d5fa1ff6c9 100644 --- a/browser/components/sessionstore/test/browser/Makefile.in +++ b/browser/components/sessionstore/test/browser/Makefile.in @@ -108,6 +108,7 @@ _BROWSER_TEST_FILES = \ browser_491577.js \ browser_493467.js \ browser_495495.js \ + browser_506482.js \ browser_514751.js \ browser_522545.js \ browser_524745.js \ diff --git a/browser/components/sessionstore/test/browser/browser_506482.js b/browser/components/sessionstore/test/browser/browser_506482.js new file mode 100644 index 000000000000..7cf13ca395b2 --- /dev/null +++ b/browser/components/sessionstore/test/browser/browser_506482.js @@ -0,0 +1,112 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is sessionstore test code. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2009 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Thomas de Grenier de Latour + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +function test() { + /** Test for Bug 506482 **/ + + // test setup + waitForExplicitFinish(); + + let ss = Cc["@mozilla.org/browser/sessionstore;1"]. + getService(Ci.nsISessionStore); + + // read the sessionstore.js mtime (picked from browser_248970_a.js) + let profilePath = Cc["@mozilla.org/file/directory_service;1"]. + getService(Ci.nsIProperties). + get("ProfD", Ci.nsIFile); + function getSessionstoreFile() { + let sessionStoreJS = profilePath.clone(); + sessionStoreJS.append("sessionstore.js"); + return sessionStoreJS; + } + function getSessionstorejsModificationTime() { + let file = getSessionstoreFile(); + if (file.exists()) + return file.lastModifiedTime; + else + return -1; + } + + // delete existing sessionstore.js, to make sure we're not reading + // the mtime of an old one initialy + let (sessionStoreJS = getSessionstoreFile()) { + if (sessionStoreJS.exists()) + sessionStoreJS.remove(false); + } + + // test content URL + const TEST_URL = "data:text/html," + + "

top

" + + // preferences that we use + const PREF_INTERVAL = "browser.sessionstore.interval"; + + // make sure sessionstore.js is saved ASAP on all events + gPrefService.setIntPref(PREF_INTERVAL, 0); + + // get the initial sessionstore.js mtime (-1 if it doesn't exist yet) + let mtime0 = getSessionstorejsModificationTime(); + + // create and select a first tab + let tab = gBrowser.addTab(TEST_URL); + tab.linkedBrowser.addEventListener("load", function loadListener(e) { + tab.linkedBrowser.removeEventListener("load", arguments.callee, true); + + // step1: the above has triggered some saveStateDelayed(), sleep until + // it's done, and get the initial sessionstore.js mtime + setTimeout(function step1(e) { + let mtime1 = getSessionstorejsModificationTime(); + isnot(mtime1, mtime0, "initial sessionstore.js update"); + + // step2: test sessionstore.js is not updated on tab selection + // or content scrolling + gBrowser.selectedTab = tab; + tab.linkedBrowser.contentWindow.scrollTo(1100, 1200); + setTimeout(function step2(e) { + let mtime2 = getSessionstorejsModificationTime(); + is(mtime2, mtime1, + "tab selection and scrolling: sessionstore.js not updated"); + + // ok, done, cleanup and finish + if (gPrefService.prefHasUserValue(PREF_INTERVAL)) + gPrefService.clearUserPref(PREF_INTERVAL); + gBrowser.removeTab(tab); + finish(); + }, 2500); // end of sleep after tab selection and scrolling + }, 2500); // end of sleep after initial saveStateDelayed() + }, true); +}