tor-browser

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

test_taskbarTabs_installedCountMetric.js (1968B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // This test ensures that the installedWebAppCount metric is updated at
      7 // startup. Remaining telemetry tests are in browser_taskbarTabs_telemetry.js;
      8 // this one is separate since it needs to check behaviour when the browser
      9 // starts, which we can't reliably do in a Mochitest.
     10 
     11 ChromeUtils.defineESModuleGetters(this, {
     12  sinon: "resource://testing-common/Sinon.sys.mjs",
     13  TaskbarTabsPin: "resource:///modules/taskbartabs/TaskbarTabsPin.sys.mjs",
     14 });
     15 
     16 add_setup(function test_setup() {
     17  do_get_profile();
     18  Services.fog.initializeFOG();
     19 
     20  sinon.stub(TaskbarTabsPin, "pinTaskbarTab");
     21  sinon.stub(TaskbarTabsPin, "unpinTaskbarTab");
     22 });
     23 
     24 add_task(async function test_installedCounterMetric() {
     25  const value = () => Glean.webApp.installedWebAppCount.testGetValue();
     26  equal(value(), undefined, "Should not be set before initializing");
     27 
     28  // We do not want to import this unknowingly, since that would mess up the
     29  // telemetry count, so import it explicitly right now.
     30  const { TaskbarTabs } = ChromeUtils.importESModule(
     31    "resource:///modules/taskbartabs/TaskbarTabs.sys.mjs"
     32  );
     33 
     34  // Initialization is asynchronous, so do something to wait for it.
     35  await TaskbarTabs.waitUntilReady();
     36 
     37  equal(value(), 0, "No taskbar tabs exist yet");
     38 
     39  const tt1 = await createTaskbarTab(
     40    TaskbarTabs,
     41    Services.io.newURI("https://example.com"),
     42    0
     43  );
     44  equal(value(), 1, "First new taskbar tab was accounted for");
     45 
     46  const tt2 = await createTaskbarTab(
     47    TaskbarTabs,
     48    Services.io.newURI("https://example.edu"),
     49    0
     50  );
     51  equal(value(), 2, "Second new taskbar tab was accounted for");
     52 
     53  await TaskbarTabs.removeTaskbarTab(tt1.id);
     54  equal(value(), 1, "Removing first taskbar tab was accounted for");
     55 
     56  await TaskbarTabs.removeTaskbarTab(tt2.id);
     57  equal(value(), 0, "Removing second taskbar tab was accounted for");
     58 });