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.

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

mercurial