-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1449107 [wpt PR 10192] - Add tests for Request.isReloadNavigation…
…, 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 UltraBlame original commit: 96c5380b8719433164c1c86dac5b4c8db50c1966
- Loading branch information
Showing
13 changed files
with
411 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
testing/web-platform/tests/fetch/api/request/request-reset-attributes.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/fetch/api/request/resources/hello.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
19 changes: 19 additions & 0 deletions
19
testing/web-platform/tests/fetch/api/request/resources/request-reset-attributes-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
|
||
const init = {cache: 'no-store'} | ||
const new_attribute = (new Request(event.request, init))[name]; | ||
|
||
event.respondWith( | ||
new Response(`old: ${old_attribute}, new: ${new_attribute}`)); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...tests/service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
})); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...e-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
31 changes: 31 additions & 0 deletions
31
.../service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
8 changes: 8 additions & 0 deletions
8
...m/tests/service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "method = GET,..." in the page, reload the page. | ||
You will see "method = GET, isReloadNavigation = true". | ||
</p> | ||
</body> | ||
</html> |
Oops, something went wrong.