tor-browser

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

browser_protectionsUI_info_message.js (2786B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /* Tests the info message that apears in the protections panel
      5 * on first render, and afterward by clicking the "info" icon */
      6 
      7 "use strict";
      8 
      9 const TRACKING_PAGE =
     10  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     11  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html";
     12 
     13 add_setup(async function () {
     14  await SpecialPowers.pushPrefEnv({
     15    set: [
     16      // Set the auto hide timing to 100ms for blocking the test less.
     17      ["browser.protections_panel.toast.timeout", 100],
     18      // Hide protections cards so as not to trigger more async messaging
     19      // when landing on the page.
     20      ["browser.contentblocking.report.monitor.enabled", false],
     21      ["browser.contentblocking.report.lockwise.enabled", false],
     22      ["browser.contentblocking.report.proxy.enabled", false],
     23      ["privacy.trackingprotection.enabled", true],
     24      // Set the infomessage pref to ensure the message is displayed
     25      // every time
     26      ["browser.protections_panel.infoMessage.seen", false],
     27    ],
     28  });
     29  let oldCanRecord = Services.telemetry.canRecordExtended;
     30  Services.telemetry.canRecordExtended = true;
     31  Services.telemetry.clearEvents();
     32 
     33  registerCleanupFunction(() => {
     34    Services.telemetry.canRecordExtended = oldCanRecord;
     35    Services.telemetry.clearEvents();
     36  });
     37 
     38  Services.fog.testResetFOG();
     39 });
     40 
     41 add_task(async function testPanelInfoMessage() {
     42  let tab = await BrowserTestUtils.openNewForegroundTab(
     43    gBrowser,
     44    TRACKING_PAGE
     45  );
     46 
     47  await openProtectionsPanel();
     48 
     49  await TestUtils.waitForCondition(() => {
     50    return gProtectionsHandler._protectionsPopup.hasAttribute(
     51      "infoMessageShowing"
     52    );
     53  });
     54 
     55  // Test that the info message is displayed when the panel opens
     56  let container = document.getElementById("info-message-container");
     57  let message = document.getElementById("protections-popup-message");
     58  let learnMoreLink = document.querySelector(
     59    "#info-message-container .text-link"
     60  );
     61 
     62  // Check the visibility of the info message.
     63  ok(
     64    BrowserTestUtils.isVisible(container),
     65    "The message container should exist."
     66  );
     67 
     68  ok(BrowserTestUtils.isVisible(message), "The message should be visible.");
     69 
     70  ok(BrowserTestUtils.isVisible(learnMoreLink), "The link should be visible.");
     71 
     72  // Check telemetry for the info message
     73  let messageEvents =
     74    Glean.securityUiProtectionspopup.openProtectionspopupCfr.testGetValue();
     75  is(
     76    messageEvents.length,
     77    1,
     78    "recorded telemetry for showing the info message"
     79  );
     80  //Clear telemetry from this test so that the next one doesn't fall over
     81  Services.telemetry.clearEvents();
     82  BrowserTestUtils.removeTab(tab);
     83 });