summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_basic-search.js
blob: b7e00fdd5fa2ee6849aa3c5151b9ca4de994a97a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Test basic search functionality.
 * Search panel is visible and number of expected results are returned.
 */

add_task(async function () {
  await pushPref("devtools.netmonitor.features.search", true);

  const { tab, monitor } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, {
    requestCount: 1,
  });
  info("Starting test... ");

  const { document, store, windowRequire } = monitor.panelWin;

  // Action should be processed synchronously in tests.
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
  store.dispatch(Actions.batchEnable(false));

  // Execute two XHRs (the same URL) and wait till it's finished.
  const URL = HTTPS_SEARCH_SJS + "?value=test";
  const wait = waitForNetworkEvents(monitor, 2);

  await SpecialPowers.spawn(tab.linkedBrowser, [URL], async function (url) {
    content.wrappedJSObject.performRequests(2, url);
  });
  await wait;

  // Open the Search panel
  store.dispatch(Actions.openSearch());

  // Fill Filter input with text and check displayed messages.
  // The filter should be focused automatically.
  typeInNetmonitor("test", monitor);
  EventUtils.synthesizeKey("KEY_Enter");

  // Wait till there are two resources rendered in the results.
  await waitForDOMIfNeeded(
    document,
    ".search-panel-content .treeRow.resourceRow",
    2
  );

  // Click on the first resource to expand it
  AccessibilityUtils.setEnv({
    // Keyboard users use arrow keys to expand/collapse tree items.
    // Accessibility is handled on the container level.
    mustHaveAccessibleRule: false,
  });
  EventUtils.sendMouseEvent(
    { type: "click" },
    document.querySelector(".search-panel-content .treeRow .treeIcon")
  );
  AccessibilityUtils.resetEnv();

  // Check that there is 5 matches.
  const matches = document.querySelectorAll(
    ".search-panel-content .treeRow.resultRow"
  );
  is(matches.length, 5, "There must be 5 matches");

  await teardown(monitor);
});