summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_header-docs.js
blob: 91d2794d5f327c2d70d8f5c759d86bf3d6dc0644 (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
69
70
71
72
73
74
75
76
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests if "Learn More" links are correctly displayed
 * next to headers.
 */
add_task(async function () {
  const { tab, monitor } = await initNetMonitor(POST_DATA_URL, {
    requestCount: 1,
  });
  info("Starting test... ");

  const { document, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
  const { getSortedRequests } = windowRequire(
    "devtools/client/netmonitor/src/selectors/index"
  );
  const {
    getHeadersURL,
  } = require("resource://devtools/client/netmonitor/src/utils/doc-utils.js");

  store.dispatch(Actions.batchEnable(false));

  // Execute requests.
  await performRequests(monitor, tab, 2);

  AccessibilityUtils.setEnv({
    // Keyboard users will will see the sidebar when the request row is
    // selected. Accessibility is handled on the container level.
    actionCountRule: false,
    interactiveRule: false,
    labelRule: false,
  });
  EventUtils.sendMouseEvent(
    { type: "click" },
    document.querySelectorAll(".request-list-item")[0]
  );
  AccessibilityUtils.resetEnv();

  testShowLearnMore(getSortedRequests(store.getState())[0]);

  return teardown(monitor);

  /*
   * Tests that a "Learn More" button is only shown if
   * and only if a header is documented in MDN.
   */
  function testShowLearnMore(data) {
    const selector = ".properties-view .treeRow.stringRow";
    document.querySelectorAll(selector).forEach((rowEl, index) => {
      const headerName = rowEl.querySelectorAll(".treeLabelCell .treeLabel")[0]
        .textContent;
      const headerDocURL = getHeadersURL(headerName);
      const learnMoreEl = rowEl.querySelectorAll(
        ".treeValueCell .learn-more-link"
      );

      if (headerDocURL === null) {
        Assert.strictEqual(
          learnMoreEl.length,
          0,
          'undocumented header does not include a "Learn More" button'
        );
      } else {
        Assert.strictEqual(
          learnMoreEl[0].getAttribute("title"),
          headerDocURL,
          'documented header includes a "Learn More" button with a link to MDN'
        );
      }
    });
  }
});