Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / navigation / beacon-same-origin.html
blobe9608e4164140d762fbe8551057fd92ed6b30279
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <script src="/js-test-resources/js-test.js"></script>
5 <script>
6 description("Testing navigator.sendBeacon() within same origin.");
8 window.jsTestIsAsync = true;
10 var binary_array = new Uint32Array(10);
11 for (var i = 0; i < binary_array.length; i++) {
12 binary_array[i] = 64 + i;
15 var blob = new Blob(["hello", " ", "world"], {type: "text/plain;from-beacon=true"});
16 var form = new FormData();
17 form.append("key", "value");
19 var tests = [
20 "SameOrigin",
21 binary_array,
22 blob,
23 form];
25 var payload;
26 function testOne() {
27 payload = tests.shift();
28 if (!payload) {
29 finishJSTest();
30 return;
32 debug("Sending beacon with type: " + Object.prototype.toString.call(payload));
33 shouldBeTrue('navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload);');
34 var xhr = new XMLHttpRequest();
35 xhr.open("GET", "resources/check-beacon.php?name=same-origin");
36 xhr.onload = function () {
37 var lines = xhr.responseText.split("\n");
38 for (var i in lines)
39 testPassed(lines[i]);
40 testOne();
42 xhr.onerror = function () {
43 testFailed("Unable to fetch beacon status");
44 testOne();
46 xhr.send();
49 function test() {
50 if (window.testRunner) {
51 testRunner.dumpAsText();
52 testRunner.waitUntilDone();
53 testRunner.dumpPingLoaderCallbacks();
55 testOne();
57 </script>
58 </head>
59 <body onload="test();">
60 </body>
61 </html>