tor-browser

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

browser_compatibility_settings.js (3208B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test whether settings page works.
      7 
      8 const TEST_URI = `
      9  <style>
     10  body {
     11    text-size-adjust: none;
     12  }
     13  div {
     14    text-size-adjust: none;
     15  }
     16  </style>
     17  <body><div></div></body>
     18 `;
     19 
     20 const {
     21  COMPATIBILITY_UPDATE_TARGET_BROWSERS_COMPLETE,
     22 } = require("resource://devtools/client/inspector/compatibility/actions/index.js");
     23 
     24 add_task(async function () {
     25  registerCleanupFunction(() => {
     26    Services.prefs.clearUserPref(
     27      "devtools.inspector.compatibility.target-browsers"
     28    );
     29  });
     30 
     31  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     32  const { inspector, panel } = await openCompatibilityView();
     33  const { store } = inspector;
     34 
     35  info("Check initial state");
     36  ok(
     37    panel.querySelector(`.compatibility-browser-icon__image[src*="firefox"]`),
     38    "Firefox browsers are the target"
     39  );
     40 
     41  info("Make Firefox browsers out of target");
     42  await updateTargetBrowsers(panel, store, id => !id.includes("firefox"));
     43  ok(
     44    !panel.querySelector(`.compatibility-browser-icon__image[src*="firefox"]`),
     45    "Firefox browsers are not the target"
     46  );
     47 
     48  info("Make all browsers out of target");
     49  await updateTargetBrowsers(panel, store, () => false);
     50  ok(
     51    !panel.querySelector(".compatibility-browser-icon__image"),
     52    "No browsers are the target"
     53  );
     54 
     55  info("Make Firefox browsers target");
     56  await updateTargetBrowsers(panel, store, id => id.includes("firefox"));
     57  ok(
     58    panel.querySelector(`.compatibility-browser-icon__image[src*="firefox"]`),
     59    "Firefox browsers are the target now"
     60  );
     61 });
     62 
     63 async function updateTargetBrowsers(panel, store, isTargetBrowserFunc) {
     64  info("Open settings pane");
     65  const settingsButton = panel.querySelector(".compatibility-footer__button");
     66  settingsButton.click();
     67  await waitUntil(() => panel.querySelector(".compatibility-settings"));
     68 
     69  const browsers = [
     70    ...new Set(
     71      Array.from(panel.querySelectorAll("[data-id]")).map(el =>
     72        el.getAttribute("data-id")
     73      )
     74    ),
     75  ];
     76  Assert.deepEqual(
     77    // Filter out IE, to be removed in an upcoming browser compat data sync.
     78    // TODO: Remove the filter once D150961 lands. see Bug 1778009
     79    browsers.filter(browser => browser != "ie"),
     80    [
     81      "chrome",
     82      "chrome_android",
     83      "edge",
     84      "firefox",
     85      "firefox_android",
     86      "safari",
     87      "safari_ios",
     88    ],
     89    "The expected browsers are displayed"
     90  );
     91 
     92  info("Change target browsers");
     93  const settingsPane = panel.querySelector(".compatibility-settings");
     94  for (const checkbox of settingsPane.querySelectorAll(
     95    ".compatibility-settings__target-browsers-item input"
     96  )) {
     97    if (checkbox.checked !== isTargetBrowserFunc(checkbox.id)) {
     98      // Need to click to toggle since the input is designed as controlled component.
     99      checkbox.click();
    100    }
    101  }
    102 
    103  info("Close settings pane");
    104  const onUpdated = waitForDispatch(
    105    store,
    106    COMPATIBILITY_UPDATE_TARGET_BROWSERS_COMPLETE
    107  );
    108  const closeButton = settingsPane.querySelector(
    109    ".compatibility-settings__header-button"
    110  );
    111  closeButton.click();
    112  await onUpdated;
    113 }