commit 34490ef80f018d97f0cbfca5341b4e213e32e968
parent 5ca469ab2cf2fc07e41a7b47fded1bd7f5df1ea0
Author: Duncan McIntosh <dmcintosh@mozilla.com>
Date: Thu, 9 Oct 2025 21:59:45 +0000
Bug 1986557 - Part 3: Test that the installed_web_app_count metric is nonzero at startup if a Taskbar Tab exists. r=nrishel
Differential Revision: https://phabricator.services.mozilla.com/D268211
Diffstat:
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_existingInstalledCountMetric.js b/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_existingInstalledCountMetric.js
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ *http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// This test ensures that the installedWebAppCount metric is updated at
+// startup even if it is nonzero. Refer to
+// test_taskbarTabs_installedCountMetric.js for more details. (This needs to
+// be in a different test so TaskbarTabs initializes a second time.)
+
+ChromeUtils.defineESModuleGetters(this, {
+ sinon: "resource://testing-common/Sinon.sys.mjs",
+ TaskbarTabsPin: "resource:///modules/taskbartabs/TaskbarTabsPin.sys.mjs",
+});
+
+add_setup(function test_setup() {
+ do_get_profile();
+ Services.fog.initializeFOG();
+
+ sinon.stub(TaskbarTabsPin, "pinTaskbarTab");
+ sinon.stub(TaskbarTabsPin, "unpinTaskbarTab");
+});
+
+add_task(async function test_installedCounterMetric() {
+ const value = () => Glean.webApp.installedWebAppCount.testGetValue();
+ equal(value(), undefined, "Should not be set before initializing");
+
+ const taskbarTabsJSON = do_get_profile();
+ taskbarTabsJSON.append("taskbartabs");
+ taskbarTabsJSON.append("taskbartabs.json");
+ const kId = "4186657a-0fe5-492a-af64-dc628c232c4c";
+ await IOUtils.writeJSON(taskbarTabsJSON.path, {
+ version: 1,
+ taskbarTabs: [
+ {
+ id: kId,
+ scopes: [{ hostname: "www.test.com" }],
+ userContextId: 0,
+ startUrl: "https://www.test.com/start",
+ },
+ ],
+ });
+
+ // We do not want to import this unknowingly, since that would mess up the
+ // telemetry count, so import it explicitly right now.
+ const { TaskbarTabs } = ChromeUtils.importESModule(
+ "resource:///modules/taskbartabs/TaskbarTabs.sys.mjs"
+ );
+
+ // Initialization is asynchronous, so do something to wait for it.
+ await TaskbarTabs.waitUntilReady();
+
+ equal(value(), 1, "The existing Taskbar Tab was counted");
+
+ const tt = await TaskbarTabs.findOrCreateTaskbarTab(
+ Services.io.newURI("https://www.test.com"),
+ 0
+ );
+ equal(tt.id, kId, "Correct Taskbar Tab was found");
+ equal(value(), 1, "Finding a Taskbar Tab does not affect the count");
+
+ await TaskbarTabs.removeTaskbarTab(tt.id);
+ equal(value(), 0, "Removing the taskbar tab was accounted for");
+});
diff --git a/browser/components/taskbartabs/test/xpcshell/xpcshell.toml b/browser/components/taskbartabs/test/xpcshell/xpcshell.toml
@@ -8,6 +8,8 @@ support-files = [
"test_taskbarTabs_nonames.json",
]
+["test_taskbarTabs_existingInstalledCountMetric.js"]
+
["test_taskbarTabs_installedCountMetric.js"]
["test_taskbarTabs_pin.js"]