summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_http3_request_details.js
blob: 9ceb9dba88137ea2cc2823645a3ef5988dabb57d (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests request details with HTTP/3
 */

add_task(async function () {
  const { monitor } = await initNetMonitor(HTTPS_SIMPLE_SJS, {
    requestCount: 1,
  });
  info("Starting test... ");

  const { document, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");

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

  const wait = waitForNetworkEvents(monitor, 1);
  await reloadBrowser();
  await wait;

  const waitForHeaders = waitForDOM(document, ".headers-overview");
  store.dispatch(Actions.toggleNetworkDetails());
  await waitForHeaders;

  info("Assert the content of the headers");

  const tabpanel = document.querySelector("#headers-panel");
  // Request URL
  is(
    tabpanel.querySelector(".url-preview .url").innerText,
    HTTPS_SIMPLE_SJS,
    "The url summary value is incorrect."
  );

  // Request method
  is(
    tabpanel.querySelectorAll(".treeLabel")[0].innerText,
    "GET",
    "The method summary value is incorrect."
  );
  // Status code
  is(
    tabpanel.querySelector(".requests-list-status-code").innerText,
    "200",
    "The status summary code is incorrect."
  );
  is(
    tabpanel.querySelector(".status").childNodes[1].textContent,
    "", // HTTP/2 and 3 send no status text, only a code
    "The status summary value is incorrect."
  );
  // Version
  is(
    tabpanel.querySelectorAll(".tabpanel-summary-value")[1].innerText,
    "HTTP/3",
    "The HTTP version is incorrect."
  );

  await waitForRequestData(store, ["requestHeaders", "responseHeaders"]);

  is(
    tabpanel.querySelectorAll(".accordion-item").length,
    2,
    "There should be 2 header scopes displayed in this tabpanel."
  );

  const headers = [...tabpanel.querySelectorAll(".accordion .treeLabelCell")];

  is(
    // The Text-Encoding header is not consistently displayed, exclude it from
    // the assertion. See Bug 1830053.
    headers.filter(cell => cell.textContent != "TE").length,
    25,
    "There should be 25 header values displayed in this tabpanel."
  );

  const headersTable = tabpanel.querySelector(".accordion");
  const responseHeaders = headersTable.querySelectorAll(
    "tr[id^='/Response Headers']"
  );

  const expectedHeaders = [
    {
      name: "cache-control",
      value: "no-cache, no-store, must-revalidate",
      index: 0,
    },
    {
      name: "content-length",
      value: "12",
      index: 1,
    },
    {
      name: "content-type",
      value: "text/plain; charset=utf-8",
      index: 2,
    },
    {
      name: "foo-bar",
      value: "baz",
      index: 6,
    },
  ];
  expectedHeaders.forEach(header => {
    is(
      responseHeaders[header.index].querySelector(".treeLabel").innerHTML,
      header.name,
      `The response header at index ${header.index} name was incorrect.`
    );
    is(
      responseHeaders[header.index].querySelector(".objectBox").innerHTML,
      `${header.value}`,
      `The response header at index ${header.index} value was incorrect.`
    );
  });

  info("Assert the content of the raw headers");

  // Click the 'Raw headers' toggle to show original headers source.
  document.querySelector("#raw-request-checkbox").click();
  document.querySelector("#raw-response-checkbox").click();

  let rawHeadersElements;
  await waitUntil(() => {
    rawHeadersElements = document.querySelectorAll("textarea.raw-headers");
    // Both raw headers must be present
    return rawHeadersElements.length > 1;
  });
  const requestHeadersText = rawHeadersElements[1].textContent;
  const rawRequestHeaderFirstLine = requestHeadersText.split(/\r\n|\n|\r/)[0];
  is(
    rawRequestHeaderFirstLine,
    "GET /browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs HTTP/3"
  );

  const responseHeadersText = rawHeadersElements[0].textContent;
  const rawResponseHeaderFirstLine = responseHeadersText.split(/\r\n|\n|\r/)[0];
  is(rawResponseHeaderFirstLine, "HTTP/3 200 "); // H2/3 send no status text

  info("Assert the content of the protocol column");
  const target = document.querySelectorAll(".request-list-item")[0];
  is(
    target.querySelector(".requests-list-protocol").textContent,
    "HTTP/3",
    "The displayed protocol is correct."
  );

  return teardown(monitor);
});