tor-browser

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

browser_net_basic-search.js (2796B)


      1 /* Any copyright is dedicated to the Public Domain.
      2  http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Test basic search functionality.
      8 * Search panel is visible and number of expected results are returned.
      9 */
     10 
     11 add_task(async function () {
     12  const { tab, monitor } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, {
     13    requestCount: 1,
     14  });
     15  info("Starting test... ");
     16 
     17  const { document, store, windowRequire } = monitor.panelWin;
     18 
     19  // Action should be processed synchronously in tests.
     20  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     21  store.dispatch(Actions.batchEnable(false));
     22 
     23  // Execute two XHRs (the same URL) and wait till it's finished.
     24  const URL = HTTPS_SEARCH_SJS + "?value=test";
     25  const wait = waitForNetworkEvents(monitor, 2);
     26 
     27  await SpecialPowers.spawn(tab.linkedBrowser, [URL], async function (url) {
     28    content.wrappedJSObject.performRequests(2, url);
     29  });
     30  await wait;
     31 
     32  const searchButton = document.querySelector(".devtools-search-icon");
     33  is(
     34    searchButton.getAttribute("aria-pressed"),
     35    "false",
     36    "The search toolbar button should not be highlighted"
     37  );
     38 
     39  // Open the Search panel
     40  searchButton.click();
     41 
     42  // Wait till the panel opens.
     43  await waitForDOMIfNeeded(document, ".search-panel");
     44 
     45  is(
     46    searchButton.getAttribute("aria-pressed"),
     47    "true",
     48    "The search toolbar button should now be highlighted"
     49  );
     50  is(
     51    document
     52      .querySelector(".requests-list-blocking-button")
     53      .getAttribute("aria-pressed"),
     54    "false",
     55    "The block toolbar button should not be highlighted"
     56  );
     57  is(
     58    document
     59      .querySelector(".devtools-http-custom-request-icon")
     60      .getAttribute("aria-pressed"),
     61    "false",
     62    "The custom request toolbar button should not be highlighted"
     63  );
     64 
     65  // Fill Filter input with text and check displayed messages.
     66  // The filter should be focused automatically.
     67  typeInNetmonitor("test", monitor);
     68  EventUtils.synthesizeKey("KEY_Enter");
     69 
     70  // Wait till there are two resources rendered in the results.
     71  await waitForDOMIfNeeded(
     72    document,
     73    ".search-panel-content .treeRow.resourceRow",
     74    2
     75  );
     76 
     77  // Click on the first resource to expand it
     78  AccessibilityUtils.setEnv({
     79    // Keyboard users use arrow keys to expand/collapse tree items.
     80    // Accessibility is handled on the container level.
     81    mustHaveAccessibleRule: false,
     82  });
     83  EventUtils.sendMouseEvent(
     84    { type: "click" },
     85    document.querySelector(".search-panel-content .treeRow .treeIcon")
     86  );
     87  AccessibilityUtils.resetEnv();
     88 
     89  // Check that there is 5 matches.
     90  const matches = document.querySelectorAll(
     91    ".search-panel-content .treeRow.resultRow"
     92  );
     93  is(matches.length, 5, "There must be 5 matches");
     94 
     95  await teardown(monitor);
     96 });