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