summaryrefslogtreecommitdiffstats
path: root/devtools/shared/webconsole/test/chrome/network_requests_iframe.html
blob: 6bb806b904b6e8313200ad4060dc6e1e19866992 (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
<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="utf-8">
    <title>Console HTTP test page</title>
    <!-- Any copyright is dedicated to the Public Domain.
       - http://creativecommons.org/publicdomain/zero/1.0/ -->
    <script type="text/javascript"><!--
      "use strict";
      let setAllowAllCookies = false;

      function makeXhr(method, url, requestBody, callback) {
        // On the first call, allow all cookies and set cookies, then resume the actual test
        if (!setAllowAllCookies) {
          SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]},
          function() {
            setAllowAllCookies = true;
            setCookies();
            makeXhrCallback(method, url, requestBody, callback);
          });
        } else {
          makeXhrCallback(method, url, requestBody, callback);
        }
      }

      function makeXhrCallback(method, url, requestBody, callback) {
        const xmlhttp = new XMLHttpRequest();
        xmlhttp.open(method, url, true);
        if (callback) {
          xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
              callback();
            }
          };
        }
        xmlhttp.send(requestBody);
      }

      /* exported testXhrGet */
      function testXhrGet(callback, url = "data.json") {
        makeXhr("get", url, null, callback);
      }

      /* exported testXhrPost */
      function testXhrPost(callback) {
        const body = "Hello world! " + (new Array(50)).join("foobaz barr");
        makeXhr("post", "data.json", body, callback);
      }

      function setCookies() {
        document.cookie = "foobar=fooval";
        document.cookie = "omgfoo=bug768096";
        document.cookie = "badcookie=bug826798=st3fan";
      }
      </script>
  </head>
  <body>
    <h1>Web Console HTTP Logging Testpage</h1>
    <h2>This page is used to test the HTTP logging.</h2>

    <form action="?" method="post">
      <input name="name" type="text" value="foo bar"><br>
      <input name="age" type="text" value="144"><br>
    </form>
  </body>
</html>