summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_network_messages_status_code.js
blob: 240a5df67fe26bdc86d08037c7a767a24111fa62 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_FILE = "test-network-request.html";
const TEST_PATH =
  "https://example.com/browser/devtools/client/webconsole/" + "test/browser/";
const TEST_URI = TEST_PATH + TEST_FILE;

const NET_PREF = "devtools.webconsole.filter.net";
const XHR_PREF = "devtools.webconsole.filter.netxhr";
const {
  l10n,
} = require("resource://devtools/client/webconsole/utils/messages.js");
const LEARN_MORE_URI =
  "https://developer.mozilla.org/docs/Web/HTTP/Status/200" + GA_PARAMS;

pushPref(NET_PREF, true);
pushPref(XHR_PREF, true);

registerCleanupFunction(async function () {
  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () =>
      resolve()
    );
  });
});

add_task(async function task() {
  const hud = await openNewTabAndConsole(TEST_URI);

  const onNetworkMessageUpdate = hud.ui.once("network-messages-updated");

  // Fire an XHR POST request.
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.wrappedJSObject.testXhrPost();
  });

  info("XHR executed");
  await onNetworkMessageUpdate;

  const xhrUrl = TEST_PATH + "test-data.json";
  const messageNode = await waitFor(() =>
    findMessageByType(hud, xhrUrl, ".network")
  );
  ok(!!messageNode, "Network message found.");

  const statusCodeNode = await waitFor(() =>
    messageNode.querySelector(".status-code")
  );
  is(
    statusCodeNode.title,
    l10n.getStr("webConsoleMoreInfoLabel"),
    "Status code has the expected tooltip"
  );

  info("Left click status code node and observe the link opens.");
  const { link, where } = await simulateLinkClick(statusCodeNode);
  is(link, LEARN_MORE_URI, `Clicking the provided link opens ${link}`);
  is(where, "tab", "Link opened in correct tab.");

  info("Right click status code node and observe the context menu opening.");
  await openContextMenu(hud, statusCodeNode);
  await hideContextMenu(hud);

  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () =>
      resolve()
    );
  });
});