summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js')
-rw-r--r--toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js b/toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js
new file mode 100644
index 0000000000..dc8ac9c081
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/browser/browser_telemetry_SignUpFormRuleset.js
@@ -0,0 +1,53 @@
+"use strict";
+
+const SIGNUP_DETECTION_HISTOGRAM = "PWMGR_SIGNUP_FORM_DETECTION_MS";
+const TEST_URL = `https://example.com${DIRECTORY_PATH}form_signup_detection.html`;
+
+/**
+ *
+ * @param {Object} histogramData The histogram data to examine
+ * @returns The amount of entries found in the histogram data
+ */
+function countEntries(histogramData) {
+ return histogramData
+ ? Object.values(histogramData.values).reduce((a, b) => a + b, 0)
+ : null;
+}
+
+/**
+ * @param {String} id The histogram to examine
+ * @param {Number} expected The expected amount of entries for a histogram
+ */
+async function countEntriesOfChildHistogram(id, expected) {
+ let histogram;
+ await TestUtils.waitForCondition(() => {
+ let histograms = Services.telemetry.getSnapshotForHistograms(
+ "main",
+ false
+ ).content;
+
+ histogram = histograms[id];
+
+ return !!histogram && countEntries(histogram) == expected;
+ }, `The histogram ${id} was expected to have ${expected} entries.`);
+ Assert.equal(countEntries(histogram), expected);
+}
+
+add_setup(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [["signon.signupDetection.enabled", true]],
+ });
+ Services.telemetry.getHistogramById(SIGNUP_DETECTION_HISTOGRAM).clear();
+});
+
+add_task(async () => {
+ let formProcessed = listenForTestNotification("FormProcessed", 2);
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
+
+ await formProcessed;
+
+ await countEntriesOfChildHistogram(SIGNUP_DETECTION_HISTOGRAM, 2);
+
+ gBrowser.removeTab(tab);
+});