tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_506482.js (2727B)


      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/. */
      4 /* eslint-disable mozilla/no-arbitrary-setTimeout */
      5 
      6 function test() {
      7  /** Test for Bug 506482 */
      8 
      9  // test setup
     10  waitForExplicitFinish();
     11 
     12  // read the sessionstore.js mtime (picked from browser_248970_a.js)
     13  let profilePath = Services.dirsvc.get("ProfD", Ci.nsIFile);
     14  function getSessionstoreFile() {
     15    let sessionStoreJS = profilePath.clone();
     16    sessionStoreJS.append("sessionstore.jsonlz4");
     17    return sessionStoreJS;
     18  }
     19  function getSessionstorejsModificationTime() {
     20    let file = getSessionstoreFile();
     21    if (file.exists()) {
     22      return file.lastModifiedTime;
     23    }
     24    return -1;
     25  }
     26 
     27  // delete existing sessionstore.js, to make sure we're not reading
     28  // the mtime of an old one initially.
     29  let sessionStoreJS = getSessionstoreFile();
     30  if (sessionStoreJS.exists()) {
     31    sessionStoreJS.remove(false);
     32  }
     33 
     34  // test content URL
     35  const TEST_URL =
     36    "data:text/html;charset=utf-8," +
     37    "<body style='width: 100000px; height: 100000px;'><p>top</p></body>";
     38 
     39  // preferences that we use
     40  const PREF_INTERVAL = "browser.sessionstore.interval";
     41 
     42  // make sure sessionstore.js is saved ASAP on all events
     43  Services.prefs.setIntPref(PREF_INTERVAL, 0);
     44 
     45  // get the initial sessionstore.js mtime (-1 if it doesn't exist yet)
     46  let mtime0 = getSessionstorejsModificationTime();
     47 
     48  // create and select a first tab
     49  let tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
     50  promiseBrowserLoaded(tab.linkedBrowser).then(() => {
     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() {
     54      let mtime1 = getSessionstorejsModificationTime();
     55      isnot(mtime1, mtime0, "initial sessionstore.js update");
     56 
     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() {
     62        let mtime2 = getSessionstorejsModificationTime();
     63        is(
     64          mtime2,
     65          mtime1,
     66          "tab selection and scrolling: sessionstore.js not updated"
     67        );
     68 
     69        // ok, done, cleanup and finish
     70        if (Services.prefs.prefHasUserValue(PREF_INTERVAL)) {
     71          Services.prefs.clearUserPref(PREF_INTERVAL);
     72        }
     73        gBrowser.removeTab(tab);
     74        finish();
     75      }, 3500); // end of sleep after tab selection and scrolling
     76    }, 3500); // end of sleep after initial saveStateDelayed()
     77  });
     78 }