diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /netwerk/test/marionette | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/marionette')
-rw-r--r-- | netwerk/test/marionette/manifest.toml | 3 | ||||
-rw-r--r-- | netwerk/test/marionette/test_purge_http_cache_at_shutdown.py | 125 |
2 files changed, 128 insertions, 0 deletions
diff --git a/netwerk/test/marionette/manifest.toml b/netwerk/test/marionette/manifest.toml new file mode 100644 index 0000000000..9c6355f499 --- /dev/null +++ b/netwerk/test/marionette/manifest.toml @@ -0,0 +1,3 @@ +[DEFAULT] + +["test_purge_http_cache_at_shutdown.py"] diff --git a/netwerk/test/marionette/test_purge_http_cache_at_shutdown.py b/netwerk/test/marionette/test_purge_http_cache_at_shutdown.py new file mode 100644 index 0000000000..ee27e29e8d --- /dev/null +++ b/netwerk/test/marionette/test_purge_http_cache_at_shutdown.py @@ -0,0 +1,125 @@ +# 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/. + +import os +from pathlib import Path + +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class PurgeHTTPCacheAtShutdownTestCase(MarionetteTestCase): + def setUp(self): + super().setUp() + self.marionette.enforce_gecko_prefs( + { + "privacy.sanitize.sanitizeOnShutdown": True, + "privacy.clearOnShutdown.cache": True, + "network.cache.shutdown_purge_in_background_task": True, + } + ) + + self.profile_path = Path(self.marionette.profile_path) + self.cache_path = self.profile_path.joinpath("cache2") + + def tearDown(self): + self.marionette.cleanup() + super().tearDown() + + def cacheDirExists(self): + return self.cache_path.exists() + + def renamedDirExists(self): + return any( + child.name.endswith(".purge.bg_rm") for child in self.profile_path.iterdir() + ) + + def initLockDir(self): + self.lock_dir = None + with self.marionette.using_context("chrome"): + path = self.marionette.execute_script( + """ + return Services.dirsvc.get("UpdRootD", Ci.nsIFile).parent.parent.path; + """ + ) + self.lock_dir = Path(path) + + def assertNoLocks(self): + locks = [ + x + for x in self.lock_dir.iterdir() + if x.is_file() and "-cachePurge" in x.name + ] + self.assertEqual(locks, [], "All locks should have been removed") + + # Tests are run in lexicographical order, so test_a* is run first to + # cleanup locks that may be there from previous runs. + def test_asetup(self): + self.initLockDir() + + self.marionette.quit() + + Wait(self.marionette, timeout=60).until( + lambda _: not self.cacheDirExists() and not self.renamedDirExists(), + message="Cache directory must be removed after orderly shutdown", + ) + + # delete locks from previous runs + locks = [ + x + for x in self.lock_dir.iterdir() + if x.is_file() and "-cachePurge" in x.name + ] + for lock in locks: + os.remove(lock) + # all locks should have been removed successfully. + self.assertNoLocks() + + def test_ensure_cache_purge_after_in_app_quit(self): + self.assertTrue(self.cacheDirExists(), "Cache directory must exist") + self.initLockDir() + + self.marionette.quit() + + Wait(self.marionette, timeout=60).until( + lambda _: not self.cacheDirExists() and not self.renamedDirExists(), + message="Cache directory must be removed after orderly shutdown", + ) + + self.assertNoLocks() + + def test_longstanding_cache_purge_after_in_app_quit(self): + self.assertTrue(self.cacheDirExists(), "Cache directory must exist") + self.initLockDir() + + self.marionette.set_pref( + "toolkit.background_tasks.remove_directory.testing.sleep_ms", 5000 + ) + + self.marionette.quit() + + Wait(self.marionette, timeout=60).until( + lambda _: not self.cacheDirExists() and not self.renamedDirExists(), + message="Cache directory must be removed after orderly shutdown", + ) + + self.assertNoLocks() + + def test_ensure_cache_purge_after_forced_restart(self): + """ + Doing forced restart here to prevent the shutdown phase purging and only allow startup + phase one, via `CacheFileIOManager::OnDelayedStartupFinished`. + """ + self.profile_path.joinpath("foo.purge.bg_rm").mkdir() + self.initLockDir() + + self.marionette.restart(in_app=False) + + Wait(self.marionette, timeout=60).until( + lambda _: not self.renamedDirExists(), + message="Directories with .purge.bg_rm postfix must be removed at startup after" + "disorderly shutdown", + ) + + self.assertNoLocks() |