tor-browser

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

commit d4aa022380da7e3c96a25035d4dd3182a209ad02
parent df59ce6374fa20c338d3de7373021bbd1a3a499b
Author: Duncan McIntosh <dmcintosh@mozilla.com>
Date:   Wed, 29 Oct 2025 19:37:55 +0000

Bug 1992808 - Part 2: Include the reason for creating the backup in telemetry when started from BackupUIParent. r=hsohaney

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

Diffstat:
Mbrowser/components/backup/actors/BackupUIParent.sys.mjs | 12+++++++-----
Mbrowser/components/backup/metrics.yaml | 6++----
Mbrowser/components/backup/tests/browser/browser_settings.js | 5+++++
Mbrowser/components/backup/tests/browser/browser_settings_create_backup.js | 10++++++++++
Mbrowser/components/backup/tests/browser/browser_settings_enable_backup_encryption.js | 5+++++
5 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/browser/components/backup/actors/BackupUIParent.sys.mjs b/browser/components/backup/actors/BackupUIParent.sys.mjs @@ -76,11 +76,13 @@ export class BackupUIParent extends JSWindowActorParent { /** * Trigger a createBackup call. * + * @param {...any} args + * Arguments to pass through to createBackup. * @returns {object} Result of the backup attempt. */ - async #triggerCreateBackup() { + async #triggerCreateBackup(...args) { try { - await this.#bs.createBackup(); + await this.#bs.createBackup(...args); return { success: true }; } catch (e) { lazy.logConsole.error(`Failed to retrigger backup`, e); @@ -104,7 +106,7 @@ export class BackupUIParent extends JSWindowActorParent { if (message.name == "RequestState") { this.sendState(); } else if (message.name == "TriggerCreateBackup") { - return await this.#triggerCreateBackup(); + return await this.#triggerCreateBackup({ reason: "manual" }); } else if (message.name == "EnableScheduledBackups") { try { let { parentDirPath, password } = message.data; @@ -212,7 +214,7 @@ export class BackupUIParent extends JSWindowActorParent { return { success: false, errorCode: e.cause || lazy.ERRORS.UNKNOWN }; } - return await this.#triggerCreateBackup(); + return await this.#triggerCreateBackup({ reason: "encryption" }); } else if (message.name == "DisableEncryption") { try { await this.#bs.disableEncryption(); @@ -222,7 +224,7 @@ export class BackupUIParent extends JSWindowActorParent { return { success: false, errorCode: e.cause || lazy.ERRORS.UNKNOWN }; } - return await this.#triggerCreateBackup(); + return await this.#triggerCreateBackup({ reason: "encryption" }); } else if (message.name == "RerunEncryption") { try { let { password } = message.data; diff --git a/browser/components/backup/metrics.yaml b/browser/components/backup/metrics.yaml @@ -648,8 +648,7 @@ browser.backup: type: string description: > The reason that the backup was started. Can be one of the following: - - "manual" if the user selected "Backup Now" (not implemented yet, - will be in Part 2); + - "manual" if the user selected "Backup Now"; - "idle" if the user was idle and sufficiently long passed since the last backup (not implemented yet, will be in Part 3); - "missed" if the user was idle, sufficiently long has passed since @@ -657,8 +656,7 @@ browser.backup: Firefox opened (not implemented yet, will be in Part 3); - "user deleted some data" if cookies or other user data was deleted; - - "encryption" if the password was added, changed, or removed (not - implemented yet, will be in Part 2); + - "encryption" if the password was added, changed, or removed; - "location" if the location changed (not implemented yet, see bug 1996377); - "first" if scheduled backups were just enabled (not implemented diff --git a/browser/components/backup/tests/browser/browser_settings.js b/browser/components/backup/tests/browser/browser_settings.js @@ -198,6 +198,11 @@ add_task(async function test_disable_backup_encryption_confirm() { createBackupStub.calledOnce, "BackupService was called to create a new backup" ); + Assert.equal( + createBackupStub.firstCall.args[0].reason, + "encryption", + "Backup reason is set" + ); let legacyEvents = TelemetryTestUtils.getEvents( { diff --git a/browser/components/backup/tests/browser/browser_settings_create_backup.js b/browser/components/backup/tests/browser/browser_settings_create_backup.js @@ -34,6 +34,8 @@ add_setup(async () => { */ add_task(async function test_create_new_backup_trigger() { await BrowserTestUtils.withNewTab("about:preferences#sync", async browser => { + Services.fog.testResetFOG(); + let settings = browser.contentDocument.querySelector("backup-settings"); // disable the buffer for the test settings.MESSAGE_BAR_BUFFER = 0; @@ -109,6 +111,14 @@ add_task(async function test_create_new_backup_trigger() { () => !settings.backupInProgressMessageBarEl, "A backup is no longer in progress, the message bar should disappear" ); + + let gleanEvents = Glean.browserBackup.backupStart.testGetValue(); + Assert.equal(gleanEvents.length, 1, "backup_start event was recorded"); + Assert.equal( + gleanEvents[0].extra.reason, + "manual", + "correct reason for the backup was recorded" + ); }); }); diff --git a/browser/components/backup/tests/browser/browser_settings_enable_backup_encryption.js b/browser/components/backup/tests/browser/browser_settings_enable_backup_encryption.js @@ -112,6 +112,11 @@ add_task(async function test_enable_backup_encryption_checkbox_confirm() { createBackupStub.calledOnce, "BackupService was called to create a new backup" ); + Assert.equal( + createBackupStub.firstCall.args[0].reason, + "encryption", + "Backup reason is set" + ); let legacyEvents = TelemetryTestUtils.getEvents( {