diff options
Diffstat (limited to 'testing/web-platform/tests/eventsource/resources')
13 files changed, 221 insertions, 0 deletions
diff --git a/testing/web-platform/tests/eventsource/resources/accept.event_stream b/testing/web-platform/tests/eventsource/resources/accept.event_stream new file mode 100644 index 0000000000..24da548267 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/accept.event_stream @@ -0,0 +1,2 @@ +data: {{headers[accept]}} + diff --git a/testing/web-platform/tests/eventsource/resources/cache-control.event_stream b/testing/web-platform/tests/eventsource/resources/cache-control.event_stream new file mode 100644 index 0000000000..aa9f2d6c09 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/cache-control.event_stream @@ -0,0 +1,2 @@ +data: {{headers[cache-control]}} + diff --git a/testing/web-platform/tests/eventsource/resources/cors-cookie.py b/testing/web-platform/tests/eventsource/resources/cors-cookie.py new file mode 100644 index 0000000000..9eaab9b95a --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/cors-cookie.py @@ -0,0 +1,31 @@ +from datetime import datetime + +def main(request, response): + last_event_id = request.headers.get(b"Last-Event-Id", b"") + ident = request.GET.first(b'ident', b"test") + cookie = b"COOKIE" if ident in request.cookies else b"NO_COOKIE" + origin = request.GET.first(b'origin', request.headers[b"origin"]) + credentials = request.GET.first(b'credentials', b'true') + + headers = [] + + if origin != b'none': + headers.append((b"Access-Control-Allow-Origin", origin)); + + if credentials != b'none': + headers.append((b"Access-Control-Allow-Credentials", credentials)); + + if last_event_id == b'': + headers.append((b"Content-Type", b"text/event-stream")) + response.set_cookie(ident, b"COOKIE") + data = b"id: 1\nretry: 200\ndata: first %s\n\n" % cookie + elif last_event_id == b'1': + headers.append((b"Content-Type", b"text/event-stream")) + long_long_time_ago = datetime.now().replace(year=2001, month=7, day=27) + response.set_cookie(ident, b"COOKIE", expires=long_long_time_ago) + data = b"id: 2\ndata: second %s\n\n" % cookie + else: + headers.append((b"Content-Type", b"stop")) + data = b"data: " + last_event_id + cookie + b"\n\n"; + + return headers, data diff --git a/testing/web-platform/tests/eventsource/resources/cors.py b/testing/web-platform/tests/eventsource/resources/cors.py new file mode 100644 index 0000000000..6ed31f2cd7 --- /dev/null +++ b/testing/web-platform/tests/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 diff --git a/testing/web-platform/tests/eventsource/resources/eventsource-onmessage-realm.htm b/testing/web-platform/tests/eventsource/resources/eventsource-onmessage-realm.htm new file mode 100644 index 0000000000..63e6d012b4 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/eventsource-onmessage-realm.htm @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<title>This page is just used to grab an EventSource constructor</title> diff --git a/testing/web-platform/tests/eventsource/resources/init.htm b/testing/web-platform/tests/eventsource/resources/init.htm new file mode 100644 index 0000000000..7c56d88800 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/init.htm @@ -0,0 +1,9 @@ +<!doctype html> +<html> + <head> + <title>support init file</title> + </head> + <body> + <script> parent.init() </script> + </body> +</html> diff --git a/testing/web-platform/tests/eventsource/resources/last-event-id.py b/testing/web-platform/tests/eventsource/resources/last-event-id.py new file mode 100644 index 0000000000..a2cb726445 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/last-event-id.py @@ -0,0 +1,9 @@ +def main(request, response): + response.headers.set(b"Content-Type", b"text/event-stream") + + last_event_id = request.headers.get(b"Last-Event-ID", b"") + if last_event_id: + return b"data: " + last_event_id + b"\n\n" + else: + idvalue = request.GET.first(b"idvalue", u"\u2026".encode("utf-8")) + return b"id: " + idvalue + b"\nretry: 200\ndata: hello\n\n" diff --git a/testing/web-platform/tests/eventsource/resources/last-event-id2.py b/testing/web-platform/tests/eventsource/resources/last-event-id2.py new file mode 100644 index 0000000000..4f133d707d --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/last-event-id2.py @@ -0,0 +1,23 @@ +ID_PERSISTS = 1 +ID_RESETS_1 = 2 +ID_RESETS_2 = 3 + +def main(request, response): + response.headers.set(b"Content-Type", b"text/event-stream") + try: + test_type = int(request.GET.first(b"type", ID_PERSISTS)) + except: + test_type = ID_PERSISTS + + if test_type == ID_PERSISTS: + return b"id: 1\ndata: 1\n\ndata: 2\n\nid: 2\ndata:3\n\ndata:4\n\n" + + elif test_type == ID_RESETS_1: + return b"id: 1\ndata: 1\n\nid:\ndata:2\n\ndata:3\n\n" + + # empty id field without colon character (:) should also reset + elif test_type == ID_RESETS_2: + return b"id: 1\ndata: 1\n\nid\ndata:2\n\ndata:3\n\n" + + else: + return b"data: invalid_test\n\n" diff --git a/testing/web-platform/tests/eventsource/resources/message.py b/testing/web-platform/tests/eventsource/resources/message.py new file mode 100644 index 0000000000..468564f4df --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/message.py @@ -0,0 +1,14 @@ +import time + +def main(request, response): + mime = request.GET.first(b"mime", b"text/event-stream") + message = request.GET.first(b"message", b"data: data"); + newline = b"" if request.GET.first(b"newline", None) == b"none" else b"\n\n"; + sleep = int(request.GET.first(b"sleep", b"0")) + + headers = [(b"Content-Type", mime)] + body = message + newline + b"\n" + if sleep != 0: + time.sleep(sleep/1000) + + return headers, body diff --git a/testing/web-platform/tests/eventsource/resources/message2.py b/testing/web-platform/tests/eventsource/resources/message2.py new file mode 100644 index 0000000000..8515e7b25e --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/message2.py @@ -0,0 +1,33 @@ +import time + +def main(request, response): + response.headers.set(b'Content-Type', b'text/event-stream') + response.headers.set(b'Cache-Control', b'no-cache') + + response.write_status_headers() + + while True: + response.writer.write(u"data:msg") + response.writer.write(u"\n") + response.writer.write(u"data: msg") + response.writer.write(u"\n\n") + + response.writer.write(u":") + response.writer.write(u"\n") + + response.writer.write(u"falsefield:msg") + response.writer.write(u"\n\n") + + response.writer.write(u"falsefield:msg") + response.writer.write(u"\n") + + response.writer.write(u"Data:data") + response.writer.write(u"\n\n") + + response.writer.write(u"data") + response.writer.write(u"\n\n") + + response.writer.write(u"data:end") + response.writer.write(u"\n\n") + + time.sleep(2) diff --git a/testing/web-platform/tests/eventsource/resources/reconnect-fail.py b/testing/web-platform/tests/eventsource/resources/reconnect-fail.py new file mode 100644 index 0000000000..12b07700cd --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/reconnect-fail.py @@ -0,0 +1,24 @@ +def main(request, response): + name = b"recon_fail_" + request.GET.first(b"id") + + headers = [(b"Content-Type", b"text/event-stream")] + cookie = request.cookies.first(name, None) + state = cookie.value if cookie is not None else None + + if state == b'opened': + status = (200, b"RECONNECT") + response.set_cookie(name, b"reconnected"); + body = b"data: reconnected\n\n"; + + elif state == b'reconnected': + status = (204, b"NO CONTENT (CLOSE)") + response.delete_cookie(name); + body = b"data: closed\n\n" # Will never get through + + else: + status = (200, b"OPEN"); + response.set_cookie(name, b"opened"); + body = b"retry: 2\ndata: opened\n\n"; + + return status, headers, body + diff --git a/testing/web-platform/tests/eventsource/resources/status-error.py b/testing/web-platform/tests/eventsource/resources/status-error.py new file mode 100644 index 0000000000..ed5687b6c2 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/status-error.py @@ -0,0 +1,15 @@ +def main(request, response): + status = (request.GET.first(b"status", b"404"), b"HAHAHAHA") + headers = [(b"Content-Type", b"text/event-stream")] + + # According to RFC7231, HTTP responses bearing status code 204 or 205 must + # not specify a body. The expected browser behavior for this condition is not + # currently defined--see the following for further discussion: + # + # https://github.com/web-platform-tests/wpt/pull/5227 + if status[0] in [b"204", b"205"]: + body = b"" + else: + body = b"data: data\n\n" + + return status, headers, body diff --git a/testing/web-platform/tests/eventsource/resources/status-reconnect.py b/testing/web-platform/tests/eventsource/resources/status-reconnect.py new file mode 100644 index 0000000000..a59f751fc3 --- /dev/null +++ b/testing/web-platform/tests/eventsource/resources/status-reconnect.py @@ -0,0 +1,21 @@ +def main(request, response): + status_code = request.GET.first(b"status", b"204") + name = request.GET.first(b"id", status_code) + + headers = [(b"Content-Type", b"text/event-stream")] + + cookie_name = b"request" + name + + if request.cookies.first(cookie_name, b"") == status_code: + status = 200 + response.delete_cookie(cookie_name) + body = b"data: data\n\n" + else: + response.set_cookie(cookie_name, status_code); + status = (int(status_code), b"TEST") + body = b"retry: 2\n" + if b"ok_first" in request.GET: + body += b"data: ok\n\n" + + return status, headers, body + |