From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../components/sessionstore/test/browser_506482.js | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 browser/components/sessionstore/test/browser_506482.js (limited to 'browser/components/sessionstore/test/browser_506482.js') diff --git a/browser/components/sessionstore/test/browser_506482.js b/browser/components/sessionstore/test/browser_506482.js new file mode 100644 index 0000000000..a8e628ff7d --- /dev/null +++ b/browser/components/sessionstore/test/browser_506482.js @@ -0,0 +1,78 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* eslint-disable mozilla/no-arbitrary-setTimeout */ + +function test() { + /** Test for Bug 506482 **/ + + // test setup + waitForExplicitFinish(); + + // read the sessionstore.js mtime (picked from browser_248970_a.js) + let profilePath = Services.dirsvc.get("ProfD", Ci.nsIFile); + function getSessionstoreFile() { + let sessionStoreJS = profilePath.clone(); + sessionStoreJS.append("sessionstore.jsonlz4"); + return sessionStoreJS; + } + function getSessionstorejsModificationTime() { + let file = getSessionstoreFile(); + if (file.exists()) { + return file.lastModifiedTime; + } + return -1; + } + + // delete existing sessionstore.js, to make sure we're not reading + // the mtime of an old one initially. + let sessionStoreJS = getSessionstoreFile(); + if (sessionStoreJS.exists()) { + sessionStoreJS.remove(false); + } + + // test content URL + const TEST_URL = + "data:text/html;charset=utf-8," + + "

top

"; + + // preferences that we use + const PREF_INTERVAL = "browser.sessionstore.interval"; + + // make sure sessionstore.js is saved ASAP on all events + Services.prefs.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 = BrowserTestUtils.addTab(gBrowser, TEST_URL); + promiseBrowserLoaded(tab.linkedBrowser).then(() => { + // step1: the above has triggered some saveStateDelayed(), sleep until + // it's done, and get the initial sessionstore.js mtime + setTimeout(function step1() { + 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() { + let mtime2 = getSessionstorejsModificationTime(); + is( + mtime2, + mtime1, + "tab selection and scrolling: sessionstore.js not updated" + ); + + // ok, done, cleanup and finish + if (Services.prefs.prefHasUserValue(PREF_INTERVAL)) { + Services.prefs.clearUserPref(PREF_INTERVAL); + } + gBrowser.removeTab(tab); + finish(); + }, 3500); // end of sleep after tab selection and scrolling + }, 3500); // end of sleep after initial saveStateDelayed() + }); +} -- cgit v1.2.3