tor-browser

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

browser_inspector_search-07.js (1718B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that searching for classes on SVG elements does work (see bug 1219920).
      6 
      7 const TEST_URL = URL_ROOT + "doc_inspector_search-svg.html";
      8 
      9 // An array of (key, suggestions) pairs where key is a key to press and
     10 // suggestions is an array of suggestions that should be shown in the popup.
     11 const TEST_DATA = [
     12  {
     13    key: "c",
     14    suggestions: ["circle", "clipPath", ".class1", ".class2"],
     15  },
     16  {
     17    key: "VK_BACK_SPACE",
     18    suggestions: [],
     19  },
     20  {
     21    key: ".",
     22    suggestions: [".class1", ".class2"],
     23  },
     24 ];
     25 
     26 add_task(async function () {
     27  const { inspector } = await openInspectorForURL(TEST_URL);
     28  const { searchBox } = inspector;
     29  const popup = inspector.searchSuggestions.searchPopup;
     30 
     31  await focusSearchBoxUsingShortcut(inspector.panelWin);
     32 
     33  for (const { key, suggestions } of TEST_DATA) {
     34    info("Pressing " + key + " to get " + suggestions);
     35 
     36    const command = once(searchBox, "input");
     37    const onSearchProcessingDone =
     38      inspector.searchSuggestions.once("processing-done");
     39    EventUtils.synthesizeKey(key, {}, inspector.panelWin);
     40    await command;
     41 
     42    info("Waiting for search query to complete and getting the suggestions");
     43    await onSearchProcessingDone;
     44    const actualSuggestions = popup.getItems();
     45 
     46    is(
     47      popup.isOpen ? actualSuggestions.length : 0,
     48      suggestions.length,
     49      "There are expected number of suggestions."
     50    );
     51 
     52    for (let i = 0; i < suggestions.length; i++) {
     53      is(
     54        actualSuggestions[i].label,
     55        suggestions[i],
     56        "The suggestion at " + i + "th index is correct."
     57      );
     58    }
     59  }
     60 });