Truly independent web browser
Tests: Import EventSource message, redirect and end-of-stream WPT tests
Shannon Booth8668df17b0ae
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 04990dd313d..673c95781e2 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -575,8 +575,13 @@ Text/input/wpt-import/html/semantics/forms/the-input-element/show-picker-disableText/input/wpt-import/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic.htmlText/input/wpt-import/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic.htmlText/input/wpt-import/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test.html+Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.html+Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.html+Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.htmlText/input/wpt-import/eventsource/format-bom-2.any.htmlText/input/wpt-import/eventsource/format-bom.any.html+Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.html+Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.htmlText/input/wpt-import/eventsource/format-field-id-2.any.htmlText/input/wpt-import/eventsource/format-field-id-2.any.worker.htmlText/input/wpt-import/eventsource/format-field-id-null.window.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txtnew file mode 100644index 00000000000..6d6c43b0663--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail MessageEvent.origin is the origin of the final URL after a cross-origin redirect\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-onmessage-trusted.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-onmessage-trusted.any.txtnew file mode 100644index 00000000000..6a473be5edf--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-onmessage-trusted.any.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail EventSource message events are trusted\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.txtnew file mode 100644index 00000000000..6a473be5edf--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail EventSource message events are trusted\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-data-before-final-empty-line.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-data-before-final-empty-line.any.txtnew file mode 100644index 00000000000..621d4a64d3c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-data-before-final-empty-line.any.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail EventSource: a data before final empty line\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.txtnew file mode 100644index 00000000000..621d4a64d3c--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail EventSource: a data before final empty line\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.htmlnew file mode 100644index 00000000000..c8717e48d62--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.html@@ -0,0 +1,15 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: origin of the event stream's final URL</title>+<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../common/get-host-info.sub.js"></script>+<div id=log></div>+<script src="../eventsource/eventsource-cross-origin-redirect-origin.any.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.jsnew file mode 100644index 00000000000..bd5c6763ab6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-cross-origin-redirect-origin.any.js@@ -0,0 +1,16 @@+// META: title=EventSource: origin of the event stream's final URL+// META: script=/common/get-host-info.sub.js++async_test(t => {+ const crossOrigin = get_host_info().HTTP_REMOTE_ORIGIN;+ const target = crossOrigin + "/eventsource/resources/cors.py?run=message";+ const source = new EventSource(+ "/common/redirect.py?location=" + encodeURIComponent(target));+ t.add_cleanup(() => source.close());++ source.onerror = t.unreached_func("error event");+ source.onmessage = t.step_func_done(e => {+ assert_equals(e.data, "data", "data");+ assert_equals(e.origin, crossOrigin, "origin");+ });+}, "MessageEvent.origin is the origin of the final URL after a cross-origin redirect");diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.htmlnew file mode 100644index 00000000000..5c7704a7f81--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.html@@ -0,0 +1,15 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource message events are trusted</title>+<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../eventsource/eventsource-onmessage-trusted.any.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.jsnew file mode 100644index 00000000000..d0be4d03e8b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.js@@ -0,0 +1,12 @@+// META: title=EventSource message events are trusted++"use strict";++async_test(t => {+ const source = new EventSource("resources/message.py");++ source.onmessage = t.step_func_done(e => {+ source.close();+ assert_equals(e.isTrusted, true);+ });+}, "EventSource message events are trusted");diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.htmlnew file mode 100644index 00000000000..a6427041324--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource message events are trusted</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<div id=log></div>+<script>+fetch_tests_from_worker(new Worker("../eventsource/eventsource-onmessage-trusted.any.worker.js"));+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.jsnew file mode 100644index 00000000000..1f8230ca23b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/eventsource-onmessage-trusted.any.worker.js@@ -0,0 +1,10 @@++self.GLOBAL = {+ isWindow: function() { return false; },+ isWorker: function() { return true; },+ isShadowRealm: function() { return false; },+};+importScripts("/resources/testharness.js");+self.META_TITLE = "EventSource message events are trusted";+importScripts("/eventsource/eventsource-onmessage-trusted.any.js");+done();diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.htmlnew file mode 100644index 00000000000..356d54aa13a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.html@@ -0,0 +1,15 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: a data before final empty line</title>+<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../eventsource/format-data-before-final-empty-line.any.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.jsnew file mode 100644index 00000000000..5a4d84d28d3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.js@@ -0,0 +1,17 @@+// META: title=EventSource: a data before final empty line++ var test = async_test()+ test.step(function() {+ var source = new EventSource("resources/message.py?newline=none&message=" + encodeURIComponent("retry:1000\ndata:test1\n\nid:test\ndata:test2"))+ var count = 0;+ source.onmessage = function(e) {+ if (++count === 2) {+ test.step(function() {+ assert_equals(e.lastEventId, "", "lastEventId")+ assert_equals(e.data, "test1", "data")+ source.close()+ })+ test.done()+ }+ }+ })diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.htmlnew file mode 100644index 00000000000..3ab6fc47b61--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: a data before final empty line</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<div id=log></div>+<script>+fetch_tests_from_worker(new Worker("../eventsource/format-data-before-final-empty-line.any.worker.js"));+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.jsnew file mode 100644index 00000000000..0ead88fb3a6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-data-before-final-empty-line.any.worker.js@@ -0,0 +1,10 @@++self.GLOBAL = {+ isWindow: function() { return false; },+ isWorker: function() { return true; },+ isShadowRealm: function() { return false; },+};+importScripts("/resources/testharness.js");+self.META_TITLE = "EventSource: a data before final empty line";+importScripts("/eventsource/format-data-before-final-empty-line.any.js");+done();diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/resources/cors.py b/Tests/LibWeb/Text/input/wpt-import/eventsource/resources/cors.pynew file mode 100644index 00000000000..6ed31f2cd7d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/resources/cors.py@@ -0,0 +1,36 @@+import os+from wptserve import pipes++from wptserve.utils import isomorphic_decode++def run_other(request, response, path):+ #This is a terrible hack+ environ = {u"__file__": path}+ exec(compile(open(path, u"r").read(), path, u'exec'), environ, environ)+ rv = environ[u"main"](request, response)+ return rv++def main(request, response):+ origin = request.GET.first(b"origin", request.headers[b"origin"])+ credentials = request.GET.first(b"credentials", b"true")++ response.headers.update([(b"Access-Control-Allow-Origin", origin),+ (b"Access-Control-Allow-Credentials", credentials)])++ handler = request.GET.first(b'run')+ if handler in [b"status-reconnect",+ b"message",+ b"redirect",+ b"cache-control"]:+ if handler == b"cache-control":+ response.headers.set(b"Content-Type", b"text/event-stream")+ rv = open(os.path.join(request.doc_root, u"eventsource", u"resources", u"cache-control.event_stream"), u"r").read()+ response.content = rv+ pipes.sub(request, response)+ return+ elif handler == b"redirect":+ return run_other(request, response, os.path.join(request.doc_root, u"common", u"redirect.py"))+ else:+ return run_other(request, response, os.path.join(os.path.dirname(isomorphic_decode(__file__)), isomorphic_decode(handler) + u".py"))+ else:+ return