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/.
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"
16 This test ensures that private repository gets properly purged in all below scenarios:
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)
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()
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):
62 # private window must have been close by now
65 def test_ensure_cleanup_after_crash(self
):
66 with self
.using_new_window("", private
=True, skipCleanup
=True):
69 # verify cleanup was performed after crashing and restarting
70 # firefox with in_app=False
71 self
.marionette
.restart(in_app
=False)
75 class PBMAutoStart(PrivateRepositoryCleanup
):
77 super(PBMAutoStart
, self
).setUp(True)
79 def test_ensure_cleanup(self
):
82 # verify cleanup was performed at the shutdown
83 self
.marionette
.quit(in_app
=True)
86 self
.marionette
.start_session()
88 def test_ensure_cleanup_after_crash(self
):
91 # verify cleanup was performed after crashing and restarting
92 # firefox with in_app=False
93 self
.marionette
.restart(in_app
=False)