diff options
Diffstat (limited to 'testing/web-platform/tests/preload/resources')
40 files changed, 288 insertions, 0 deletions
diff --git a/testing/web-platform/tests/preload/resources/A4.ogv b/testing/web-platform/tests/preload/resources/A4.ogv Binary files differnew file mode 100644 index 0000000000..de99616ece --- /dev/null +++ b/testing/web-platform/tests/preload/resources/A4.ogv diff --git a/testing/web-platform/tests/preload/resources/A4.ogv.sub.headers b/testing/web-platform/tests/preload/resources/A4.ogv.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/A4.ogv.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/cross-origin-module.py b/testing/web-platform/tests/preload/resources/cross-origin-module.py new file mode 100644 index 0000000000..35dce5401c --- /dev/null +++ b/testing/web-platform/tests/preload/resources/cross-origin-module.py @@ -0,0 +1,9 @@ +def main(request, response): + headers = [ + (b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Origin", request.headers.get(b"Origin")), + (b"Timing-Allow-Origin", request.headers.get(b"Origin")), + (b"Access-Control-Allow-Credentials", b"true") + ] + + return headers, u"// Cross-origin module, nothing to see here" diff --git a/testing/web-platform/tests/preload/resources/dummy-preloads-subresource.css b/testing/web-platform/tests/preload/resources/dummy-preloads-subresource.css new file mode 100644 index 0000000000..5097166a05 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy-preloads-subresource.css @@ -0,0 +1 @@ +/* This is just a dummy, empty CSS file */ diff --git a/testing/web-platform/tests/preload/resources/dummy-preloads-subresource.css.sub.headers b/testing/web-platform/tests/preload/resources/dummy-preloads-subresource.css.sub.headers new file mode 100644 index 0000000000..f6b4b491ce --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy-preloads-subresource.css.sub.headers @@ -0,0 +1,2 @@ +Cache-Control: max-age=1000 +Link: </fonts/CanvasTest.ttf?link-header-on-subresource>; rel=preload;as=font;crossorigin diff --git a/testing/web-platform/tests/preload/resources/dummy.css b/testing/web-platform/tests/preload/resources/dummy.css new file mode 100644 index 0000000000..5097166a05 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy.css @@ -0,0 +1 @@ +/* This is just a dummy, empty CSS file */ diff --git a/testing/web-platform/tests/preload/resources/dummy.css.sub.headers b/testing/web-platform/tests/preload/resources/dummy.css.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy.css.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/dummy.js b/testing/web-platform/tests/preload/resources/dummy.js new file mode 100644 index 0000000000..cfcb9d89a1 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy.js @@ -0,0 +1 @@ +// This is example JS content. Nothing to see here. diff --git a/testing/web-platform/tests/preload/resources/dummy.js.sub.headers b/testing/web-platform/tests/preload/resources/dummy.js.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy.js.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/dummy.xml b/testing/web-platform/tests/preload/resources/dummy.xml new file mode 100644 index 0000000000..0d88d0cb3e --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8"?> +<root>Text.me</root> diff --git a/testing/web-platform/tests/preload/resources/dummy.xml.sub.headers b/testing/web-platform/tests/preload/resources/dummy.xml.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/dummy.xml.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/echo-preload-header.py b/testing/web-platform/tests/preload/resources/echo-preload-header.py new file mode 100644 index 0000000000..5cfb9e8c25 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/echo-preload-header.py @@ -0,0 +1,16 @@ +import os +from wptserve.utils import isomorphic_encode + +def main(request, response): + response.headers.set(b"Content-Type", request.GET.first(b"type")) + link = request.GET.first(b"link") + response.headers.set(b"Access-Control-Allow-Origin", b"*") + response.headers.set(b"Access-Control-Allow-Credentials", b"true") + if link is not None: + response.headers.set(b"Link", link) + + if b"file" in request.GET: + path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), request.GET.first(b"file")); + response.content = open(path, mode=u'rb').read(); + else: + return request.GET.first(b"content") diff --git a/testing/web-platform/tests/preload/resources/echo-referrer.py b/testing/web-platform/tests/preload/resources/echo-referrer.py new file mode 100644 index 0000000000..287e000f8f --- /dev/null +++ b/testing/web-platform/tests/preload/resources/echo-referrer.py @@ -0,0 +1,6 @@ +def main(request, response): + response_headers = [(b"Access-Control-Allow-Origin", b"*"), (b"Content-Type", b"text/javascript")] + body = b""" + window.referrers["%s"] = "%s"; + """ % (request.GET.first(b"uid", b""), request.headers.get(b"referer", b"")) + return (200, response_headers, body) diff --git a/testing/web-platform/tests/preload/resources/echo-with-cors.py b/testing/web-platform/tests/preload/resources/echo-with-cors.py new file mode 100644 index 0000000000..06d30c303c --- /dev/null +++ b/testing/web-platform/tests/preload/resources/echo-with-cors.py @@ -0,0 +1,8 @@ +def main(request, response): + response.headers.set(b"Content-Type", request.GET.first(b"type")) + origin = request.headers.get('Origin') + if origin is not None: + response.headers.set(b"Access-Control-Allow-Origin", origin) + response.headers.set(b"Access-Control-Allow-Credentials", b"true") + + return request.GET.first(b"content") diff --git a/testing/web-platform/tests/preload/resources/empty.html b/testing/web-platform/tests/preload/resources/empty.html new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/empty.html diff --git a/testing/web-platform/tests/preload/resources/empty.html.sub.headers b/testing/web-platform/tests/preload/resources/empty.html.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/empty.html.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/font.ttf b/testing/web-platform/tests/preload/resources/font.ttf Binary files differnew file mode 100644 index 0000000000..4d4785a412 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/font.ttf diff --git a/testing/web-platform/tests/preload/resources/font.ttf.sub.headers b/testing/web-platform/tests/preload/resources/font.ttf.sub.headers new file mode 100644 index 0000000000..baff318e67 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/font.ttf.sub.headers @@ -0,0 +1,2 @@ +Access-Control-Allow-Origin: {{header_or_default(Origin, *)}} +Access-Control-Allow-Credentials: true diff --git a/testing/web-platform/tests/preload/resources/foo.vtt b/testing/web-platform/tests/preload/resources/foo.vtt new file mode 100644 index 0000000000..b533895c60 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/foo.vtt @@ -0,0 +1,4 @@ +WEBVTT + +00:00:00.000 --> 00:00:05.000 +Foo diff --git a/testing/web-platform/tests/preload/resources/foo.vtt.sub.headers b/testing/web-platform/tests/preload/resources/foo.vtt.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/foo.vtt.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/link-header-referrer-policy.html b/testing/web-platform/tests/preload/resources/link-header-referrer-policy.html new file mode 100644 index 0000000000..dd2144d507 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/link-header-referrer-policy.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<body> +<script> +window.referrers = {}; +const params = new URLSearchParams(location.search); +const href = new URL(params.get('href'), location.href).toString(); +new PerformanceObserver(async list => { + let entries = list.getEntriesByName(href).length; + if (!entries) + return; + + const script = document.createElement('script'); + script.src = href; + script.referrerPolicy = params.get('resource-policy'); + const loaded = new Promise(resolve => script.addEventListener('load', resolve)); + document.body.appendChild(script); + await loaded; + entries = performance.getEntriesByName(href).length; + window.parent.postMessage({ + referrers: window.referrers, + entries + }, '*'); +}).observe({type: 'resource', buffered: true}) +</script> +</body> diff --git a/testing/web-platform/tests/preload/resources/link-header-referrer-policy.py b/testing/web-platform/tests/preload/resources/link-header-referrer-policy.py new file mode 100644 index 0000000000..984518d364 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/link-header-referrer-policy.py @@ -0,0 +1,11 @@ +def main(request, response): + response_headers = [(b"Link", b"<%s>;rel=\"preload\";%s;as=\"script\"" % + (request.GET.first(b"href", b""), + request.GET.first(b"preload-policy", b"")))] + body = "" + body_name_list = __file__.split(".")[:-1] + body_name_list.append("html") + filename = ".".join(body_name_list) + with open(filename, 'r+b') as f: + body = f.readlines() + return (200, response_headers, body) diff --git a/testing/web-platform/tests/preload/resources/module1.js b/testing/web-platform/tests/preload/resources/module1.js new file mode 100644 index 0000000000..ebaeae7ac7 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/module1.js @@ -0,0 +1,2 @@ +import { y } from './module2.js'; +export let x = y + 1;
\ No newline at end of file diff --git a/testing/web-platform/tests/preload/resources/module1.mjs b/testing/web-platform/tests/preload/resources/module1.mjs new file mode 100644 index 0000000000..ebaeae7ac7 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/module1.mjs @@ -0,0 +1,2 @@ +import { y } from './module2.js'; +export let x = y + 1;
\ No newline at end of file diff --git a/testing/web-platform/tests/preload/resources/module2.js b/testing/web-platform/tests/preload/resources/module2.js new file mode 100644 index 0000000000..e4e3217b8c --- /dev/null +++ b/testing/web-platform/tests/preload/resources/module2.js @@ -0,0 +1 @@ +export let y = 1; diff --git a/testing/web-platform/tests/preload/resources/modulepreload-iframe.html b/testing/web-platform/tests/preload/resources/modulepreload-iframe.html new file mode 100644 index 0000000000..1d3d21f4d9 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/modulepreload-iframe.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<body> + <script> + const m = new URL('module1.js', location.href).toString(); + const observer = new PerformanceObserver(l => { + const entries = l.getEntriesByName(m); + if (entries.length === 1) { + import(m).then(() => { + observer.disconnect(); + const all = performance.getEntriesByName(m); + window.parent.postMessage(all.length, '*'); + }); + } + }); + + observer.observe({type: 'resource', buffered: true}); + + + </script> +</body>
\ No newline at end of file diff --git a/testing/web-platform/tests/preload/resources/prefetch-exec.html b/testing/web-platform/tests/preload/resources/prefetch-exec.html new file mode 100644 index 0000000000..1d6765bc93 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/prefetch-exec.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Message BC</title> +<script src="/common/dispatcher/dispatcher.js"></script> +<script> +"use strict"; +const params = new URLSearchParams(location.search); +window.executor = new Executor(params.get("key")); +</script> diff --git a/testing/web-platform/tests/preload/resources/prefetch-helper.js b/testing/web-platform/tests/preload/resources/prefetch-helper.js new file mode 100644 index 0000000000..cf0e0d583c --- /dev/null +++ b/testing/web-platform/tests/preload/resources/prefetch-helper.js @@ -0,0 +1,21 @@ +async function get_prefetch_info(href) { + const response = await fetch(`${href}&mode=info`, {mode: "cors"}); + return await response.json(); +} + +async function prefetch(p = {}, t) { + const link = document.createElement("link"); + link.rel = "prefetch"; + if (p.crossOrigin) + link.setAttribute("crossorigin", p.crossOrigin); + const uid = token(); + const params = new URLSearchParams(); + params.set("key", uid); + for (const key in p) + params.set(key, p[key]); + const origin = p.origin || ''; + link.href = `${origin}/preload/resources/prefetch-info.py?${params.toString()}`; + document.head.appendChild(link); + while (!(await get_prefetch_info(link.href)).length) { } + return {href: link.href, uid}; +} diff --git a/testing/web-platform/tests/preload/resources/prefetch-info.py b/testing/web-platform/tests/preload/resources/prefetch-info.py new file mode 100644 index 0000000000..04d942ba05 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/prefetch-info.py @@ -0,0 +1,37 @@ +import os +from wptserve.utils import isomorphic_encode +from json import dumps, loads + +def main(request, response): + key = request.GET.first(b"key").decode("utf8") + mode = request.GET.first(b"mode", "content") + status = int(request.GET.first(b"status", b"200")) + stash = request.server.stash + cors = request.GET.first(b"cors", "true") + if cors == "true" or mode == b"info": + response.headers.set(b"Access-Control-Allow-Origin", b"*") + + response.status = status + with stash.lock: + requests = loads(stash.take(key) or '[]') + if mode == b"info": + response.headers.set(b"Content-Type", "application/json") + json_reqs = dumps(requests) + response.content = json_reqs + stash.put(key, json_reqs) + return + else: + headers = {} + for header, value in request.headers.items(): + headers[header.decode("utf8")] = value[0].decode("utf8") + path = request.url + requests.append({"headers": headers, "url": request.url}) + stash.put(key, dumps(requests)) + + response.headers.set(b"Content-Type", request.GET.first(b"type", "text/plain")) + response.headers.set(b"Cache-Control", request.GET.first(b"cache-control", b"max-age: 604800")) + if b"file" in request.GET: + path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), os.path.basename(request.GET.first(b"file"))) + response.content = open(path, mode=u'rb').read() + else: + return request.GET.first(b"content", "123") diff --git a/testing/web-platform/tests/preload/resources/preload_helper.js b/testing/web-platform/tests/preload/resources/preload_helper.js new file mode 100644 index 0000000000..5b7a6eb52b --- /dev/null +++ b/testing/web-platform/tests/preload/resources/preload_helper.js @@ -0,0 +1,60 @@ +function stashPutUrl(token) { + return `/preload/resources/stash-put.py?key=${token}`; +} + +function encodedStashPutUrl(token) { + return encodeURIComponent(stashPutUrl(token)); +} + +async function hasArrivedAtServer(token) { + const res = await fetch(`/preload/resources/stash-take.py?key=${token}`); + assert_true(res.status === 200 || res.status === 404, + 'status must be either 200 or 404'); + return res.status === 200; +} + +function verifyPreloadAndRTSupport() +{ + var link = window.document.createElement("link"); + assert_true(link.relList && link.relList.supports("preload"), "Preload not supported"); + assert_true(!!window.PerformanceResourceTiming, "ResourceTiming not supported"); +} + +function getAbsoluteURL(url) +{ + return new URL(url, location.href).href; +} + +function verifyNumberOfResourceTimingEntries(url, number) +{ + assert_equals(numberOfResourceTimingEntries(url), number, url); +} + +function numberOfResourceTimingEntries(url) +{ + return performance.getEntriesByName(getAbsoluteURL(url)).length; +} + +// Verifies that the resource is loaded, but not downloaded from network +// more than once. This can be used to verify that a preloaded resource is +// not downloaded again when used. +function verifyLoadedAndNoDoubleDownload(url) { + var entries = performance.getEntriesByName(getAbsoluteURL(url)); + // UA may create separate RT entries for preload and normal load, + // so we just check (entries.length > 0). + assert_greater_than(entries.length, 0, url + ' should be loaded'); + + var numDownloads = 0; + entries.forEach(entry => { + // transferSize is zero if the resource is loaded from cache. + if (entry.transferSize > 0) { + numDownloads++; + } + }); + // numDownloads can be zero if the resource was already cached before running + // the test (for example, when the test is running repeatedly without + // clearing cache between runs). + assert_less_than_equal( + numDownloads, 1, + url + ' should be downloaded from network at most once'); +} diff --git a/testing/web-platform/tests/preload/resources/slow-exec.js b/testing/web-platform/tests/preload/resources/slow-exec.js new file mode 100644 index 0000000000..3b37da4ef4 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/slow-exec.js @@ -0,0 +1,3 @@ +window.didLoadModule = false; +await new Promise(r => setTimeout(t, 5000)); +window.didLoadModule = true; diff --git a/testing/web-platform/tests/preload/resources/sound_5.oga b/testing/web-platform/tests/preload/resources/sound_5.oga Binary files differnew file mode 100644 index 0000000000..239ad2bd08 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/sound_5.oga diff --git a/testing/web-platform/tests/preload/resources/sound_5.oga.sub.headers b/testing/web-platform/tests/preload/resources/sound_5.oga.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/sound_5.oga.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/square.png b/testing/web-platform/tests/preload/resources/square.png Binary files differnew file mode 100644 index 0000000000..01c9666a8d --- /dev/null +++ b/testing/web-platform/tests/preload/resources/square.png diff --git a/testing/web-platform/tests/preload/resources/square.png.sub.headers b/testing/web-platform/tests/preload/resources/square.png.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/square.png.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 diff --git a/testing/web-platform/tests/preload/resources/stash-put.py b/testing/web-platform/tests/preload/resources/stash-put.py new file mode 100644 index 0000000000..f4bc87940e --- /dev/null +++ b/testing/web-platform/tests/preload/resources/stash-put.py @@ -0,0 +1,20 @@ +from wptserve.utils import isomorphic_decode + +def main(request, response): + if request.method == u'OPTIONS': + # CORS preflight + response.headers.set(b'Access-Control-Allow-Origin', b'*') + response.headers.set(b'Access-Control-Allow-Methods', b'*') + response.headers.set(b'Access-Control-Allow-Headers', b'*') + return 'done' + + url_dir = u'/'.join(request.url_parts.path.split(u'/')[:-1]) + u'/' + key = request.GET.first(b"key") + if b"value" in request.GET: + value = request.GET.first(b"value") + else: + value = b"value" + # value here must be a text string. It will be json.dump()'ed in stash-take.py. + request.server.stash.put(key, isomorphic_decode(value), url_dir) + response.headers.set(b'Access-Control-Allow-Origin', b'*') + return "done" diff --git a/testing/web-platform/tests/preload/resources/stash-take.py b/testing/web-platform/tests/preload/resources/stash-take.py new file mode 100644 index 0000000000..9977197cae --- /dev/null +++ b/testing/web-platform/tests/preload/resources/stash-take.py @@ -0,0 +1,14 @@ +from wptserve.handlers import json_handler + + +@json_handler +def main(request, response): + dir = u'/'.join(request.url_parts.path.split(u'/')[:-1]) + u'/' + key = request.GET.first(b"key") + response.headers.set(b'Access-Control-Allow-Origin', b'*') + value = request.server.stash.take(key, dir) + if value is None: + response.status = 404 + return 'No entry is found' + response.status = 200 + return value diff --git a/testing/web-platform/tests/preload/resources/syntax-error.js b/testing/web-platform/tests/preload/resources/syntax-error.js new file mode 100644 index 0000000000..471697a43b --- /dev/null +++ b/testing/web-platform/tests/preload/resources/syntax-error.js @@ -0,0 +1 @@ +;-) diff --git a/testing/web-platform/tests/preload/resources/white.mp4 b/testing/web-platform/tests/preload/resources/white.mp4 Binary files differnew file mode 100644 index 0000000000..ef609e4281 --- /dev/null +++ b/testing/web-platform/tests/preload/resources/white.mp4 diff --git a/testing/web-platform/tests/preload/resources/white.mp4.sub.headers b/testing/web-platform/tests/preload/resources/white.mp4.sub.headers new file mode 100644 index 0000000000..360e6686bf --- /dev/null +++ b/testing/web-platform/tests/preload/resources/white.mp4.sub.headers @@ -0,0 +1 @@ +Cache-Control: max-age=1000 |