tor-browser

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

browser_markup_search_html.js (4611B)


      1 "use strict";
      2 
      3 // Test search html navigation using keys <ENTER> and <SHIFT>+<ENTER> as well
      4 // as using buttons <prev> and <next> updates the search label.
      5 
      6 const TEST_URL = URL_ROOT + "doc_markup_update-on-navigtion_1.html";
      7 
      8 const STATES = {
      9  keys: [
     10    { shiftKey: false, expectedValue: "1 of 3" },
     11    { shiftKey: false, expectedValue: "2 of 3" },
     12    { shiftKey: true, expectedValue: "1 of 3" },
     13    { shiftKey: true, expectedValue: "3 of 3" },
     14  ],
     15  mouse: [
     16    { next: true, expectedValue: "1 of 3" },
     17    { next: true, expectedValue: "2 of 3" },
     18    { next: false, expectedValue: "1 of 3" },
     19    { next: false, expectedValue: "3 of 3" },
     20  ],
     21 };
     22 
     23 add_task(async function () {
     24  const { inspector } = await openInspectorForURL(TEST_URL);
     25 
     26  info("Starting test...");
     27  const {
     28    searchBox,
     29    searchResultsLabel,
     30    searchPrevButton,
     31    searchNextButton,
     32    searchClearButton,
     33    search,
     34    searchResultsContainer,
     35    searchNavigationContainer,
     36  } = inspector;
     37 
     38  await focusSearchBoxUsingShortcut(inspector.panelWin);
     39 
     40  info("Checking search label and navigation buttons are not displayed");
     41  ok(
     42    searchResultsContainer.hidden,
     43    "The search label and navigation buttons are not visible"
     44  );
     45 
     46  info("Searching for 'o'");
     47  searchBox.value = "o";
     48 
     49  info("Navigating using keys");
     50  await navigateUsingKeys(inspector, searchResultsLabel);
     51 
     52  info("Navigating using mouse");
     53  await navigateUsingMouse(
     54    inspector,
     55    searchResultsLabel,
     56    searchNextButton,
     57    searchPrevButton
     58  );
     59 
     60  info("Clearing the text");
     61  await clearText(
     62    search,
     63    searchClearButton,
     64    searchResultsLabel,
     65    searchResultsContainer
     66  );
     67 
     68  info("Searching for 'mozilla' (not-present)");
     69  searchBox.value = "mozilla";
     70  await findNotPresentString(
     71    inspector,
     72    searchResultsLabel,
     73    searchResultsContainer,
     74    searchNavigationContainer
     75  );
     76 });
     77 
     78 async function navigateUsingKeys(inspector, searchResultsLabel) {
     79  for (const { expectedValue, shiftKey } of STATES.keys) {
     80    const onSearchProcessingDone =
     81      inspector.searchSuggestions.once("processing-done");
     82    const onSearchResult = inspector.search.once("search-result");
     83 
     84    info(`Pressing ${shiftKey ? "<SHIFT>+" : ""}<ENTER> key.`);
     85    EventUtils.synthesizeKey("VK_RETURN", { shiftKey }, inspector.panelWin);
     86 
     87    info("Waiting for results");
     88    await onSearchResult;
     89 
     90    info("Waiting for search query to complete");
     91    await onSearchProcessingDone;
     92 
     93    is(
     94      searchResultsLabel.textContent,
     95      expectedValue,
     96      "The search label shows correct values."
     97    );
     98  }
     99 }
    100 
    101 async function navigateUsingMouse(
    102  inspector,
    103  searchResultsLabel,
    104  nextBtn,
    105  prevBtn
    106 ) {
    107  for (const { next, expectedValue } of STATES.mouse) {
    108    const onSearchResult = inspector.search.once("search-result");
    109 
    110    info(`Clicking ${next ? "<NEXT>" : "<PREVIOUS>"} button`);
    111    EventUtils.sendMouseEvent({ type: "click" }, next ? nextBtn : prevBtn);
    112 
    113    info("Waiting for results");
    114    await onSearchResult;
    115 
    116    is(
    117      searchResultsLabel.textContent,
    118      expectedValue,
    119      "The search label shows correct values."
    120    );
    121  }
    122 }
    123 
    124 async function clearText(
    125  search,
    126  searchClearButton,
    127  searchResultsLabel,
    128  searchResultsContainer
    129 ) {
    130  const onSearchCleared = search.once("search-cleared");
    131  EventUtils.sendMouseEvent({ type: "click" }, searchClearButton);
    132 
    133  info("Waiting for search to clear");
    134  await onSearchCleared;
    135 
    136  is(
    137    searchResultsLabel.textContent,
    138    "",
    139    "The search label shows correct value."
    140  );
    141 
    142  info("Checking search label and navigation buttons are not displayed");
    143  ok(
    144    searchResultsContainer.hidden,
    145    "The search label and navigation buttons are not visible"
    146  );
    147 }
    148 
    149 async function findNotPresentString(
    150  inspector,
    151  searchResultsLabel,
    152  searchResultsContainer,
    153  searchNavigationContainer
    154 ) {
    155  const onSearchProcessingDone =
    156    inspector.searchSuggestions.once("processing-done");
    157  const onSearchResult = inspector.search.once("search-result");
    158 
    159  info(`Pressing <ENTER> key`);
    160  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
    161 
    162  info("Waiting for results");
    163  await onSearchResult;
    164 
    165  info("Waiting for search query to complete");
    166  await onSearchProcessingDone;
    167 
    168  is(
    169    searchResultsLabel.textContent,
    170    "No matches",
    171    "The search label shows correct values."
    172  );
    173 
    174  info("Checking search label is displayed");
    175  ok(!searchResultsContainer.hidden, "The search label is visible");
    176  info("Checking navigation buttons are not displayed");
    177  ok(
    178    searchNavigationContainer.hidden,
    179    "The navigation buttons are not visible"
    180  );
    181 }