browser/devtools/netmonitor/test/html_curl-utils.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/html_curl-utils.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +<!-- Any copyright is dedicated to the Public Domain.
     1.5 +     http://creativecommons.org/publicdomain/zero/1.0/ -->
     1.6 +<!doctype html>
     1.7 +
     1.8 +<html>
     1.9 +  <head>
    1.10 +    <meta charset="utf-8"/>
    1.11 +    <title>Network Monitor test page</title>
    1.12 +  </head>
    1.13 +
    1.14 +  <body>
    1.15 +    <p>Performing requests</p>
    1.16 +
    1.17 +    <p>
    1.18 +      <canvas width="100" height="100"></canvas>
    1.19 +    </p>
    1.20 +
    1.21 +    <hr/>
    1.22 +
    1.23 +    <form method="post" action="#" enctype="multipart/form-data" target="target" id="post-form">
    1.24 +      <input type="text" name="param1" value="value1"/>
    1.25 +      <input type="text" name="param2" value="value2"/>
    1.26 +      <input type="text" name="param3" value="value3"/>
    1.27 +      <input type="submit"/>
    1.28 +    </form>
    1.29 +    <iframe name="target"></iframe>
    1.30 +
    1.31 +    <script type="text/javascript">
    1.32 +
    1.33 +      function ajaxGet(aUrl, aCallback) {
    1.34 +        var xhr = new XMLHttpRequest();
    1.35 +        xhr.open("GET", aUrl + "?param1=value1&param2=value2&param3=value3", true);
    1.36 +        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    1.37 +        xhr.onload = function() {
    1.38 +          aCallback();
    1.39 +        };
    1.40 +        xhr.send();
    1.41 +      }
    1.42 +
    1.43 +      function ajaxPost(aUrl, aCallback) {
    1.44 +        var xhr = new XMLHttpRequest();
    1.45 +        xhr.open("POST", aUrl, true);
    1.46 +        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    1.47 +        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    1.48 +        xhr.onload = function() {
    1.49 +          aCallback();
    1.50 +        };
    1.51 +        var params = "param1=value1&param2=value2&param3=value3";
    1.52 +        xhr.send(params);
    1.53 +      }
    1.54 +
    1.55 +      function ajaxMultipart(aUrl, aCallback) {
    1.56 +        var xhr = new XMLHttpRequest();
    1.57 +        xhr.open("POST", aUrl, true);
    1.58 +        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    1.59 +        xhr.onload = function() {
    1.60 +          aCallback();
    1.61 +        };
    1.62 +
    1.63 +        getCanvasElem().toBlob((blob) => {
    1.64 +          var formData = new FormData();
    1.65 +          formData.append("param1", "value1");
    1.66 +          formData.append("file", blob, "filename.png");
    1.67 +          xhr.send(formData);
    1.68 +        });
    1.69 +      }
    1.70 +
    1.71 +      function submitForm() {
    1.72 +        var form = document.querySelector("#post-form");
    1.73 +        form.submit();
    1.74 +      }
    1.75 +
    1.76 +      function getCanvasElem() {
    1.77 +        return document.querySelector("canvas");
    1.78 +      }
    1.79 +
    1.80 +      function initCanvas() {
    1.81 +        var canvas = getCanvasElem();
    1.82 +        var ctx = canvas.getContext("2d");
    1.83 +        ctx.fillRect(0,0,100,100);
    1.84 +        ctx.clearRect(20,20,60,60);
    1.85 +        ctx.strokeRect(25,25,50,50);
    1.86 +      }
    1.87 +
    1.88 +      function performRequests(aUrl) {
    1.89 +        ajaxGet(aUrl, () => {
    1.90 +          ajaxPost(aUrl, () => {
    1.91 +            ajaxMultipart(aUrl, () => {
    1.92 +              submitForm();
    1.93 +            });
    1.94 +          });
    1.95 +        });
    1.96 +      }
    1.97 +
    1.98 +      initCanvas();
    1.99 +    </script>
   1.100 +  </body>
   1.101 +
   1.102 +</html>

mercurial