tor-browser

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

browser_aboutSupport.js (5818B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { ExperimentAPI } = ChromeUtils.importESModule(
      7  "resource://nimbus/ExperimentAPI.sys.mjs"
      8 );
      9 const { NimbusTestUtils } = ChromeUtils.importESModule(
     10  "resource://testing-common/NimbusTestUtils.sys.mjs"
     11 );
     12 const { RemoteSettings } = ChromeUtils.importESModule(
     13  "resource://services-settings/remote-settings.sys.mjs"
     14 );
     15 ChromeUtils.defineESModuleGetters(this, {
     16  sinon: "resource://testing-common/Sinon.sys.mjs",
     17 });
     18 
     19 add_task(async function () {
     20  await BrowserTestUtils.withNewTab(
     21    { gBrowser, url: "about:support" },
     22    async function (browser) {
     23      let keyLocationServiceGoogleStatus = await SpecialPowers.spawn(
     24        browser,
     25        [],
     26        async function () {
     27          let textBox = content.document.getElementById(
     28            "key-location-service-google-box"
     29          );
     30          await ContentTaskUtils.waitForCondition(
     31            () => content.document.l10n.getAttributes(textBox).id,
     32            "Google location service API key status loaded"
     33          );
     34          return content.document.l10n.getAttributes(textBox).id;
     35        }
     36      );
     37      ok(
     38        keyLocationServiceGoogleStatus,
     39        "Google location service API key status shown"
     40      );
     41 
     42      let keySafebrowsingGoogleStatus = await SpecialPowers.spawn(
     43        browser,
     44        [],
     45        async function () {
     46          let textBox = content.document.getElementById(
     47            "key-safebrowsing-google-box"
     48          );
     49          await ContentTaskUtils.waitForCondition(
     50            () => content.document.l10n.getAttributes(textBox).id,
     51            "Google Safebrowsing API key status loaded"
     52          );
     53          return content.document.l10n.getAttributes(textBox).id;
     54        }
     55      );
     56      ok(
     57        keySafebrowsingGoogleStatus,
     58        "Google Safebrowsing API key status shown"
     59      );
     60 
     61      let keyMozillaStatus = await SpecialPowers.spawn(
     62        browser,
     63        [],
     64        async function () {
     65          let textBox = content.document.getElementById("key-mozilla-box");
     66          await ContentTaskUtils.waitForCondition(
     67            () => content.document.l10n.getAttributes(textBox).id,
     68            "Mozilla API key status loaded"
     69          );
     70          return content.document.l10n.getAttributes(textBox).id;
     71        }
     72      );
     73      ok(keyMozillaStatus, "Mozilla API key status shown");
     74    }
     75  );
     76 });
     77 
     78 add_task(async function test_nimbus_experiments() {
     79  await ExperimentAPI.ready();
     80  let doExperimentCleanup = await NimbusTestUtils.enrollWithFeatureConfig({
     81    featureId: "aboutwelcome",
     82    value: { enabled: true },
     83  });
     84 
     85  await BrowserTestUtils.withNewTab(
     86    { gBrowser, url: "about:support" },
     87    async function (browser) {
     88      let experimentName = await SpecialPowers.spawn(
     89        browser,
     90        [],
     91        async function () {
     92          await ContentTaskUtils.waitForCondition(
     93            () =>
     94              content.document.querySelector(
     95                "#remote-experiments-tbody tr:first-child td"
     96              )?.innerText
     97          );
     98          return content.document.querySelector(
     99            "#remote-experiments-tbody tr:first-child td"
    100          ).innerText;
    101        }
    102      );
    103      ok(
    104        experimentName.match("Nimbus"),
    105        "Rendered the expected experiment slug"
    106      );
    107    }
    108  );
    109 
    110  await doExperimentCleanup();
    111 });
    112 
    113 add_task(async function test_remote_configuration() {
    114  await ExperimentAPI.ready();
    115  let doCleanup = await NimbusTestUtils.enrollWithFeatureConfig(
    116    {
    117      featureId: NimbusFeatures.aboutwelcome.featureId,
    118      value: { enabled: true },
    119    },
    120    { isRollout: true }
    121  );
    122 
    123  await BrowserTestUtils.withNewTab(
    124    { gBrowser, url: "about:support" },
    125    async function (browser) {
    126      let [userFacingName, branch] = await SpecialPowers.spawn(
    127        browser,
    128        [],
    129        async function () {
    130          await ContentTaskUtils.waitForCondition(
    131            () =>
    132              content.document.querySelector(
    133                "#remote-features-tbody tr:first-child td"
    134              )?.innerText
    135          );
    136          let rolloutName = content.document.querySelector(
    137            "#remote-features-tbody tr:first-child td"
    138          ).innerText;
    139          let branchName = content.document.querySelector(
    140            "#remote-features-tbody tr:first-child td:nth-child(2)"
    141          ).innerText;
    142 
    143          return [rolloutName, branchName];
    144        }
    145      );
    146      ok(
    147        userFacingName.match("NimbusTestUtils recipe"),
    148        `Rendered the expected rollout ${userFacingName}`
    149      );
    150      ok(branch.match("control"), "Rendered the expected rollout branch");
    151    }
    152  );
    153 
    154  doCleanup();
    155 });
    156 
    157 add_task(async function test_remote_settings() {
    158  const sandbox = sinon.createSandbox();
    159  sandbox.stub(RemoteSettings, "inspect").resolves({
    160    isSynchronizationBroken: false,
    161    lastCheck: 1715698289,
    162    localTimestamp: '"1715698176626"',
    163    history: {
    164      "settings-sync": [
    165        { status: "SUCCESS", datetime: "2024-05-14T14:49:36.626Z", infos: {} },
    166      ],
    167    },
    168  });
    169 
    170  await BrowserTestUtils.withNewTab(
    171    { gBrowser, url: "about:support" },
    172    async browser => {
    173      const localTimestamp = await SpecialPowers.spawn(
    174        browser,
    175        [],
    176        async () => {
    177          const sel = "#support-remote-settings-local-timestamp";
    178          await ContentTaskUtils.waitForCondition(
    179            () => content.document.querySelector(sel)?.innerText
    180          );
    181          return content.document.querySelector(sel).innerText;
    182        }
    183      );
    184      Assert.equal(
    185        localTimestamp,
    186        '"1715698176626"',
    187        "Rendered the local timestamp"
    188      );
    189    }
    190  );
    191 
    192  registerCleanupFunction(() => {
    193    sandbox.restore();
    194  });
    195 });