tor-browser

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

test_taskbarTabs_existingInstalledCountMetric.js (2262B)


      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 even if it is nonzero. Refer to
      8 // test_taskbarTabs_installedCountMetric.js for more details. (This needs to
      9 // be in a different test so TaskbarTabs initializes a second time.)
     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  const taskbarTabsJSON = do_get_profile();
     29  taskbarTabsJSON.append("taskbartabs");
     30  taskbarTabsJSON.append("taskbartabs.json");
     31  const kId = "4186657a-0fe5-492a-af64-dc628c232c4c";
     32  await IOUtils.writeJSON(taskbarTabsJSON.path, {
     33    version: 1,
     34    taskbarTabs: [
     35      {
     36        id: kId,
     37        scopes: [{ hostname: "www.test.com" }],
     38        userContextId: 0,
     39        startUrl: "https://www.test.com/start",
     40      },
     41    ],
     42  });
     43 
     44  // We do not want to import this unknowingly, since that would mess up the
     45  // telemetry count, so import it explicitly right now.
     46  const { TaskbarTabs } = ChromeUtils.importESModule(
     47    "resource:///modules/taskbartabs/TaskbarTabs.sys.mjs"
     48  );
     49 
     50  // Initialization is asynchronous, so do something to wait for it.
     51  await TaskbarTabs.waitUntilReady();
     52 
     53  equal(value(), 1, "The existing Taskbar Tab was counted");
     54 
     55  const { taskbarTab, created } = await TaskbarTabs.findOrCreateTaskbarTab(
     56    Services.io.newURI("https://www.test.com"),
     57    0
     58  );
     59  equal(created, false, "No new Taskbar Tab was created");
     60  equal(taskbarTab.id, kId, "Correct Taskbar Tab was found");
     61  equal(value(), 1, "Finding a Taskbar Tab does not affect the count");
     62 
     63  await TaskbarTabs.removeTaskbarTab(taskbarTab.id);
     64  equal(value(), 0, "Removing the taskbar tab was accounted for");
     65 });