browser/components/sessionstore/test/browser_506482.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_506482.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  /** Test for Bug 506482 **/
    1.10 +
    1.11 +  // test setup
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  // read the sessionstore.js mtime (picked from browser_248970_a.js)
    1.15 +  let profilePath = Cc["@mozilla.org/file/directory_service;1"].
    1.16 +                    getService(Ci.nsIProperties).
    1.17 +                    get("ProfD", Ci.nsIFile);
    1.18 +  function getSessionstoreFile() {
    1.19 +    let sessionStoreJS = profilePath.clone();
    1.20 +    sessionStoreJS.append("sessionstore.js");
    1.21 +    return sessionStoreJS;
    1.22 +  }
    1.23 +  function getSessionstorejsModificationTime() {
    1.24 +    let file = getSessionstoreFile();
    1.25 +    if (file.exists())
    1.26 +      return file.lastModifiedTime;
    1.27 +    else
    1.28 +      return -1;
    1.29 +  }
    1.30 +
    1.31 +  // delete existing sessionstore.js, to make sure we're not reading
    1.32 +  // the mtime of an old one initialy
    1.33 +  let (sessionStoreJS = getSessionstoreFile()) {
    1.34 +    if (sessionStoreJS.exists())
    1.35 +      sessionStoreJS.remove(false);
    1.36 +  }
    1.37 +
    1.38 +  // test content URL
    1.39 +  const TEST_URL = "data:text/html;charset=utf-8,"
    1.40 +    + "<body style='width: 100000px; height: 100000px;'><p>top</p></body>"
    1.41 +
    1.42 +  // preferences that we use
    1.43 +  const PREF_INTERVAL = "browser.sessionstore.interval";
    1.44 +
    1.45 +  // make sure sessionstore.js is saved ASAP on all events
    1.46 +  gPrefService.setIntPref(PREF_INTERVAL, 0);
    1.47 +
    1.48 +  // get the initial sessionstore.js mtime (-1 if it doesn't exist yet)
    1.49 +  let mtime0 = getSessionstorejsModificationTime();
    1.50 +
    1.51 +  // create and select a first tab
    1.52 +  let tab = gBrowser.addTab(TEST_URL);
    1.53 +  whenBrowserLoaded(tab.linkedBrowser, function() {
    1.54 +    // step1: the above has triggered some saveStateDelayed(), sleep until
    1.55 +    // it's done, and get the initial sessionstore.js mtime
    1.56 +    setTimeout(function step1(e) {
    1.57 +      let mtime1 = getSessionstorejsModificationTime();
    1.58 +      isnot(mtime1, mtime0, "initial sessionstore.js update");
    1.59 +
    1.60 +      // step2: test sessionstore.js is not updated on tab selection
    1.61 +      // or content scrolling
    1.62 +      gBrowser.selectedTab = tab;
    1.63 +      tab.linkedBrowser.contentWindow.scrollTo(1100, 1200);
    1.64 +      setTimeout(function step2(e) {
    1.65 +        let mtime2 = getSessionstorejsModificationTime();
    1.66 +        is(mtime2, mtime1,
    1.67 +           "tab selection and scrolling: sessionstore.js not updated");
    1.68 +
    1.69 +        // ok, done, cleanup and finish
    1.70 +        if (gPrefService.prefHasUserValue(PREF_INTERVAL))
    1.71 +          gPrefService.clearUserPref(PREF_INTERVAL);
    1.72 +        gBrowser.removeTab(tab);
    1.73 +        finish();
    1.74 +      }, 3500); // end of sleep after tab selection and scrolling
    1.75 +    }, 3500); // end of sleep after initial saveStateDelayed()
    1.76 +  });
    1.77 +}

mercurial