tor-browser

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

browser_inspector_search-04.js (2838B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Testing that searching for elements inside iframes does work.
      6 
      7 const IFRAME_SRC = "doc_inspector_search.html";
      8 const TEST_URL =
      9  "data:text/html;charset=utf-8," +
     10  '<div class="c1 c2">' +
     11  '<iframe src="' +
     12  URL_ROOT +
     13  IFRAME_SRC +
     14  '"></iframe>' +
     15  '<iframe src="' +
     16  URL_ROOT +
     17  IFRAME_SRC +
     18  '"></iframe>';
     19 
     20 // An array of (key, suggestions) pairs where key is a key to press and
     21 // suggestions is an array of suggestions that should be shown in the popup.
     22 // Suggestion is an object with label of the entry and optional count
     23 // (defaults to 1)
     24 var TEST_DATA = [
     25  {
     26    key: "d",
     27    suggestions: [{ label: "div" }, { label: "#d1" }, { label: "#d2" }],
     28  },
     29  {
     30    key: "i",
     31    suggestions: [{ label: "div" }],
     32  },
     33  {
     34    key: "v",
     35    suggestions: [],
     36  },
     37  {
     38    key: "VK_BACK_SPACE",
     39    suggestions: [{ label: "div" }],
     40  },
     41  {
     42    key: "VK_BACK_SPACE",
     43    suggestions: [{ label: "div" }, { label: "#d1" }, { label: "#d2" }],
     44  },
     45  {
     46    key: "VK_BACK_SPACE",
     47    suggestions: [],
     48  },
     49  {
     50    key: ".",
     51    suggestions: [{ label: ".c1" }, { label: ".c2" }],
     52  },
     53  {
     54    key: "VK_BACK_SPACE",
     55    suggestions: [],
     56  },
     57  {
     58    key: "#",
     59    suggestions: [
     60      { label: "#b1" },
     61      { label: "#d1" },
     62      { label: "#d2" },
     63      { label: "#p1" },
     64      { label: "#p2" },
     65      { label: "#p3" },
     66      { label: "#root" },
     67      { label: "#s1" },
     68      { label: "#s2" },
     69    ],
     70  },
     71 ];
     72 
     73 add_task(async function () {
     74  const { inspector } = await openInspectorForURL(TEST_URL);
     75  const searchBox = inspector.searchBox;
     76  const popup = inspector.searchSuggestions.searchPopup;
     77 
     78  await focusSearchBoxUsingShortcut(inspector.panelWin);
     79 
     80  for (const { key, suggestions } of TEST_DATA) {
     81    info("Pressing " + key + " to get " + formatSuggestions(suggestions));
     82 
     83    const command = once(searchBox, "input");
     84    const onSearchProcessingDone =
     85      inspector.searchSuggestions.once("processing-done");
     86    EventUtils.synthesizeKey(key, {}, inspector.panelWin);
     87    await command;
     88 
     89    info("Waiting for search query to complete");
     90    await onSearchProcessingDone;
     91 
     92    info(
     93      "Query completed. Performing checks for input '" + searchBox.value + "'"
     94    );
     95    const actualSuggestions = popup.getItems();
     96 
     97    is(
     98      popup.isOpen ? actualSuggestions.length : 0,
     99      suggestions.length,
    100      "There are expected number of suggestions."
    101    );
    102 
    103    for (let i = 0; i < suggestions.length; i++) {
    104      is(
    105        actualSuggestions[i].label,
    106        suggestions[i].label,
    107        "The suggestion at " + i + "th index is correct."
    108      );
    109    }
    110  }
    111 });
    112 
    113 function formatSuggestions(suggestions) {
    114  return "[" + suggestions.map(s => "'" + s.label + "'").join(", ") + "]";
    115 }