Add test coverage for sendBeacon() keepalive flag
[WebKit-https.git] / LayoutTests / http / wpt / beacon / keepalive-after-navigation.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>SendBeacon keepalive flag</title>
6     <script src=/resources/testharness.js></script>
7     <script src=/resources/testharnessreport.js></script>
8   </head>
9   <body>
10     <script src="/common/utils.js"></script>
11     <script src="/common/get-host-info.sub.js"></script>
12     <script>
13 const RESOURCES_DIR = "/beacon/resources/";
14
15 function pollResult(test, id) {
16   var checkUrl = RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;
17
18   return new Promise(resolve => {
19     step_timeout(test.step_func(() => {
20       fetch(checkUrl).then(response => {
21         response.text().then(body => {
22           resolve(body);
23         });
24       });
25     }), 50);
26   });
27 }
28
29 onload = function() {
30     promise_test(function(test) {
31     let testFrame = document.getElementById("testFrame");
32     let id = testFrame.contentWindow.id;
33     testFrame.remove();
34
35     return pollResult(test, id).then(result => {
36       assert_equals(result, "text/plain;charset=UTF-8", "Correct content-type header result");
37     });
38   }, "Test that beacon sent from unload event handler is properly received");
39 }
40     </script>
41   <iframe id="testFrame" src="support/sendBeacon-onunload-iframe.html"></iframe>
42   </body>
43 </html>