Add test coverage for sendBeacon() keepalive flag
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 23:22:00 +0000 (23:22 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 23:22:00 +0000 (23:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175212

Reviewed by Youenn Fablet.

* http/wpt/beacon/keepalive-after-navigation-expected.txt: Added.
* http/wpt/beacon/keepalive-after-navigation.html: Added.
* http/wpt/beacon/support/sendBeacon-onunload-iframe.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220304 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/wpt/beacon/keepalive-after-navigation-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/keepalive-after-navigation.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/support/sendBeacon-onunload-iframe.html [new file with mode: 0644]

index 7a96ed6ad7f72e173d430bbcb7e6cbaa799d047e..dea0aca439a5b44f27bc5423787be00d443380ea 100644 (file)
@@ -1,3 +1,14 @@
+2017-08-04  Chris Dumez  <cdumez@apple.com>
+
+        Add test coverage for sendBeacon() keepalive flag
+        https://bugs.webkit.org/show_bug.cgi?id=175212
+
+        Reviewed by Youenn Fablet.
+
+        * http/wpt/beacon/keepalive-after-navigation-expected.txt: Added.
+        * http/wpt/beacon/keepalive-after-navigation.html: Added.
+        * http/wpt/beacon/support/sendBeacon-onunload-iframe.html: Added.
+
 2017-08-04  Chris Dumez  <cdumez@apple.com>
 
         [Beacon] Update sendBeacon to use the CachedResourceLoader
diff --git a/LayoutTests/http/wpt/beacon/keepalive-after-navigation-expected.txt b/LayoutTests/http/wpt/beacon/keepalive-after-navigation-expected.txt
new file mode 100644 (file)
index 0000000..bcaeae6
--- /dev/null
@@ -0,0 +1,4 @@
+frame "testFrame" - has 1 onunload handler(s)
+
+PASS Test that beacon sent from unload event handler is properly received 
+
diff --git a/LayoutTests/http/wpt/beacon/keepalive-after-navigation.html b/LayoutTests/http/wpt/beacon/keepalive-after-navigation.html
new file mode 100644 (file)
index 0000000..b44c862
--- /dev/null
@@ -0,0 +1,43 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>SendBeacon keepalive flag</title>
+    <script src=/resources/testharness.js></script>
+    <script src=/resources/testharnessreport.js></script>
+  </head>
+  <body>
+    <script src="/common/utils.js"></script>
+    <script src="/common/get-host-info.sub.js"></script>
+    <script>
+const RESOURCES_DIR = "/beacon/resources/";
+
+function pollResult(test, id) {
+  var checkUrl = RESOURCES_DIR + "content-type.py?cmd=get&id=" + id;
+
+  return new Promise(resolve => {
+    step_timeout(test.step_func(() => {
+      fetch(checkUrl).then(response => {
+        response.text().then(body => {
+          resolve(body);
+        });
+      });
+    }), 50);
+  });
+}
+
+onload = function() {
+    promise_test(function(test) {
+    let testFrame = document.getElementById("testFrame");
+    let id = testFrame.contentWindow.id;
+    testFrame.remove();
+
+    return pollResult(test, id).then(result => {
+      assert_equals(result, "text/plain;charset=UTF-8", "Correct content-type header result");
+    });
+  }, "Test that beacon sent from unload event handler is properly received");
+}
+    </script>
+  <iframe id="testFrame" src="support/sendBeacon-onunload-iframe.html"></iframe>
+  </body>
+</html>
diff --git a/LayoutTests/http/wpt/beacon/support/sendBeacon-onunload-iframe.html b/LayoutTests/http/wpt/beacon/support/sendBeacon-onunload-iframe.html
new file mode 100644 (file)
index 0000000..275109e
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<body onunload="unload()">
+<script src="/common/utils.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+
+<script>
+const RESOURCES_DIR = "/beacon/resources/";
+var id = self.token();
+
+function unload() {
+    var testUrl = RESOURCES_DIR + "content-type.py?cmd=put&id=" + id;
+    navigator.sendBeacon(testUrl, "test");
+}
+</script>
+</body>
+</html>