From acd8e361b2b8d8d4098595a47f86ee43ddb4167e Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Tue, 1 May 2018 15:44:13 +0000 Subject: [PATCH] Bug 1449107 [wpt PR 10192] - Add tests for Request.isReloadNavigation, a=testonly Automatic update from web-platform-testsAdd tests for Request.isReloadNavigation See https://github.com/whatwg/fetch/pull/685, https://github.com/whatwg/html/pull/3592, and discussion in https://github.com/w3c/ServiceWorker/issues/1167. -- wpt-commits: 58ee169367245c6fe5edc01177eac68f76c12f4a wpt-pr: 10192 --- testing/web-platform/meta/MANIFEST.json | 84 ++++++++++- .../tests/fetch/api/request/request-idl.html | 1 + .../request-reset-attributes.https.html | 36 +++++ .../fetch/api/request/request-structure.html | 5 + .../fetch/api/request/resources/hello.txt | 1 + .../request-reset-attributes-worker.js | 19 +++ ...ache-keys-attributes-for-service-worker.js | 22 +++ ...s-attributes-for-service-worker.https.html | 36 +++++ ...reload-iframe-navigation-manual.https.html | 31 ++++ ...ent-is-reload-navigation-manual.https.html | 8 + .../service-worker/fetch-event.https.html | 141 ++++++++++++++++++ .../resources/fetch-event-test-worker.js | 9 ++ .../resources/install-worker.html | 22 +++ 13 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 testing/web-platform/tests/fetch/api/request/request-reset-attributes.https.html create mode 100644 testing/web-platform/tests/fetch/api/request/resources/hello.txt create mode 100644 testing/web-platform/tests/fetch/api/request/resources/request-reset-attributes-worker.js create mode 100644 testing/web-platform/tests/service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js create mode 100644 testing/web-platform/tests/service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html create mode 100644 testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html create mode 100644 testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html create mode 100644 testing/web-platform/tests/service-workers/service-worker/resources/install-worker.html diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index d4e9b8467f121..3c8ba36729fc0 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -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", @@ -274056,6 +274068,16 @@ {} ] ], + "fetch/api/request/resources/hello.txt": [ + [ + {} + ] + ], + "fetch/api/request/resources/request-reset-attributes-worker.js": [ + [ + {} + ] + ], "fetch/api/resources/authentication.py": [ [ {} @@ -293926,6 +293948,11 @@ {} ] ], + "service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js": [ + [ + {} + ] + ], "service-workers/cache-storage/resources/common-worker.js": [ [ {} @@ -294876,6 +294903,11 @@ {} ] ], + "service-workers/service-worker/resources/install-worker.html": [ + [ + {} + ] + ], "service-workers/service-worker/resources/interfaces-idls.js": [ [ {} @@ -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", @@ -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", @@ -558319,7 +558363,7 @@ "testharness" ], "fetch/api/request/request-idl.html": [ - "679ff0c44a0ece1c480f5296e738b7a15f4c79cb", + "a49521fba96ca40676063dd3d57480618a4d6fc3", "testharness" ], "fetch/api/request/request-init-001.sub.html": [ @@ -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": [ @@ -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" @@ -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" @@ -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" @@ -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" @@ -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": [ @@ -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": [ @@ -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" diff --git a/testing/web-platform/tests/fetch/api/request/request-idl.html b/testing/web-platform/tests/fetch/api/request/request-idl.html index f7833779ce25a..2f1279ab0fe30 100644 --- a/testing/web-platform/tests/fetch/api/request/request-idl.html +++ b/testing/web-platform/tests/fetch/api/request/request-idl.html @@ -43,6 +43,7 @@ readonly attribute RequestCache cache; readonly attribute RequestRedirect redirect; readonly attribute DOMString integrity; + readonly attribute boolean isReloadNavigation; [NewObject] Request clone(); }; diff --git a/testing/web-platform/tests/fetch/api/request/request-reset-attributes.https.html b/testing/web-platform/tests/fetch/api/request/request-reset-attributes.https.html new file mode 100644 index 0000000000000..ba04d19a8776d --- /dev/null +++ b/testing/web-platform/tests/fetch/api/request/request-reset-attributes.https.html @@ -0,0 +1,36 @@ + + + + + + + diff --git a/testing/web-platform/tests/fetch/api/request/request-structure.html b/testing/web-platform/tests/fetch/api/request/request-structure.html index ccdb707795c16..3f82e9c448b0d 100644 --- a/testing/web-platform/tests/fetch/api/request/request-structure.html +++ b/testing/web-platform/tests/fetch/api/request/request-structure.html @@ -99,6 +99,11 @@ newValue = true; break; + case "isReloadNavigation": + defaultValue = false; + newValue = true; + break; + default: return; } diff --git a/testing/web-platform/tests/fetch/api/request/resources/hello.txt b/testing/web-platform/tests/fetch/api/request/resources/hello.txt new file mode 100644 index 0000000000000..ce013625030ba --- /dev/null +++ b/testing/web-platform/tests/fetch/api/request/resources/hello.txt @@ -0,0 +1 @@ +hello diff --git a/testing/web-platform/tests/fetch/api/request/resources/request-reset-attributes-worker.js b/testing/web-platform/tests/fetch/api/request/resources/request-reset-attributes-worker.js new file mode 100644 index 0000000000000..4b264ca2fec3b --- /dev/null +++ b/testing/web-platform/tests/fetch/api/request/resources/request-reset-attributes-worker.js @@ -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}`)); + }); diff --git a/testing/web-platform/tests/service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js b/testing/web-platform/tests/service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js new file mode 100644 index 0000000000000..ee574d2cb77a7 --- /dev/null +++ b/testing/web-platform/tests/service-workers/cache-storage/resources/cache-keys-attributes-for-service-worker.js @@ -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}`); + })); + }); diff --git a/testing/web-platform/tests/service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html b/testing/web-platform/tests/service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html new file mode 100644 index 0000000000000..20240768edc91 --- /dev/null +++ b/testing/web-platform/tests/service-workers/cache-storage/serviceworker/cache-keys-attributes-for-service-worker.https.html @@ -0,0 +1,36 @@ + +Cache.keys (checking request attributes that can be set only on service workers) + + + + + diff --git a/testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html b/testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html new file mode 100644 index 0000000000000..cf1feccf6e441 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-iframe-navigation-manual.https.html @@ -0,0 +1,31 @@ + + + + + + + + + diff --git a/testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html b/testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html new file mode 100644 index 0000000000000..a349f07c36c22 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/fetch-event-is-reload-navigation-manual.https.html @@ -0,0 +1,8 @@ + + +

Click this link. + Once you see "method = GET,..." in the page, reload the page. + You will see "method = GET, isReloadNavigation = true". +

+ + diff --git a/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html b/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html index 12b09321ed015..02f8d0e4530dd 100644 --- a/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html +++ b/testing/web-platform/tests/service-workers/service-worker/fetch-event.https.html @@ -6,6 +6,9 @@ diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js b/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js index 65025d934093a..a313094cf4441 100644 --- a/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js +++ b/testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-test-worker.js @@ -129,6 +129,14 @@ function handleKeepalive(event) { event.respondWith(new Response(event.request.keepalive)); } +function handleIsReloadNavigation(event) { + const request = event.request; + const body = + `method = ${request.method}, ` + + `isReloadNavigation = ${request.isReloadNavigation}`; + event.respondWith(new Response(body)); +} + self.addEventListener('fetch', function(event) { var url = event.request.url; var handlers = [ @@ -151,6 +159,7 @@ self.addEventListener('fetch', function(event) { { pattern: '?integrity', fn: handleIntegrity }, { pattern: '?request-body', fn: handleRequestBody }, { pattern: '?keepalive', fn: handleKeepalive }, + { pattern: '?isReloadNavigation', fn: handleIsReloadNavigation }, ]; var handler = null; diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/install-worker.html b/testing/web-platform/tests/service-workers/service-worker/resources/install-worker.html new file mode 100644 index 0000000000000..ed20cd4dca6a1 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/resources/install-worker.html @@ -0,0 +1,22 @@ + + + +

Loading...

+ + +