|
1 <!-- Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
3 <!doctype html> |
|
4 |
|
5 <html> |
|
6 <head> |
|
7 <meta charset="utf-8"/> |
|
8 <title>Network Monitor test page</title> |
|
9 </head> |
|
10 |
|
11 <body> |
|
12 <p>Performing requests</p> |
|
13 |
|
14 <p> |
|
15 <canvas width="100" height="100"></canvas> |
|
16 </p> |
|
17 |
|
18 <hr/> |
|
19 |
|
20 <form method="post" action="#" enctype="multipart/form-data" target="target" id="post-form"> |
|
21 <input type="text" name="param1" value="value1"/> |
|
22 <input type="text" name="param2" value="value2"/> |
|
23 <input type="text" name="param3" value="value3"/> |
|
24 <input type="submit"/> |
|
25 </form> |
|
26 <iframe name="target"></iframe> |
|
27 |
|
28 <script type="text/javascript"> |
|
29 |
|
30 function ajaxGet(aUrl, aCallback) { |
|
31 var xhr = new XMLHttpRequest(); |
|
32 xhr.open("GET", aUrl + "?param1=value1¶m2=value2¶m3=value3", true); |
|
33 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); |
|
34 xhr.onload = function() { |
|
35 aCallback(); |
|
36 }; |
|
37 xhr.send(); |
|
38 } |
|
39 |
|
40 function ajaxPost(aUrl, aCallback) { |
|
41 var xhr = new XMLHttpRequest(); |
|
42 xhr.open("POST", aUrl, true); |
|
43 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
|
44 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); |
|
45 xhr.onload = function() { |
|
46 aCallback(); |
|
47 }; |
|
48 var params = "param1=value1¶m2=value2¶m3=value3"; |
|
49 xhr.send(params); |
|
50 } |
|
51 |
|
52 function ajaxMultipart(aUrl, aCallback) { |
|
53 var xhr = new XMLHttpRequest(); |
|
54 xhr.open("POST", aUrl, true); |
|
55 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); |
|
56 xhr.onload = function() { |
|
57 aCallback(); |
|
58 }; |
|
59 |
|
60 getCanvasElem().toBlob((blob) => { |
|
61 var formData = new FormData(); |
|
62 formData.append("param1", "value1"); |
|
63 formData.append("file", blob, "filename.png"); |
|
64 xhr.send(formData); |
|
65 }); |
|
66 } |
|
67 |
|
68 function submitForm() { |
|
69 var form = document.querySelector("#post-form"); |
|
70 form.submit(); |
|
71 } |
|
72 |
|
73 function getCanvasElem() { |
|
74 return document.querySelector("canvas"); |
|
75 } |
|
76 |
|
77 function initCanvas() { |
|
78 var canvas = getCanvasElem(); |
|
79 var ctx = canvas.getContext("2d"); |
|
80 ctx.fillRect(0,0,100,100); |
|
81 ctx.clearRect(20,20,60,60); |
|
82 ctx.strokeRect(25,25,50,50); |
|
83 } |
|
84 |
|
85 function performRequests(aUrl) { |
|
86 ajaxGet(aUrl, () => { |
|
87 ajaxPost(aUrl, () => { |
|
88 ajaxMultipart(aUrl, () => { |
|
89 submitForm(); |
|
90 }); |
|
91 }); |
|
92 }); |
|
93 } |
|
94 |
|
95 initCanvas(); |
|
96 </script> |
|
97 </body> |
|
98 |
|
99 </html> |