Skip to content

Commit 2bdac9d

Browse files
author
Micah Tigley
committed
Bug 1947634 - Add Glean event for changes to password records. r=rsafaeian,credential-management-reviewers
Depends on D237967 Differential Revision: https://phabricator.services.mozilla.com/D238130
1 parent a197076 commit 2bdac9d

File tree

8 files changed

+90
-4
lines changed

8 files changed

+90
-4
lines changed

toolkit/components/satchel/megalist/aggregator/datasources/LoginDataSource.sys.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ export class LoginDataSource extends DataSourceBase {
387387
});
388388
}
389389

390+
#recordLoginsUpdate(changeType) {
391+
Glean.contextualManager.recordsUpdate.record({
392+
change_type: changeType,
393+
});
394+
}
395+
390396
async #importFromFile(title, buttonLabel, csvTitle, tsvTitle) {
391397
const { BrowserWindowTracker } = ChromeUtils.importESModule(
392398
"resource:///modules/BrowserWindowTracker.sys.mjs"
@@ -493,6 +499,7 @@ export class LoginDataSource extends DataSourceBase {
493499
l10nArgs: { total },
494500
viewMode: VIEW_MODES.LIST,
495501
});
502+
this.#recordLoginsUpdate("remove_all");
496503
}
497504
}
498505

@@ -637,6 +644,7 @@ export class LoginDataSource extends DataSourceBase {
637644
guid: newLogin.guid,
638645
viewMode: VIEW_MODES.LIST,
639646
});
647+
this.#recordLoginsUpdate("add");
640648
} catch (error) {
641649
this.#handleLoginStorageErrors(origin, error);
642650
}
@@ -663,6 +671,7 @@ export class LoginDataSource extends DataSourceBase {
663671
id: "update-login-success",
664672
viewMode: VIEW_MODES.LIST,
665673
});
674+
this.#recordLoginsUpdate("edit");
666675
} catch (error) {
667676
this.#handleLoginStorageErrors(modifiedLogin.origin, error);
668677
}
@@ -713,6 +722,7 @@ export class LoginDataSource extends DataSourceBase {
713722
l10nArgs: { total: 1 },
714723
viewMode: VIEW_MODES.LIST,
715724
});
725+
this.#recordLoginsUpdate("remove");
716726
}
717727

718728
/**
@@ -849,6 +859,13 @@ export class LoginDataSource extends DataSourceBase {
849859
message == "signon.management.page.breach-alerts.enabled" ||
850860
message == "signon.management.page.vulnerable-passwords.enabled"
851861
) {
862+
if (
863+
topic == "passwordmgr-storage-changed" &&
864+
message === "importLogins"
865+
) {
866+
this.#recordLoginsUpdate("import");
867+
}
868+
852869
this.#reloadDataSource();
853870
}
854871
}

toolkit/components/satchel/megalist/content/tests/browser/browser_passwords_create_login.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,24 @@ add_task(async function test_add_login_success() {
6666
const megalist = await openPasswordsSidebar();
6767
await waitForSnapshots();
6868
await openLoginForm(megalist);
69-
let events = Glean.contextualManager.toolbarAction.testGetValue();
70-
Assert.equal(events.length, 1, "Recorded add password once.");
71-
assertCPMGleanEvent(events[0], {
69+
70+
let toolbarEvents = Glean.contextualManager.toolbarAction.testGetValue();
71+
Assert.equal(toolbarEvents.length, 1, "Recorded add password once.");
72+
assertCPMGleanEvent(toolbarEvents[0], {
7273
trigger: "toolbar",
7374
option_name: "add_new",
7475
});
76+
7577
addLogin(megalist, TEST_LOGIN_1);
7678
await waitForNotification(megalist, "add-login-success");
7779
await checkAllLoginsRendered(megalist);
7880

81+
let updateEvents = Glean.contextualManager.recordsUpdate.testGetValue();
82+
Assert.equal(updateEvents.length, 1, "Recorded manual add password once.");
83+
assertCPMGleanEvent(updateEvents[0], {
84+
change_type: "add",
85+
});
86+
7987
LoginTestUtils.clearData();
8088
});
8189

toolkit/components/satchel/megalist/content/tests/browser/browser_passwords_delete_login.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ add_task(async function test_delete_login_success() {
1919
return;
2020
}
2121

22+
Services.fog.testResetFOG();
23+
await Services.fog.testFlushAllChildren();
24+
2225
await addMockPasswords();
2326
info("Three logins added in total.");
2427

@@ -48,6 +51,13 @@ add_task(async function test_delete_login_success() {
4851
info("Delete one login.");
4952

5053
await waitForNotification(megalist, "delete-login-success");
54+
let updateEvents = Glean.contextualManager.recordsUpdate.testGetValue();
55+
56+
Assert.equal(updateEvents.length, 1, "Recorded delete password once.");
57+
assertCPMGleanEvent(updateEvents[0], {
58+
change_type: "remove",
59+
});
60+
5161
await checkAllLoginsRendered(megalist);
5262

5363
const numPasswords = megalist.querySelectorAll("password-card").length;

toolkit/components/satchel/megalist/content/tests/browser/browser_passwords_remove_all_notification.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ add_task(
7979
return;
8080
}
8181

82+
Services.fog.testResetFOG();
83+
await Services.fog.testFlushAllChildren();
84+
8285
const megalist = await openPasswordsSidebar();
8386
await addMockPasswords();
8487
await checkAllLoginsRendered(megalist);
@@ -121,6 +124,12 @@ add_task(
121124
await checkEmptyState(".no-logins-card-content", megalist);
122125
ok(true, "Empty state rendered after logins are removed.");
123126

127+
let updateEvents = Glean.contextualManager.recordsUpdate.testGetValue();
128+
Assert.equal(updateEvents.length, 1, "Recorded delete all passwords once.");
129+
assertCPMGleanEvent(updateEvents[0], {
130+
change_type: "remove_all",
131+
});
132+
124133
info("Closing the sidebar");
125134
SidebarController.hide();
126135
Services.prompt = originalPromptService;

toolkit/components/satchel/megalist/content/tests/browser/browser_passwords_sidebar_import_from_csv.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ add_task(async function test_import_empty_state() {
154154
const summary = mozMessageBar.messageL10nArgs;
155155
is(summary.added, 1, "Import added one item");
156156

157+
let updateEvents = Glean.contextualManager.recordsUpdate.testGetValue();
158+
Assert.equal(updateEvents.length, 1, "Recorded import passwords once.");
159+
assertCPMGleanEvent(updateEvents[0], {
160+
change_type: "import",
161+
});
162+
157163
info("Closing the sidebar");
158164
SidebarController.hide();
159165
});

toolkit/components/satchel/megalist/content/tests/browser/browser_passwords_update_login.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ add_task(async function test_update_login_success() {
6565
() => updatedPasswordCard.passwordLine.value === newPassword,
6666
"Password not updated."
6767
);
68+
69+
let updateEvents = Glean.contextualManager.recordsUpdate.testGetValue();
70+
Assert.equal(updateEvents.length, 1, "Recorded update password once.");
71+
assertCPMGleanEvent(updateEvents[0], {
72+
change_type: "edit",
73+
});
6874
LoginTestUtils.clearData();
6975
SidebarController.hide();
7076
});
@@ -115,6 +121,9 @@ add_task(async function test_update_login_discard_changes() {
115121
return;
116122
}
117123

124+
Services.fog.testResetFOG();
125+
await Services.fog.testFlushAllChildren();
126+
118127
const login = TEST_LOGIN_1;
119128
await LoginTestUtils.addLogin(login);
120129

toolkit/components/satchel/megalist/content/tests/browser/head.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function assertCPMGleanEvent(actualEvent, expectedEvent) {
236236
Assert.equal(
237237
actualEvent.extra[key],
238238
expectedEvent[key],
239-
`${actualEvent.extra[key]} is the recorded trigger.
239+
`${actualEvent.extra[key]} is the recorded ${key}.
240240
Expected: '${expectedEvent[key]}'.`
241241
);
242242
}

toolkit/components/satchel/megalist/metrics.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ contextual_manager:
4949
The action selected from the toolbar
5050
type: string
5151

52+
records_update:
53+
type: event
54+
description: >
55+
Client modifies, adds, or removes CM record. Captures changes committed to
56+
a client's password management records.
57+
Possible change types:
58+
"add": Single record is created
59+
"edit": Single record is edited
60+
"remove": Single record is removed
61+
"remove_all": All records are removed
62+
"import": Records were changed by importing from another dataset
63+
(such as a file, browser)
64+
bugs:
65+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1947634
66+
data_reviews:
67+
- https://bugzilla.mozilla.org/show_bug.cgi?id=1947634
68+
notification_emails:
69+
- passwords-dev@mozilla.org
70+
- issozi@mozilla.com
71+
- tthorne@mozilla.com
72+
expires: never
73+
extra_keys:
74+
change_type:
75+
description: >
76+
The type of change the client made to records
77+
type: string
78+
5279
records_interaction:
5380
type: event
5481
description: >

0 commit comments

Comments
 (0)