tor-browser

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

browser_inspector_search-02.js (3571B)


      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 combining selectors using the inspector search
      6 // field produces correct suggestions.
      7 
      8 const TEST_URL = URL_ROOT + "doc_inspector_search-suggestions.html";
      9 
     10 // See head.js `checkMarkupSearchSuggestions` function
     11 const TEST_DATA = [
     12  {
     13    key: "d",
     14    value: "d",
     15    suggestions: ["div", "#d1", "#d2"],
     16  },
     17  {
     18    key: "i",
     19    value: "di",
     20    suggestions: ["div"],
     21  },
     22  {
     23    key: "v",
     24    value: "div",
     25    suggestions: [],
     26  },
     27  {
     28    key: " ",
     29    value: "div ",
     30    suggestions: ["div div", "div span"],
     31  },
     32  {
     33    key: ">",
     34    value: "div >",
     35    suggestions: ["div >div", "div >span"],
     36  },
     37  {
     38    key: "VK_BACK_SPACE",
     39    value: "div ",
     40    suggestions: ["div div", "div span"],
     41  },
     42  {
     43    key: "+",
     44    value: "div +",
     45    suggestions: ["div +span"],
     46  },
     47  {
     48    key: "VK_BACK_SPACE",
     49    value: "div ",
     50    suggestions: ["div div", "div span"],
     51  },
     52  {
     53    key: "VK_BACK_SPACE",
     54    value: "div",
     55    suggestions: [],
     56  },
     57  {
     58    key: "VK_BACK_SPACE",
     59    value: "di",
     60    suggestions: ["div"],
     61  },
     62  {
     63    key: "VK_BACK_SPACE",
     64    value: "d",
     65    suggestions: ["div", "#d1", "#d2"],
     66  },
     67  {
     68    key: "VK_BACK_SPACE",
     69    value: "",
     70    suggestions: [],
     71  },
     72  {
     73    key: "p",
     74    value: "p",
     75    suggestions: ["p", "#p1", "#p2", "#p3"],
     76  },
     77  {
     78    key: " ",
     79    value: "p ",
     80    suggestions: ["p strong"],
     81  },
     82  {
     83    key: "+",
     84    value: "p +",
     85    suggestions: ["p +button", "p +footer", "p +p"],
     86  },
     87  {
     88    key: "b",
     89    value: "p +b",
     90    suggestions: ["p +button"],
     91  },
     92  {
     93    key: "u",
     94    value: "p +bu",
     95    suggestions: ["p +button"],
     96  },
     97  {
     98    key: "t",
     99    value: "p +but",
    100    suggestions: ["p +button"],
    101  },
    102  {
    103    key: "t",
    104    value: "p +butt",
    105    suggestions: ["p +button"],
    106  },
    107  {
    108    key: "o",
    109    value: "p +butto",
    110    suggestions: ["p +button"],
    111  },
    112  {
    113    key: "n",
    114    value: "p +button",
    115    suggestions: [],
    116  },
    117  {
    118    key: "+",
    119    value: "p +button+",
    120    suggestions: ["p +button+p"],
    121  },
    122  {
    123    key: "VK_BACK_SPACE",
    124    value: "p +button",
    125    suggestions: [],
    126  },
    127  {
    128    key: "~",
    129    value: "p +button~",
    130    suggestions: ["p +button~footer", "p +button~p"],
    131  },
    132  {
    133    key: "f",
    134    value: "p +button~f",
    135    suggestions: ["p +button~footer"],
    136  },
    137 ];
    138 
    139 add_task(async function () {
    140  const { inspector } = await openInspectorForURL(TEST_URL);
    141  await checkMarkupSearchSuggestions(inspector, TEST_DATA);
    142 });
    143 
    144 add_task(async function testEscape() {
    145  const { inspector } = await openInspectorForURL(TEST_URL);
    146 
    147  // Get in a state where the suggestions popup is displayed
    148  await checkMarkupSearchSuggestions(inspector, [
    149    { key: "d", value: "d", suggestions: ["div", "#d1", "#d2"] },
    150  ]);
    151 
    152  const searchBox = inspector.searchBox;
    153  const popup = inspector.searchSuggestions.searchPopup;
    154 
    155  ok(popup.isOpen, `The suggestions popup is open`);
    156  is(searchBox.value, "d", "search input has expected value");
    157 
    158  info("Check that Esc closes the suggestions popup");
    159  const onPopupClose = popup.once("popup-closed");
    160  EventUtils.synthesizeKey("VK_ESCAPE", {}, inspector.panelWin);
    161  await onPopupClose;
    162  ok(!popup.isOpen, `The suggestions popup is closed`);
    163  is(searchBox.value, "d", "The search input value didn't changed");
    164 
    165  info("Check that Esc clears the input when the popup isn't opened");
    166  EventUtils.synthesizeKey("VK_ESCAPE", {}, inspector.panelWin);
    167  is(searchBox.value, "", "The search input was cleared");
    168 });