tor-browser

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

browser_markup_keybindings_04.js (2089B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 requestLongerTimeout(2);
      7 
      8 // Tests that selecting a node using the browser context menu (inspect element)
      9 // or the element picker focuses that node so that the keyboard can be used
     10 // immediately.
     11 
     12 const TEST_URL = "data:text/html;charset=utf8,<div>test element</div>";
     13 
     14 add_task(async function () {
     15  const { inspector } = await openInspectorForURL(TEST_URL);
     16 
     17  info("Select the test node with the browser ctx menu");
     18  await clickOnInspectMenuItem("div");
     19  assertNodeSelected(inspector, "div");
     20 
     21  info(
     22    "Press arrowUp to focus <body> " +
     23      "(which works if the node was focused properly)"
     24  );
     25  await selectPreviousNodeWithArrowUp(inspector);
     26  assertNodeSelected(inspector, "body");
     27 
     28  info("Select the test node with the element picker");
     29  await selectWithElementPicker(inspector);
     30  assertNodeSelected(inspector, "div");
     31 
     32  info(
     33    "Press arrowUp to focus <body> " +
     34      "(which works if the node was focused properly)"
     35  );
     36  await selectPreviousNodeWithArrowUp(inspector);
     37  assertNodeSelected(inspector, "body");
     38 });
     39 
     40 function assertNodeSelected(inspector, tagName) {
     41  is(
     42    inspector.selection.nodeFront.tagName.toLowerCase(),
     43    tagName,
     44    `The <${tagName}> node is selected`
     45  );
     46 }
     47 
     48 function selectPreviousNodeWithArrowUp(inspector) {
     49  const { waitForHighlighterTypeShown } = getHighlighterTestHelpers(inspector);
     50  const onNodeHighlighted = waitForHighlighterTypeShown(
     51    inspector.highlighters.TYPES.BOXMODEL
     52  );
     53  const onUpdated = inspector.once("inspector-updated");
     54  EventUtils.synthesizeKey("KEY_ArrowUp");
     55  return Promise.all([onUpdated, onNodeHighlighted]);
     56 }
     57 
     58 async function selectWithElementPicker(inspector) {
     59  await startPicker(inspector.toolbox);
     60 
     61  await safeSynthesizeMouseEventAtCenterInContentPage(
     62    "div",
     63    {
     64      type: "mousemove",
     65    },
     66    gBrowser.selectedBrowser
     67  );
     68 
     69  BrowserTestUtils.synthesizeKey("KEY_Enter", {}, gBrowser.selectedBrowser);
     70  await inspector.once("inspector-updated");
     71 }