tor-browser

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

browser_contextmenu_cross_boundary_selection.js (2015B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const PAGE = `
      5  data:text/html,
      6  <div>OuterText<div>
      7  <div id="host">
      8    <template shadowrootmode="open">
      9      <span id="innerText">InnerText</span>
     10    </template>
     11  </div>
     12  `;
     13 
     14 add_setup(async function () {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [["test.wait300msAfterTabSwitch", true]],
     17  });
     18 });
     19 
     20 /**
     21 * Tests that right click on a cross boundary selection shows the context menu
     22 */
     23 add_task(async function () {
     24  await SpecialPowers.pushPrefEnv({
     25    set: [["dom.shadowdom.selection_across_boundary.enabled", true]],
     26  });
     27  await BrowserTestUtils.withNewTab(
     28    {
     29      gBrowser,
     30      url: PAGE,
     31    },
     32    async function (browser) {
     33      let contextMenu = document.getElementById("contentAreaContextMenu");
     34      let awaitPopupShown = BrowserTestUtils.waitForEvent(
     35        contextMenu,
     36        "popupshown"
     37      );
     38 
     39      let awaitPopupHidden = BrowserTestUtils.waitForEvent(
     40        contextMenu,
     41        "popuphidden"
     42      );
     43 
     44      await SpecialPowers.spawn(browser, [], () => {
     45        let host = content.document.getElementById("host");
     46        content.getSelection().setBaseAndExtent(
     47          content.document.body,
     48          0,
     49          host.shadowRoot.getElementById("innerText").firstChild,
     50          3 // Only select the first three characters of the inner text
     51        );
     52      });
     53 
     54      await BrowserTestUtils.synthesizeMouseAtCenter(
     55        "div", // Click on the div for OuterText
     56        {
     57          type: "contextmenu",
     58          button: 2,
     59        },
     60        browser
     61      );
     62 
     63      await awaitPopupShown;
     64 
     65      const allVisibleMenuItems = Array.from(contextMenu.children)
     66        .filter(elem => {
     67          return !elem.hidden;
     68        })
     69        .map(elem => elem.id);
     70 
     71      ok(
     72        allVisibleMenuItems.includes("context-copy"),
     73        "copy button should exist"
     74      );
     75 
     76      contextMenu.hidePopup();
     77      await awaitPopupHidden;
     78    }
     79  );
     80 });