summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resource-timing/sizes-redirect.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/resource-timing/sizes-redirect.any.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/resource-timing/sizes-redirect.any.js')
-rw-r--r--testing/web-platform/tests/resource-timing/sizes-redirect.any.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/testing/web-platform/tests/resource-timing/sizes-redirect.any.js b/testing/web-platform/tests/resource-timing/sizes-redirect.any.js
new file mode 100644
index 0000000000..e483a4d409
--- /dev/null
+++ b/testing/web-platform/tests/resource-timing/sizes-redirect.any.js
@@ -0,0 +1,62 @@
+// META: global=window,worker
+// META: script=/common/get-host-info.sub.js
+// META: script=/resource-timing/resources/sizes-helper.js
+
+const baseUrl =
+ new URL('/resource-timing/resources/TAOResponse.py?tao=wildcard', location.href).href;
+const expectedSize = 4;
+
+const hostInfo = get_host_info();
+performance.clearResourceTimings();
+
+const accumulateEntry = () => {
+ return new Promise(resolve => {
+ const po = new PerformanceObserver(list => {
+ resolve(list);
+ });
+ po.observe({type: "resource", buffered: true});
+ });
+};
+
+const checkResourceSizes = () => {
+ const entries = performance.getEntriesByType('resource');
+ for (let entry of entries) {
+ checkSizeFields(entry, expectedSize, expectedSize + headerSize);
+ }
+}
+
+const redirectUrl = (redirectSourceOrigin, allowOrigin, targetUrl) => {
+ return redirectSourceOrigin +
+ '/resource-timing/resources/redirect-cors.py?allow_origin=' +
+ encodeURIComponent(allowOrigin) +
+ '&timing_allow_origin=*' +
+ '&location=' + encodeURIComponent(targetUrl);
+}
+
+promise_test(() => {
+ // Use a different URL every time so that the cache behaviour does not
+ // depend on execution order.
+ const directUrl = cacheBustUrl(baseUrl);
+ const sameOriginRedirect = redirectUrl(hostInfo.ORIGIN, '*', directUrl);
+ const crossOriginRedirect = redirectUrl(hostInfo.REMOTE_ORIGIN,
+ hostInfo.ORIGIN, directUrl);
+ const mixedRedirect = redirectUrl(hostInfo.REMOTE_ORIGIN,
+ hostInfo.ORIGIN, sameOriginRedirect);
+ const complexRedirect = redirectUrl(hostInfo.ORIGIN,
+ hostInfo.REMOTE_ORIGIN, mixedRedirect);
+ let eatBody = response => response.arrayBuffer();
+ return fetch(directUrl)
+ .then(eatBody)
+ .then(() => fetch(sameOriginRedirect))
+ .then(eatBody)
+ .then(() => fetch(crossOriginRedirect))
+ .then(eatBody)
+ .then(() => fetch(mixedRedirect))
+ .then(eatBody)
+ .then(() => fetch(complexRedirect))
+ .then(eatBody)
+ .then(accumulateEntry)
+ .then(checkResourceSizes);
+}, 'PerformanceResourceTiming sizes Fetch with redirect test');
+
+done();