browser/components/sessionstore/test/browser_506482.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function test() {
michael@0 6 /** Test for Bug 506482 **/
michael@0 7
michael@0 8 // test setup
michael@0 9 waitForExplicitFinish();
michael@0 10
michael@0 11 // read the sessionstore.js mtime (picked from browser_248970_a.js)
michael@0 12 let profilePath = Cc["@mozilla.org/file/directory_service;1"].
michael@0 13 getService(Ci.nsIProperties).
michael@0 14 get("ProfD", Ci.nsIFile);
michael@0 15 function getSessionstoreFile() {
michael@0 16 let sessionStoreJS = profilePath.clone();
michael@0 17 sessionStoreJS.append("sessionstore.js");
michael@0 18 return sessionStoreJS;
michael@0 19 }
michael@0 20 function getSessionstorejsModificationTime() {
michael@0 21 let file = getSessionstoreFile();
michael@0 22 if (file.exists())
michael@0 23 return file.lastModifiedTime;
michael@0 24 else
michael@0 25 return -1;
michael@0 26 }
michael@0 27
michael@0 28 // delete existing sessionstore.js, to make sure we're not reading
michael@0 29 // the mtime of an old one initialy
michael@0 30 let (sessionStoreJS = getSessionstoreFile()) {
michael@0 31 if (sessionStoreJS.exists())
michael@0 32 sessionStoreJS.remove(false);
michael@0 33 }
michael@0 34
michael@0 35 // test content URL
michael@0 36 const TEST_URL = "data:text/html;charset=utf-8,"
michael@0 37 + "<body style='width: 100000px; height: 100000px;'><p>top</p></body>"
michael@0 38
michael@0 39 // preferences that we use
michael@0 40 const PREF_INTERVAL = "browser.sessionstore.interval";
michael@0 41
michael@0 42 // make sure sessionstore.js is saved ASAP on all events
michael@0 43 gPrefService.setIntPref(PREF_INTERVAL, 0);
michael@0 44
michael@0 45 // get the initial sessionstore.js mtime (-1 if it doesn't exist yet)
michael@0 46 let mtime0 = getSessionstorejsModificationTime();
michael@0 47
michael@0 48 // create and select a first tab
michael@0 49 let tab = gBrowser.addTab(TEST_URL);
michael@0 50 whenBrowserLoaded(tab.linkedBrowser, function() {
michael@0 51 // step1: the above has triggered some saveStateDelayed(), sleep until
michael@0 52 // it's done, and get the initial sessionstore.js mtime
michael@0 53 setTimeout(function step1(e) {
michael@0 54 let mtime1 = getSessionstorejsModificationTime();
michael@0 55 isnot(mtime1, mtime0, "initial sessionstore.js update");
michael@0 56
michael@0 57 // step2: test sessionstore.js is not updated on tab selection
michael@0 58 // or content scrolling
michael@0 59 gBrowser.selectedTab = tab;
michael@0 60 tab.linkedBrowser.contentWindow.scrollTo(1100, 1200);
michael@0 61 setTimeout(function step2(e) {
michael@0 62 let mtime2 = getSessionstorejsModificationTime();
michael@0 63 is(mtime2, mtime1,
michael@0 64 "tab selection and scrolling: sessionstore.js not updated");
michael@0 65
michael@0 66 // ok, done, cleanup and finish
michael@0 67 if (gPrefService.prefHasUserValue(PREF_INTERVAL))
michael@0 68 gPrefService.clearUserPref(PREF_INTERVAL);
michael@0 69 gBrowser.removeTab(tab);
michael@0 70 finish();
michael@0 71 }, 3500); // end of sleep after tab selection and scrolling
michael@0 72 }, 3500); // end of sleep after initial saveStateDelayed()
michael@0 73 });
michael@0 74 }

mercurial