tor-browser

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

browser_dbg-search-file-retains-query.js (2580B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 "use strict";
      6 
      7 // Tests the search bar retains previous query on re-opening.
      8 add_task(async function testSearchRetainsPreviousQuery() {
      9  const dbg = await initDebugger("doc-scripts.html", "simple1.js");
     10  const {
     11    selectors: { getActiveSearch },
     12  } = dbg;
     13  await selectSource(dbg, "simple1.js");
     14 
     15  // Open search bar
     16  pressKey(dbg, "fileSearch");
     17  await waitFor(() => getActiveSearch() === "file");
     18  is(getActiveSearch(), "file");
     19 
     20  // Type a search query
     21  type(dbg, "con");
     22  await waitForSearchState(dbg);
     23  is(findElement(dbg, "fileSearchInput").value, "con");
     24 
     25  // Close the search bar
     26  pressKey(dbg, "Escape");
     27  await waitFor(() => getActiveSearch() === null);
     28  is(getActiveSearch(), null);
     29 
     30  // Re-open search bar
     31  pressKey(dbg, "fileSearch");
     32  await waitFor(() => getActiveSearch() === "file");
     33  is(getActiveSearch(), "file");
     34 
     35  // Test for the retained query
     36  is(findElement(dbg, "fileSearchInput").value, "con");
     37 });
     38 
     39 // Tests that the search results are updated when switching between sources
     40 add_task(async function testSearchUpdatesResultsOnSourceChanges() {
     41  const dbg = await initDebugger("doc-scripts.html", "simple1.js", "long.js");
     42  const {
     43    selectors: { getActiveSearch },
     44  } = dbg;
     45 
     46  await selectSource(dbg, "simple1.js");
     47 
     48  // Open search bar
     49  pressKey(dbg, "fileSearch");
     50  await waitFor(() => getActiveSearch() === "file");
     51  is(getActiveSearch(), "file");
     52 
     53  // Type a search query
     54  const searchQuery = "this";
     55  type(dbg, searchQuery);
     56  await waitForSearchState(dbg);
     57 
     58  await waitUntil(
     59    () => findElement(dbg, "fileSearchSummary").innerText !== "No results found"
     60  );
     61 
     62  is(
     63    findElement(dbg, "fileSearchSummary").innerText,
     64    "1 of 3 results",
     65    `There are 3 results found for search query "${searchQuery}" in simple1.js`
     66  );
     67  is(
     68    findElement(dbg, "fileSearchInput").value,
     69    searchQuery,
     70    `The search input value matches the search query "${searchQuery}"`
     71  );
     72 
     73  info("Switch to long.js");
     74  await selectSource(dbg, "long.js");
     75 
     76  await waitUntil(
     77    () => findElement(dbg, "fileSearchSummary")?.innerText == "1 of 23 results"
     78  );
     79  ok(
     80    true,
     81    `There are 23 results found for search query "${searchQuery}" in long.js`
     82  );
     83  is(
     84    findElement(dbg, "fileSearchInput").value,
     85    searchQuery,
     86    `The search input value still matches the search query "${searchQuery}"`
     87  );
     88 });