tor-browser

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

browser_inspector_search-01.js (3336B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 requestLongerTimeout(2);
      6 
      7 // Test that searching for nodes in the search field actually selects those
      8 // nodes.
      9 
     10 const TEST_URL = URL_ROOT + "doc_inspector_search.html";
     11 
     12 // The various states of the inspector: [key, id, isValid]
     13 // [
     14 //  what key to press,
     15 //  what id should be selected after the keypress,
     16 //  is the searched text valid selector
     17 // ]
     18 const KEY_STATES = [
     19  ["#", "b1", true], // #
     20  ["d", "b1", true], // #d
     21  ["1", "b1", true], // #d1
     22  ["VK_RETURN", "d1", true], // #d1
     23  ["VK_BACK_SPACE", "d1", true], // #d
     24  ["2", "d1", true], // #d2
     25  ["VK_RETURN", "d2", true], // #d2
     26  ["2", "d2", true], // #d22
     27  ["VK_RETURN", "d2", false], // #d22
     28  ["VK_BACK_SPACE", "d2", false], // #d2
     29  ["VK_RETURN", "d2", true], // #d2
     30  ["VK_BACK_SPACE", "d2", true], // #d
     31  ["1", "d2", true], // #d1
     32  ["VK_RETURN", "d1", true], // #d1
     33  ["VK_BACK_SPACE", "d1", true], // #d
     34  ["VK_BACK_SPACE", "d1", true], // #
     35  ["VK_BACK_SPACE", "d1", true], //
     36  ["d", "d1", true], // d
     37  ["i", "d1", true], // di
     38  ["v", "d1", true], // div
     39  [".", "d1", true], // div.
     40  ["c", "d1", true], // div.c
     41  ["VK_UP", "d1", true], // div.c1
     42  ["VK_TAB", "d1", true], // div.c1
     43  ["VK_RETURN", "d2", true], // div.c1
     44  ["VK_BACK_SPACE", "d2", true], // div.c
     45  ["VK_BACK_SPACE", "d2", true], // div.
     46  ["VK_BACK_SPACE", "d2", true], // div
     47  ["VK_BACK_SPACE", "d2", true], // di
     48  ["VK_BACK_SPACE", "d2", true], // d
     49  ["VK_BACK_SPACE", "d2", true], //
     50  [".", "d2", true], // .
     51  ["c", "d2", true], // .c
     52  ["1", "d2", true], // .c1
     53  ["VK_RETURN", "d2", true], // .c1
     54  ["VK_RETURN", "s2", true], // .c1
     55  ["VK_RETURN", "p1", true], // .c1
     56  ["P", "p1", true], // .c1P
     57  ["VK_RETURN", "p1", false], // .c1P
     58 ];
     59 
     60 add_task(async function () {
     61  const { inspector } = await openInspectorForURL(TEST_URL);
     62  const { searchBox } = inspector;
     63 
     64  await selectNode("#b1", inspector);
     65  await focusSearchBoxUsingShortcut(inspector.panelWin);
     66 
     67  let index = 0;
     68  for (const [key, id, isValid] of KEY_STATES) {
     69    const promises = [];
     70    info(index + ": Pressing key " + key + " to get id " + id + ".");
     71 
     72    info("Waiting for current key press processing to complete");
     73    promises.push(inspector.searchSuggestions.once("processing-done"));
     74 
     75    if (key === "VK_RETURN") {
     76      info("Waiting for " + (isValid ? "NO " : "") + "results");
     77      promises.push(inspector.search.once("search-result"));
     78    }
     79 
     80    info("Waiting for search query to complete");
     81    promises.push(inspector.searchSuggestions.once("processing-done"));
     82 
     83    EventUtils.synthesizeKey(key, {}, inspector.panelWin);
     84 
     85    await Promise.all(promises);
     86    info(
     87      "The keypress press process, any possible search results and the search query are complete."
     88    );
     89 
     90    info(
     91      inspector.selection.nodeFront.id +
     92        " is selected with text " +
     93        searchBox.value
     94    );
     95    const nodeFront = await getNodeFront("#" + id, inspector);
     96    is(
     97      inspector.selection.nodeFront,
     98      nodeFront,
     99      "Correct node is selected for state " + index
    100    );
    101 
    102    is(
    103      !searchBox.parentNode.classList.contains("devtools-searchbox-no-match"),
    104      isValid,
    105      "Correct searchbox result state for state " + index
    106    );
    107 
    108    index++;
    109  }
    110 });