Skip to content

Commit

Permalink
Bug 1449107 [wpt PR 10192] - Add tests for Request.isReloadNavigation…
Browse files Browse the repository at this point in the history
…, a=testonly

Automatic update from web-platform-testsAdd tests for Request.isReloadNavigation

See whatwg/fetch#685, whatwg/html#3592, and discussion in w3c/ServiceWorker#1167.
--

wpt-commits: 58ee169367245c6fe5edc01177eac68f76c12f4a
wpt-pr: 10192
  • Loading branch information
yutakahirano authored and jgraham committed May 2, 2018
1 parent 05dbbc9 commit acd8e36
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 4 deletions.
84 changes: 80 additions & 4 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -15601,6 +15601,18 @@
{}
]
],
"service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html": [
[
"/service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html",
{}
]
],
"service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html": [
[
"/service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html",
{}
]
],
"service-workers/service-worker/fetch-event-within-sw-manual.https.html": [
[
"/service-workers/service-worker/fetch-event-within-sw-manual.https.html",
Expand Down Expand Up @@ -274056,6 +274068,16 @@
{}
]
],
"fetch/api/request/resources/hello.txt": [
[
{}
]
],
"fetch/api/request/resources/request-reset-attributes-worker.js": [
[
{}
]
],
"fetch/api/resources/authentication.py": [
[
{}
Expand Down Expand Up @@ -293926,6 +293948,11 @@
{}
]
],
"service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js": [
[
{}
]
],
"service-workers/cache-storage/resources/common-worker.js": [
[
{}
Expand Down Expand Up @@ -294876,6 +294903,11 @@
{}
]
],
"service-workers/service-worker/resources/install-worker.html": [
[
{}
]
],
"service-workers/service-worker/resources/interfaces-idls.js": [
[
{}
Expand Down Expand Up @@ -329587,6 +329619,12 @@
{}
]
],
"fetch/api/request/request-reset-attributes.https.html": [
[
"/fetch/api/request/request-reset-attributes.https.html",
{}
]
],
"fetch/api/request/request-structure.html": [
[
"/fetch/api/request/request-structure.html",
Expand Down Expand Up @@ -364281,6 +364319,12 @@
}
]
],
"service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html": [
[
"/service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html",
{}
]
],
"service-workers/cache-storage/serviceworker/cache-keys.https.html": [
[
"/service-workers/cache-storage/serviceworker/cache-keys.https.html",
Expand Down Expand Up @@ -558319,7 +558363,7 @@
"testharness"
],
"fetch/api/request/request-idl.html": [
"679ff0c44a0ece1c480f5296e738b7a15f4c79cb",
"a49521fba96ca40676063dd3d57480618a4d6fc3",
"testharness"
],
"fetch/api/request/request-init-001.sub.html": [
Expand All @@ -558342,8 +558386,12 @@
"e6c2afd6cef41d358016d4d021b7c3e0e1185704",
"testharness"
],
"fetch/api/request/request-reset-attributes.https.html": [
"132b917c77c61230f7c5e84c3c9cafe4d1f0b565",
"testharness"
],
"fetch/api/request/request-structure.html": [
"b01d5ae0d56c22d2b86e0efd2cf64ac938770b11",
"2af02f3ecf8449c91f2f1d28effc3478a4bfc235",
"testharness"
],
"fetch/api/request/request-type-attribute-historical.html": [
Expand All @@ -558354,6 +558402,14 @@
"3cd7d5191fe33b2f2dab571a4b006d8332fdf42e",
"support"
],
"fetch/api/request/resources/hello.txt": [
"f572d396fae9206628714fb2ce00f72e94f2258f",
"support"
],
"fetch/api/request/resources/request-reset-attributes-worker.js": [
"cde1835ecc64d416df0a25a8cdd1d2bcc3f38431",
"support"
],
"fetch/api/request/url-encoding.html": [
"1f8a8e00c5c1ba5ae9995ca6561801479b487b3a",
"testharness"
Expand Down Expand Up @@ -599738,6 +599794,10 @@
"0ddb4f1cf84729ed673295719ec58a3e5d600a12",
"support"
],
"service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js": [
"27d9ec7d86fcdb50e892321283d36143c5066461",
"support"
],
"service-workers/cache-storage/resources/common-worker.js": [
"7683f075e231ee17b3909f5cf96d727908823577",
"support"
Expand Down Expand Up @@ -599818,6 +599878,10 @@
"6484fca817f556be3ffead18f162649c0fbfba30",
"testharness"
],
"service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html": [
"ce03773200d0dc76199b0ea5353bc44be4e86793",
"testharness"
],
"service-workers/cache-storage/serviceworker/cache-keys.https.html": [
"c1f638bea1f897b086ce403b7a87fe4fd7b77b25",
"testharness"
Expand Down Expand Up @@ -600202,6 +600266,14 @@
"00c90429203c85ae8f10a6a6604cdf9619524f06",
"testharness"
],
"service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html": [
"9f69732ecf50608ea2695e2fb348d8dff6df6791",
"manual"
],
"service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html": [
"109c975e4c31e5e880b3308967c05623a76aacb4",
"manual"
],
"service-workers/service-worker/fetch-event-network-error.https.html": [
"07b81a0af207ee0723a9abae90e49482701f8935",
"testharness"
Expand Down Expand Up @@ -600259,7 +600331,7 @@
"testharness"
],
"service-workers/service-worker/fetch-event.https.html": [
"1a7e0410ef0e486738ca7c76542c2612228d5bd2",
"cf2d0ef7275fd08bd0fbd2dde4c8c4ee4a2452d6",
"testharness"
],
"service-workers/service-worker/fetch-frame-resource.https.html": [
Expand Down Expand Up @@ -601019,7 +601091,7 @@
"support"
],
"service-workers/service-worker/resources/fetch-event-test-worker.js": [
"bba096216d8fbca6d4ddb6b7e9352a095a5e5db8",
"2cd3893314f0296b4c8260f250cc87b570c7d692",
"support"
],
"service-workers/service-worker/resources/fetch-event-within-sw-worker.js": [
Expand Down Expand Up @@ -601214,6 +601286,10 @@
"fd486a19472f142bbd2909929a67ac3d39adc845",
"support"
],
"service-workers/service-worker/resources/install-worker.html": [
"0f2d441a80fb4641af35ad851e86690b7c02d1f7",
"support"
],
"service-workers/service-worker/resources/interfaces-idls.js": [
"2d3ae3bdd1be17a2871aa3af2009daaacf43d3db",
"support"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
readonly attribute RequestCache cache;
readonly attribute RequestRedirect redirect;
readonly attribute DOMString integrity;
readonly attribute boolean isReloadNavigation;

[NewObject] Request clone();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<body>
<script>
const worker = 'resources/request-reset-attributes-worker.js';

promise_test(async (t) => {
const scope = 'resources/hello.txt?name=isReloadNavigation';
let frame;
let reg;

try {
reg = await service_worker_unregister_and_register(t, worker, scope);
await wait_for_state(t, reg.installing, 'activated');
frame = await with_iframe(scope);
assert_equals(frame.contentDocument.body.textContent,
'old: false, new: false');
await new Promise((resolve) => {
frame.onload = resolve;
frame.contentWindow.location.reload();
});
assert_equals(frame.contentDocument.body.textContent,
'old: true, new: false');
} finally {
if (frame) {
frame.remove();
}
if (reg) {
await reg.unregister();
}
}
}, 'Request.isReloadNavigation is reset with non-empty RequestInit');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
newValue = true;
break;

case "isReloadNavigation":
defaultValue = false;
newValue = true;
break;

default:
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
self.addEventListener('fetch', (event) => {
const params = new URL(event.request.url).searchParams;
if (params.has('ignore')) {
return;
}
if (!params.has('name')) {
event.respondWith(Promise.reject(TypeError('No name is provided.')));
return;
}

const name = params.get('name');
const old_attribute = event.request[name];
// If any of |init|'s member is present...
const init = {cache: 'no-store'}
const new_attribute = (new Request(event.request, init))[name];

event.respondWith(
new Response(`old: ${old_attribute}, new: ${new_attribute}`));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
self.addEventListener('fetch', (event) => {
const params = new URL(event.request.url).searchParams;
if (params.has('ignore')) {
return;
}
if (!params.has('name')) {
event.respondWith(Promise.reject(TypeError('No name is provided.')));
return;
}

event.respondWith(Promise.resolve().then(async () => {
const name = params.get('name');
await caches.delete('foo');
const cache = await caches.open('foo');
await cache.put(event.request, new Response('hello'));
const keys = await cache.keys();

const original = event.request[name];
const stored = keys[0][name];
return new Response(`original: ${original}, stored: ${stored}`);
}));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<title>Cache.keys (checking request attributes that can be set only on service workers)</title>
<link rel="help" href="https://w3c.github.io/ServiceWorker/#cache-keys">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../service-worker/resources/test-helpers.sub.js"></script>
<script>
const worker = '../resources/cache-keys-attributes-for-service-worker.js';

promise_test(async (t) => {
const scope = '../resources/blank.html?name=isReloadNavigation';
let frame;
let reg;

try {
reg = await service_worker_unregister_and_register(t, worker, scope);
await wait_for_state(t, reg.installing, 'activated');
frame = await with_iframe(scope);
assert_equals(frame.contentDocument.body.textContent,
'original: false, stored: false');
await new Promise((resolve) => {
frame.onload = resolve;
frame.contentWindow.location.reload();
});
assert_equals(frame.contentDocument.body.textContent,
'original: true, stored: true');
} finally {
if (frame) {
frame.remove();
}
if (reg) {
await reg.unregister();
}
}
}, 'Request.IsReloadNavigation should persist.');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<body>
<script>
const worker = 'resources/fetch-event-test-worker.js';

promise_test(async (t) => {
const scope = 'resources/simple.html?isReloadNavigation';

const reg = await service_worker_unregister_and_register(t, worker, scope);
await wait_for_state(t, reg.installing, 'activated');
const frame = await with_iframe(scope);
assert_equals(frame.contentDocument.body.textContent,
'method = GET, isReloadNavigation = false');
await new Promise((resolve) => {
frame.addEventListener('load', resolve);
frame.contentDocument.body.innerText =
'Reload this frame manually!';
});
assert_equals(frame.contentDocument.body.textContent,
'method = GET, isReloadNavigation = true');
frame.remove();
await reg.unregister();
}, 'FetchEvent#request.isReloadNavigation is true for manual reload.');

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<body>
<p>Click <a href="resources/install-worker.html?isReloadNavigation&script=fetch-event-test-worker.js">this link</a>.
Once you see &quot;method = GET,...&quot; in the page, reload the page.
You will see &quot;method = GET, isReloadNavigation = true&quot;.
</p>
</body>
</html>
Loading

0 comments on commit acd8e36

Please sign in to comment.