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/.
6 from pathlib
import Path
8 from marionette_driver
import Wait
9 from marionette_harness
import MarionetteTestCase
12 class PurgeHTTPCacheAtShutdownTestCase(MarionetteTestCase
):
15 self
.marionette
.enforce_gecko_prefs(
17 "privacy.sanitize.sanitizeOnShutdown": True,
18 "privacy.clearOnShutdown.cache": True,
19 "network.cache.shutdown_purge_in_background_task": True,
23 self
.profile_path
= Path(self
.marionette
.profile_path
)
24 self
.cache_path
= self
.profile_path
.joinpath("cache2")
27 self
.marionette
.cleanup()
30 def cacheDirExists(self
):
31 return self
.cache_path
.exists()
33 def renamedDirExists(self
):
35 child
.name
.endswith(".purge.bg_rm") for child
in self
.profile_path
.iterdir()
38 def initLockDir(self
):
40 with self
.marionette
.using_context("chrome"):
41 path
= self
.marionette
.execute_script(
43 return Services.dirsvc.get("UpdRootD", Ci.nsIFile).parent.parent.path;
46 self
.lock_dir
= Path(path
)
48 def assertNoLocks(self
):
51 for x
in self
.lock_dir
.iterdir()
52 if x
.is_file() and "-cachePurge" in x
.name
54 self
.assertEqual(locks
, [], "All locks should have been removed")
56 # Tests are run in lexicographical order, so test_a* is run first to
57 # cleanup locks that may be there from previous runs.
58 def test_asetup(self
):
61 self
.marionette
.quit()
63 Wait(self
.marionette
, timeout
=60).until(
64 lambda _
: not self
.cacheDirExists() and not self
.renamedDirExists(),
65 message
="Cache directory must be removed after orderly shutdown",
68 # delete locks from previous runs
71 for x
in self
.lock_dir
.iterdir()
72 if x
.is_file() and "-cachePurge" in x
.name
76 # all locks should have been removed successfully.
79 def test_ensure_cache_purge_after_in_app_quit(self
):
80 self
.assertTrue(self
.cacheDirExists(), "Cache directory must exist")
83 self
.marionette
.quit()
85 Wait(self
.marionette
, timeout
=60).until(
86 lambda _
: not self
.cacheDirExists() and not self
.renamedDirExists(),
87 message
="Cache directory must be removed after orderly shutdown",
92 def test_longstanding_cache_purge_after_in_app_quit(self
):
93 self
.assertTrue(self
.cacheDirExists(), "Cache directory must exist")
96 self
.marionette
.set_pref(
97 "toolkit.background_tasks.remove_directory.testing.sleep_ms", 5000
100 self
.marionette
.quit()
102 Wait(self
.marionette
, timeout
=60).until(
103 lambda _
: not self
.cacheDirExists() and not self
.renamedDirExists(),
104 message
="Cache directory must be removed after orderly shutdown",
109 def test_ensure_cache_purge_after_forced_restart(self
):
111 Doing forced restart here to prevent the shutdown phase purging and only allow startup
112 phase one, via `CacheFileIOManager::OnDelayedStartupFinished`.
114 self
.profile_path
.joinpath("foo.purge.bg_rm").mkdir()
117 self
.marionette
.restart(in_app
=False)
119 Wait(self
.marionette
, timeout
=60).until(
120 lambda _
: not self
.renamedDirExists(),
121 message
="Directories with .purge.bg_rm postfix must be removed at startup after"
122 "disorderly shutdown",