tor-browser

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

browser_inspector_search-05.js (3717B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Testing that when search results contain suggestions for nodes in other
      6 // frames, selecting these suggestions actually selects the right nodes.
      7 
      8 requestLongerTimeout(2);
      9 
     10 add_task(async function () {
     11  const { inspector } = await openInspectorForURL(
     12    `${URL_ROOT_ORG_SSL}doc_inspector_search-iframes.html`
     13  );
     14 
     15  info("Focus the search box");
     16  await focusSearchBoxUsingShortcut(inspector.panelWin);
     17 
     18  info("Enter # to search for all ids");
     19  let processingDone = once(inspector.searchSuggestions, "processing-done");
     20  EventUtils.synthesizeKey("#", {}, inspector.panelWin);
     21 
     22  info("Wait for search query to complete");
     23  await processingDone;
     24 
     25  info("Press tab to fill the search input with the first suggestion");
     26  processingDone = once(inspector.searchSuggestions, "processing-done");
     27  EventUtils.synthesizeKey("VK_TAB", {}, inspector.panelWin);
     28  await processingDone;
     29 
     30  info("Press enter and expect a new selection");
     31  let onSelect = inspector.once("inspector-updated");
     32  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
     33  await onSelect;
     34 
     35  await checkCorrectButton(inspector, ["#iframe-1"]);
     36 
     37  info("Press enter to cycle through multiple nodes matching this suggestion");
     38  onSelect = inspector.once("inspector-updated");
     39  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
     40  await onSelect;
     41 
     42  await checkCorrectButton(inspector, ["#iframe-2"]);
     43 
     44  info("Press enter to cycle through multiple nodes matching this suggestion");
     45  onSelect = inspector.once("inspector-updated");
     46  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
     47  await onSelect;
     48 
     49  await checkCorrectButton(inspector, ["#iframe-3"]);
     50 
     51  info("Press enter to cycle through multiple nodes matching this suggestion");
     52  onSelect = inspector.once("inspector-updated");
     53  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
     54  await onSelect;
     55 
     56  await checkCorrectButton(inspector, ["#iframe-3", "#iframe-4"]);
     57 
     58  info("Press enter to cycle through multiple nodes matching this suggestion");
     59  onSelect = inspector.once("inspector-updated");
     60  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
     61  await onSelect;
     62 
     63  await checkCorrectButton(inspector, ["#iframe-1"]);
     64 });
     65 
     66 const checkCorrectButton = async function (inspector, frameSelector) {
     67  const nodeFrontInfo = await getSelectedNodeFrontInfo(inspector);
     68  is(nodeFrontInfo.nodeFront.id, "b1", "The selected node is #b1");
     69  is(
     70    nodeFrontInfo.nodeFront.tagName.toLowerCase(),
     71    "button",
     72    "The selected node is <button>"
     73  );
     74 
     75  const iframe = await getNodeFrontInFrames(frameSelector, inspector);
     76  const expectedDocument = (await iframe.walkerFront.children(iframe)).nodes[0];
     77 
     78  is(
     79    nodeFrontInfo.document,
     80    expectedDocument,
     81    "The selected node is in " + frameSelector
     82  );
     83 };
     84 /**
     85 * Gets the currently selected nodefront. It also finds the
     86 * document node which contains the node.
     87 *
     88 * @param   {object} inspector
     89 * @returns {object}
     90 *          nodeFront - The currently selected nodeFront
     91 *          document - The document which contains the node.
     92 */
     93 async function getSelectedNodeFrontInfo(inspector) {
     94  const { selection, commands } = inspector;
     95 
     96  const nodeFront = selection.nodeFront;
     97  const inspectors = await commands.inspectorCommand.getAllInspectorFronts();
     98 
     99  for (let i = 0; i < inspectors.length; i++) {
    100    const inspectorFront = inspectors[i];
    101    if (inspectorFront.walker == nodeFront.walkerFront) {
    102      const document = await inspectorFront.walker.document(nodeFront);
    103      return { nodeFront, document };
    104    }
    105  }
    106  return null;
    107 }