tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit acf02673980a1e28ea660340e393d366a814ec6f
parent 4cbe981d6d500a5d551cca33e10bf9a6b55bc91a
Author: Harsheet <hsohaney@mozilla.com>
Date:   Fri, 12 Dec 2025 13:56:25 +0000

Bug 2003079 - Add a marionette test to see if backups are deleted between sessions. r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D275004

Diffstat:
Mbrowser/components/backup/tests/marionette/test_backup.py | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+), 0 deletions(-)

diff --git a/browser/components/backup/tests/marionette/test_backup.py b/browser/components/backup/tests/marionette/test_backup.py @@ -317,10 +317,80 @@ class BackupTest(MarionetteTestCase): mozfile.remove(archivePath) mozfile.remove(recoveryPath) + def test_backup_disablement_in_new_session(self): + archiveDestPath = os.path.join( + tempfile.gettempdir(), "backup-dest-disable-test" + ) + + [archivePath, lastBackupFileName] = self.marionette.execute_async_script( + """ + const { BackupService } = ChromeUtils.importESModule("resource:///modules/backup/BackupService.sys.mjs"); + let bs = BackupService.init(); + if (!bs) { + throw new Error("Could not get initialized BackupService."); + } + + let [archiveDestPath, outerResolve] = arguments; + bs.setParentDirPath(archiveDestPath); + + (async () => { + bs.setScheduledBackups(true); + let { archivePath } = await bs.createBackup(); + if (!archivePath) { + throw new Error("Could not create backup."); + } + + let lastBackupFileName = Services.prefs.getStringPref("browser.backup.scheduled.last-backup-file", ""); + return [archivePath, lastBackupFileName]; + })().then(outerResolve); + """, + script_args=[archiveDestPath], + ) + + print(f"Created backup at: {archivePath}") + print(f"Last backup filename: {lastBackupFileName}") + + self.marionette.quit() + self.marionette.start_session() + self.marionette.set_context("chrome") + + if os.path.exists(archivePath): + print(f"File size: {os.path.getsize(archivePath)} bytes") + + self.marionette.execute_async_script( + """ + + ChromeUtils.defineESModuleGetters(this, { + BackupService: "resource:///modules/backup/BackupService.sys.mjs", + ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs", + }); + + let bs = BackupService.init(); + if (!bs) { + throw new Error("Could not get initialized BackupService."); + } + + let [outerResolve] = arguments; + (async () => { + await ASRouterTargeting.Environment.backupsInfo; + await bs.cleanupBackupFiles(); + bs.setScheduledBackups(false); + })().then(outerResolve); + """, + script_args=[], + ) + + archiveDeletedAfterDisable = not os.path.exists(archivePath) + self.assertTrue( + archiveDeletedAfterDisable, + f"Backup file should be deleted after disabling backups. Path: {archivePath}, exists: {os.path.exists(archivePath)}", + ) + def add_test_cookie(self): self.marionette.execute_async_script( """ let [outerResolve] = arguments; + (async () => { // We'll just add a single cookie, and then make sure that it shows // up on the other side.