summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/fetching
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/css/fetching
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/fetching')
-rw-r--r--testing/web-platform/tests/css/fetching/fetch-resources.sub.html102
-rw-r--r--testing/web-platform/tests/css/fetching/support/echo-css.py7
-rw-r--r--testing/web-platform/tests/css/fetching/support/echo-headers.py24
-rw-r--r--testing/web-platform/tests/css/fetching/support/echo-helper.js19
4 files changed, 152 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/fetching/fetch-resources.sub.html b/testing/web-platform/tests/css/fetching/fetch-resources.sub.html
new file mode 100644
index 0000000000..03c3e346f1
--- /dev/null
+++ b/testing/web-platform/tests/css/fetching/fetch-resources.sub.html
@@ -0,0 +1,102 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test various interactions between fetch, service-workers and resource timing</title>
+<meta charset="utf-8" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="support/echo-helper.js"></script>
+<link rel=help href="https://github.com/w3c/csswg-drafts/pull/6715">
+</head>
+
+<body>
+<script>
+ const image_url = '/css/support/1x1-green.png'
+ const font_url = '/fonts/pass.woff'
+ const stylesheet_url = '/css/support/a-green.css'
+
+ async function load_image({url, prop, uid}, t) {
+ const element = document.createElement('div');
+ const echo = get_resource_echo_url(uid, url)
+ element.style[prop] = `url(${echo})`
+ document.body.appendChild(element);
+ t.add_cleanup(() => element.remove());
+ await wait_for_resource(echo);
+ const headers = await get_headers(uid);
+ return headers[url]
+ }
+
+ async function load_font({url, uid}, t) {
+ const echo = get_resource_echo_url(uid, url)
+ const style = `
+ @font-face { font-family: "SomeFont"; src: url(${echo}); }
+ `
+ const styleElement = document.createElement('style')
+ styleElement.innerHTML = style
+ document.head.appendChild(styleElement)
+ const element = document.createElement('p')
+ element.innerText = "SomeFont"
+ element.style.fontFamily = 'SomeFont'
+ document.body.appendChild(element)
+ t.add_cleanup(() => element.remove())
+ t.add_cleanup(() => styleElement.remove())
+ await wait_for_resource(echo);
+ const headers = await get_headers(uid);
+ return headers[url]
+ }
+
+ async function load_stylesheet({url, uid}, t) {
+ const echo = get_resource_echo_url(uid, url)
+ const styleElement = document.createElement('style')
+ styleElement.innerHTML = `@import "${echo}"`
+ document.head.appendChild(styleElement)
+ t.add_cleanup(() => styleElement.remove())
+ await wait_for_resource(echo);
+ const headers = await get_headers(uid);
+ return headers[url]
+ }
+
+ function load_style(text, host, t) {
+ const styleElement = document.createElement('style');
+ const styleURL = `${host || window.origin}/css/fetching/support/echo-css.py?content=${encodeURIComponent(text)}`;
+ styleElement.innerHTML = `@import "${styleURL}"`;
+ document.head.appendChild(styleElement);
+ t.add_cleanup(() => styleElement.remove());
+ return styleURL
+ }
+
+ function extract_cors_mode(result) {
+ const fetchMode = result['sec-fetch-mode'];
+ if (fetchMode)
+ return fetchMode;
+
+ return Reflect.has(result, 'origin') ? 'cors' : 'no-cors';
+ }
+
+ promise_test(async t => {
+ const uid = "{{uuid()}}";
+ const result = await load_image({uid, url: image_url, prop: 'background'}, t)
+ assert_equals(extract_cors_mode(result), 'no-cors');
+ }, 'Background images should fetch with no-cors');
+
+ promise_test(async t => {
+ const uid = "{{uuid()}}";
+ const result = await load_image({uid, url: image_url, prop: 'shape-outside'}, t)
+ assert_equals(extract_cors_mode(result), 'cors');
+ }, 'Shape images should fetched with cors');
+
+ promise_test(async t => {
+ const uid = "{{uuid()}}";
+ const result = await load_font({uid, url: font_url}, t)
+ assert_equals(extract_cors_mode(result), 'cors');
+ }, "WebFonts should be fetched with cors")
+
+ promise_test(async t => {
+ const uid = "{{uuid()}}";
+ const result = await load_stylesheet({uid, url: stylesheet_url}, t)
+ assert_equals(extract_cors_mode(result), 'no-cors');
+ }, "CSS imports should be fetched without cors")
+</script>
+
+</body>
+</html>
diff --git a/testing/web-platform/tests/css/fetching/support/echo-css.py b/testing/web-platform/tests/css/fetching/support/echo-css.py
new file mode 100644
index 0000000000..bbfd3f07c0
--- /dev/null
+++ b/testing/web-platform/tests/css/fetching/support/echo-css.py
@@ -0,0 +1,7 @@
+import sys
+import json
+
+def main(request, response):
+ content = request.GET.first(b"content", None)
+ response.headers.set(b"Content-Type", "text/css");
+ return content
diff --git a/testing/web-platform/tests/css/fetching/support/echo-headers.py b/testing/web-platform/tests/css/fetching/support/echo-headers.py
new file mode 100644
index 0000000000..9feb6f91a4
--- /dev/null
+++ b/testing/web-platform/tests/css/fetching/support/echo-headers.py
@@ -0,0 +1,24 @@
+import sys
+import json
+
+def main(request, response):
+ token = request.GET.first(b"token", None)
+ location = request.GET.first(b"location", None)
+ store = request.server.stash.take(token)
+ headers = {}
+ if (location == b"echo"):
+ return store
+
+ if (store == None):
+ store = {}
+ else:
+ store = json.loads(store)
+
+ for header in request.headers:
+ headers[header.decode('utf-8')] = request.headers.get(header).decode('utf-8')
+
+ store[location.decode('utf-8')] = headers
+
+ request.server.stash.put(token, json.dumps(store))
+ response.status = 302
+ response.headers.set(b"Location", location)
diff --git a/testing/web-platform/tests/css/fetching/support/echo-helper.js b/testing/web-platform/tests/css/fetching/support/echo-helper.js
new file mode 100644
index 0000000000..15bec65033
--- /dev/null
+++ b/testing/web-platform/tests/css/fetching/support/echo-helper.js
@@ -0,0 +1,19 @@
+function get_resource_echo_url(uid, url) {
+ return `/css/fetching/support/echo-headers.py?token=${uid}&location=${url}`
+}
+
+function wait_for_resource(url) {
+ return new Promise(resolve => {
+ const po = new PerformanceObserver(list => {
+ const entries = list.getEntries();
+ if (entries.find(e => e.name.includes(url)))
+ resolve();
+ })
+ po.observe({type: "resource", buffered: true});
+ });
+}
+
+async function get_headers(uid) {
+ return await (await fetch(`/css/fetching/support/echo-headers.py?token=${uid}&location=echo`)).json()
+}
+