tor-browser

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

browser_protectionsUI_milestones.js (3085B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 add_setup(async function () {
      5  await SpecialPowers.pushPrefEnv({
      6    set: [
      7      // Hide protections cards so as not to trigger more async messaging
      8      // when landing on the page.
      9      ["browser.contentblocking.report.monitor.enabled", false],
     10      ["browser.contentblocking.report.lockwise.enabled", false],
     11      ["browser.contentblocking.report.proxy.enabled", false],
     12      ["browser.contentblocking.cfr-milestone.update-interval", 0],
     13    ],
     14  });
     15 });
     16 
     17 add_task(async function doTest() {
     18  requestLongerTimeout(3);
     19 
     20  // The protections panel needs to be openend at least once,
     21  // or the milestone-achieved pref observer is not triggered.
     22  await BrowserTestUtils.withNewTab("https://example.com", async () => {
     23    await openProtectionsPanel();
     24    await closeProtectionsPanel();
     25  });
     26 
     27  // This also ensures that the DB tables have been initialized.
     28  await TrackingDBService.clearAll();
     29 
     30  let milestones = JSON.parse(
     31    Services.prefs.getStringPref(
     32      "browser.contentblocking.cfr-milestone.milestones"
     33    )
     34  );
     35 
     36  let tab = await BrowserTestUtils.openNewForegroundTab(
     37    gBrowser,
     38    "https://example.com"
     39  );
     40 
     41  for (let milestone of milestones) {
     42    Services.telemetry.clearEvents();
     43    // Trigger the milestone feature.
     44    Services.prefs.setIntPref(
     45      "browser.contentblocking.cfr-milestone.milestone-achieved",
     46      milestone
     47    );
     48    await TestUtils.waitForCondition(
     49      () => gProtectionsHandler._milestoneTextSet
     50    );
     51    // We set the shown-time pref to pretend that the CFR has been
     52    // shown, so that we can test the panel.
     53    // TODO: Full integration test for robustness.
     54    Services.prefs.setStringPref(
     55      "browser.contentblocking.cfr-milestone.milestone-shown-time",
     56      Date.now().toString()
     57    );
     58    await openProtectionsPanel();
     59 
     60    ok(
     61      BrowserTestUtils.isVisible(
     62        gProtectionsHandler._protectionsPopupMilestonesText
     63      ),
     64      "Milestones section should be visible in the panel."
     65    );
     66 
     67    await closeProtectionsPanel();
     68    await openProtectionsPanel();
     69 
     70    ok(
     71      BrowserTestUtils.isVisible(
     72        gProtectionsHandler._protectionsPopupMilestonesText
     73      ),
     74      "Milestones section should still be visible in the panel."
     75    );
     76 
     77    let newTabPromise = waitForAboutProtectionsTab();
     78    await EventUtils.synthesizeMouseAtCenter(
     79      document.getElementById("protections-popup-milestones-content"),
     80      {}
     81    );
     82    let protectionsTab = await newTabPromise;
     83 
     84    ok(true, "about:protections has been opened as expected.");
     85 
     86    BrowserTestUtils.removeTab(protectionsTab);
     87 
     88    await openProtectionsPanel();
     89 
     90    ok(
     91      !BrowserTestUtils.isVisible(
     92        gProtectionsHandler._protectionsPopupMilestonesText
     93      ),
     94      "Milestones section should no longer be visible in the panel."
     95    );
     96 
     97    checkClickTelemetry("milestone_message");
     98 
     99    await closeProtectionsPanel();
    100  }
    101 
    102  BrowserTestUtils.removeTab(tab);
    103  await TrackingDBService.clearAll();
    104 });