summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_truncate-post-data.js
blob: 70cdab11b4ed497238e8414201c773753be418cb (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
/* Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Bug 1542172 -
 * Verifies that requests with large post data are truncated and error is displayed.
 */
add_task(async function () {
  const { monitor, tab } = await initNetMonitor(POST_JSON_URL, {
    requestCount: 1,
  });

  info("Starting test... ");

  const {
    L10N,
  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");

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

  requestLongerTimeout(2);

  info("Perform requests");
  await performRequestsAndWait(monitor, tab);

  await waitUntil(() => document.querySelector(".request-list-item"));
  const item = document.querySelectorAll(".request-list-item")[0];
  await waitUntil(() => item.querySelector(".requests-list-type").title);

  // Make sure the header and editor are loaded
  const waitHeader = waitForDOM(document, "#request-panel .data-header");
  const waitSourceEditor = waitForDOM(
    document,
    "#request-panel .CodeMirror.cm-s-mozilla"
  );

  store.dispatch(Actions.toggleNetworkDetails());
  clickOnSidebarTab(document, "request");

  await Promise.all([waitHeader, waitSourceEditor]);

  const tabpanel = document.querySelector("#request-panel");
  is(
    tabpanel.querySelector(".request-error-header") === null,
    false,
    "The request error header doesn't have the intended visibility."
  );
  is(
    tabpanel.querySelector(".request-error-header").textContent,
    "Request has been truncated",
    "The error message shown is incorrect"
  );
  const jsonView = tabpanel.querySelector(".data-label") || {};
  is(
    jsonView.textContent === L10N.getStr("jsonScopeName"),
    false,
    "The params json view doesn't have the intended visibility."
  );
  is(
    tabpanel.querySelector("PRE") === null,
    false,
    "The Request Payload has the intended visibility."
  );

  return teardown(monitor);
});

async function performRequestsAndWait(monitor, tab) {
  const wait = waitForNetworkEvents(monitor, 1);
  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
    content.wrappedJSObject.performLargePostDataRequest();
  });
  await wait;
}