tor-browser

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

browser_inspector_breadcrumbs_keybinding.js (2270B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that the breadcrumbs keybindings work.
      6 
      7 const TEST_URI = URL_ROOT + "doc_inspector_breadcrumbs.html";
      8 const TEST_DATA = [
      9  {
     10    desc: "Pressing left should select the parent <body>",
     11    key: "KEY_ArrowLeft",
     12    newSelection: "body",
     13  },
     14  {
     15    desc: "Pressing left again should select the parent <html>",
     16    key: "KEY_ArrowLeft",
     17    newSelection: "html",
     18  },
     19  {
     20    desc: "Pressing left again should stay on <html>, it's the first element",
     21    key: "KEY_ArrowLeft",
     22    newSelection: "html",
     23  },
     24  {
     25    desc: "Pressing right should go to <body>",
     26    key: "KEY_ArrowRight",
     27    newSelection: "body",
     28  },
     29  {
     30    desc: "Pressing right again should go to #i2",
     31    key: "KEY_ArrowRight",
     32    newSelection: "#i2",
     33  },
     34  {
     35    desc: "Pressing right again should stay on #i2, it's the last element",
     36    key: "KEY_ArrowRight",
     37    newSelection: "#i2",
     38  },
     39 ];
     40 
     41 add_task(async function () {
     42  const { inspector } = await openInspectorForURL(TEST_URI);
     43 
     44  info("Selecting the test node");
     45  await selectNode("#i2", inspector);
     46 
     47  info("Clicking on the corresponding breadcrumbs node to focus it");
     48  const container = inspector.panelDoc.getElementById("inspector-breadcrumbs");
     49 
     50  const button = container.querySelector(`button[aria-pressed="true"]`);
     51  button.click();
     52 
     53  let currentSelection = "#id2";
     54  for (const { desc, key, newSelection } of TEST_DATA) {
     55    info(desc);
     56 
     57    // If the selection will change, wait for the breadcrumb to update,
     58    // otherwise continue.
     59    let onUpdated = null;
     60    if (newSelection !== currentSelection) {
     61      info("Expecting a new node to be selected");
     62      onUpdated = inspector.once("breadcrumbs-updated");
     63    }
     64 
     65    EventUtils.synthesizeKey(key);
     66    await onUpdated;
     67 
     68    const newNodeFront = await getNodeFront(newSelection, inspector);
     69    is(
     70      newNodeFront,
     71      inspector.selection.nodeFront,
     72      "The current selection is correct"
     73    );
     74    is(
     75      container.getAttribute("aria-activedescendant"),
     76      container.querySelector(`button[aria-pressed="true"]`).id,
     77      "aria-activedescendant is set correctly"
     78    );
     79 
     80    currentSelection = newSelection;
     81  }
     82 });