tor-browser

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

browser_toolbox_selectionchanged_event.js (1365B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const PAGE_URL = "data:text/html;charset=utf-8,<body><div></div></body>";
      7 
      8 add_task(async function () {
      9  const tab = await addTab(PAGE_URL);
     10  const toolbox = await openToolboxForTab(tab, "inspector", "bottom");
     11  const inspector = toolbox.getCurrentPanel();
     12 
     13  const root = await inspector.walker.getRootNode();
     14  const body = await inspector.walker.querySelector(root, "body");
     15  const node = await inspector.walker.querySelector(root, "div");
     16 
     17  is(inspector.selection.nodeFront, body, "Body is selected by default");
     18 
     19  // Listen to selection changed
     20  const onSelectionChanged = toolbox.once("selection-changed");
     21 
     22  info("Select the div and wait for the selection-changed event to be fired.");
     23  inspector.selection.setNodeFront(node, { reason: "browser-context-menu" });
     24 
     25  await onSelectionChanged;
     26 
     27  is(inspector.selection.nodeFront, node, "Div is now selected");
     28 
     29  // Listen to cleared selection changed
     30  const onClearSelectionChanged = toolbox.once("selection-changed");
     31 
     32  info(
     33    "Clear the selection and wait for the selection-changed event to be fired."
     34  );
     35  inspector.selection.setNodeFront(null);
     36 
     37  await onClearSelectionChanged;
     38 
     39  is(inspector.selection.nodeFront, null, "The selection is null as expected");
     40 });