Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=936340
5 -->
6 <head>
7 <title>Test for beacon</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936340">Mozilla Bug 936340</a>
13 <p id="display"></p>
15 <div id="content">
16 </div>
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
21 // not enabled by default yet.
22 SimpleTest.waitForExplicitFinish();
23 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, runNextTest);
25 function getBeaconServerStatus(callback) {
26 var request = new XMLHttpRequest();
27 request.open("GET", "http://mochi.test:8888/tests/dom/tests/mochitest/beacon/beacon-handler.sjs?getLastBeacon", true);
28 request.onload = function() {
29 if (request.readyState === request.DONE) {
30 callback(request.responseText);
31 }
32 };
33 request.send(null);
34 }
36 function createIframeWithData(data, mimetype, convert) {
37 beaconConvert = convert;
39 var frame = document.createElement("IFRAME");
40 frame.setAttribute("src", "beacon-frame.html");
41 frame.id = "frame";
42 frame.setAttribute("data", data.toString());
43 frame.setAttribute("mimetype", mimetype);
44 var c = document.getElementById("content");
45 c.appendChild(frame);
46 }
48 function beaconSent(result) {
49 // This function gets called from beacon-frame.html in the inner frame
50 // Check that the beacon was actually sent
51 ok(result, "Beacon was not sent")
53 // remove the frame.
54 var frame = document.getElementById("frame");
55 var data = frame.getAttribute("data");
56 var mimetype = frame.getAttribute("mimetype");
58 var c = document.getElementById("content");
59 c.removeChild(frame);
61 getBeaconServerStatus( function(response) {
62 console.log(response);
63 var result = JSON.parse(response);
65 is(result.data, data, "Beacon status should match expected. is: " + result.data + " should be: " + data);
66 is(result.mimetype, mimetype, "Beacon mimetype should match expected. is: " + result.mimetype + " should be: " + mimetype);
68 runNextTest();
69 });
70 }
72 function runNextTest() {
73 var test = tests.shift();
74 setTimeout(test, 0);
75 }
77 var beaconConvert = function() {};
79 function stringToArrayBuffer(input) {
81 var buffer = new ArrayBuffer(input.length * 2);
82 var array = new Uint16Array(buffer);
84 // dumbly copy over the bytes
85 for (var i = 0, len = input.length; i < len; i++) {
86 array[i] = input.charCodeAt(i);
87 }
88 return array;
89 }
91 function stringToBlob(input) {
92 var blob = new Blob([input], {type : 'text/html'});
93 return blob;
94 }
96 function stringToFormData(input) {
97 var formdata = new FormData();
98 formdata.append(input, new Blob(['hi']));
99 return formdata;
100 }
102 function identity(data) {
103 return data;
104 }
106 var tests = [
107 function() { createIframeWithData("hi!", "text/plain;charset=UTF-8", identity); },
108 function() { createIframeWithData("123", "application/octet-stream", stringToArrayBuffer); },
109 function() { createIframeWithData("abc", "text/html", stringToBlob); },
110 function() { createIframeWithData("qwerty", "multipart/form-data", stringToFormData); },
111 function() { SimpleTest.finish(); },
112 ];
114 </script>
115 </pre>
116 </body>
117 </html>