tor-browser

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

browser_compatibility_event_top-level-target-change.js (2524B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test the issues after navigating to another page.
      7 
      8 const TEST_DATA_ISSUES = {
      9  uri: `
     10    <style>
     11    body {
     12      overflow-anchor: auto;
     13    }
     14    div {
     15      user-select: auto;
     16    }
     17    </style>
     18    <body>
     19      <div>test</div>
     20    </body>
     21  `,
     22  expectedIssuesOnSelected: [
     23    {
     24      property: "overflow-anchor",
     25      url: "https://developer.mozilla.org/docs/Web/CSS/Reference/Properties/overflow-anchor",
     26    },
     27  ],
     28  expectedIssuesOnAll: [
     29    {
     30      property: "overflow-anchor",
     31      url: "https://developer.mozilla.org/docs/Web/CSS/Reference/Properties/overflow-anchor",
     32    },
     33    {
     34      property: "user-select",
     35      url: "https://developer.mozilla.org/docs/Web/CSS/Reference/Properties/user-select",
     36    },
     37  ],
     38 };
     39 
     40 const TEST_DATA_NO_ISSUES = {
     41  uri: "<body></body>",
     42  expectedIssuesOnSelected: [],
     43  expectedIssuesOnAll: [],
     44 };
     45 
     46 add_task(async function () {
     47  const tab = await addTab(
     48    "data:text/html;charset=utf-8," + encodeURIComponent(TEST_DATA_ISSUES.uri)
     49  );
     50 
     51  const { allElementsPane, inspector, selectedElementPane } =
     52    await openCompatibilityView();
     53 
     54  info("Check issues at initial");
     55  await assertIssues(selectedElementPane, allElementsPane, TEST_DATA_ISSUES);
     56 
     57  info("Navigate to next uri that has no issues");
     58  await navigateTo(TEST_DATA_NO_ISSUES.uri, tab, inspector);
     59  info("Check issues after navigating");
     60  await assertIssues(selectedElementPane, allElementsPane, TEST_DATA_NO_ISSUES);
     61 
     62  info("Revert the uri");
     63  await navigateTo(TEST_DATA_ISSUES.uri, tab, inspector);
     64  info("Check issues after reverting");
     65  await assertIssues(selectedElementPane, allElementsPane, TEST_DATA_ISSUES);
     66 });
     67 
     68 async function assertIssues(
     69  selectedElementPane,
     70  allElementsPane,
     71  { expectedIssuesOnSelected, expectedIssuesOnAll }
     72 ) {
     73  await assertIssueList(selectedElementPane, expectedIssuesOnSelected);
     74  await assertIssueList(allElementsPane, expectedIssuesOnAll);
     75 }
     76 
     77 async function navigateTo(uri, tab, { store }) {
     78  uri = "data:text/html;charset=utf-8," + encodeURIComponent(uri);
     79  const onSelectedNodeUpdated = waitForUpdateSelectedNodeAction(store);
     80  const onTopLevelTargetUpdated = waitForUpdateTopLevelTargetAction(store);
     81  const onLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
     82  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, uri);
     83  await Promise.all([onLoaded, onSelectedNodeUpdated, onTopLevelTargetUpdated]);
     84 }