Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPT for deliveryType: 'cache' #36072

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions resource-timing/delivery-type.tentative.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// META: global=window,worker
// META: script=/resource-timing/resources/resource-loaders.js

let url = new URL(
'/resource-timing/resources/cacheable-and-validated.py' +
'?content=somecontent',
location.href).href;

const accumulateEntries = () => {
return new Promise(resolve => {
const po = new PerformanceObserver(list => {
resolve(list);
});
po.observe({type: "resource", buffered: true});
});
};

const checkDeliveryType = list => {
const entries = list.getEntriesByName(url);
assert_equals(entries.length, 3, 'Wrong number of entries');
let seenCount = 0;
for (let entry of entries) {
if (seenCount === 0) {
// 200 response (`cacheMode` is an empty string)
assert_equals(entry.deliveryType, "",
"Expect empty deliveryType for 200 response.");
} else if (seenCount === 1 || seenCount === 2) {
// Cached response (`cacheMode` is "local") or 304 response (`cacheMode`
// is "validated").
assert_equals(entry.deliveryType, "cache",
"Expect 'cache' deliveryType for cached or 304 response.");
} else {
assert_unreached('Too many matching entries');
}
++seenCount;
}
};

// TODO(crbug/1358591): Rename this file from "tentative" once
// `w3c/resource-timing#343` is merged.
promise_test(() => {
// Use a different URL every time so that the cache behaviour does not
// depend on execution order.
url = load.cache_bust(url);
const eatBody = response => response.arrayBuffer();
const mustRevalidate = {headers: {'Cache-Control': 'max-age=0'}};
return fetch(url)
.then(eatBody)
.then(() => fetch(url))
.then(eatBody)
.then(() => fetch(url, mustRevalidate))
.then(eatBody)
.then(accumulateEntries)
.then(checkDeliveryType);
}, 'PerformanceResourceTiming deliveryType test');