Bug 1945643 - Update to mozilla-nimbus-schemas 2025.1.1 r=chumphreys
[gecko.git] / dom / quota / test / marionette / test_private_repository_cleanup.py
blob54b7466386823b08c1a92bd14d7b93ffe95729ac
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/.
5 import os
6 import sys
7 from pathlib import Path
9 sys.path.append(os.fspath(Path(__file__).parents[0]))
10 from quota_test_case import QuotaTestCase
12 QM_TESTING_PREF = "dom.quotaManager.testing"
13 AUTOSTART_PBM_PREF = "browser.privatebrowsing.autostart"
15 """
16 This test ensures that private repository gets properly purged in all below scenarios:
17 1. at PBM session end
18 2. on firefox start when last session was abnormally terminated (crash)
19 3. on firefox shutdown (when PBM autostart is enabled i.e. browser.privatebrowsing.autostart set to true)
20 """
23 class PrivateRepositoryCleanup(QuotaTestCase):
24 def setUp(self, autostartPBM=False):
25 super(PrivateRepositoryCleanup, self).setUp()
27 self.marionette.set_pref(AUTOSTART_PBM_PREF, autostartPBM)
28 self.marionette.set_pref(QM_TESTING_PREF, True)
30 self.marionette.restart(in_app=True)
32 assert self.initStorage()
33 assert self.initTemporaryStorage()
35 def tearDown(self):
36 self.marionette.clear_pref(AUTOSTART_PBM_PREF)
37 self.marionette.clear_pref(QM_TESTING_PREF)
39 self.marionette.restart(in_app=True)
40 super(PrivateRepositoryCleanup, self).tearDown()
42 def doStorageWork(self):
43 origin = "https://example.com^privateBrowsingId=1"
44 assert self.initTemporaryOrigin("private", origin)
46 self.ensureInvariantHolds(lambda _: os.path.exists(self.getPrivateRepository()))
48 def verifyCleanup(self):
49 self.ensureInvariantHolds(
50 lambda _: not os.path.exists(self.getPrivateRepository())
53 def getPrivateRepository(self):
54 return self.getRepositoryPath("private")
57 class PBM(PrivateRepositoryCleanup):
58 def test_ensure_cleanup(self):
59 with self.using_new_window("", private=True):
60 self.doStorageWork()
62 # private window must have been close by now
63 self.verifyCleanup()
65 def test_ensure_cleanup_after_crash(self):
66 with self.using_new_window("", private=True, skipCleanup=True):
67 self.doStorageWork()
69 # verify cleanup was performed after crashing and restarting
70 # firefox with in_app=False
71 self.marionette.restart(in_app=False)
72 self.verifyCleanup()
75 class PBMAutoStart(PrivateRepositoryCleanup):
76 def setUp(self):
77 super(PBMAutoStart, self).setUp(True)
79 def test_ensure_cleanup(self):
80 self.doStorageWork()
82 # verify cleanup was performed at the shutdown
83 self.marionette.quit(in_app=True)
84 self.verifyCleanup()
86 self.marionette.start_session()
88 def test_ensure_cleanup_after_crash(self):
89 self.doStorageWork()
91 # verify cleanup was performed after crashing and restarting
92 # firefox with in_app=False
93 self.marionette.restart(in_app=False)
94 self.verifyCleanup()