diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index a5439e629e75..87bcd038020a 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -609444,7 +609444,7 @@ "testharness" ], "service-workers/service-worker/fetch-event.https.html": [ - "dfd8525f82292cc3728cc3b1afb2a14e19ef4b43", + "d4ff864f1d5a7896cc748cd4abe10d08c0fb08f9", "testharness" ], "service-workers/service-worker/fetch-frame-resource.https.html": [ 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 8ecf8e6cbe82..ecb1c1422314 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 @@ -10,15 +10,21 @@ function wait(ms) { return new Promise(resolve => step_timeout(resolve, ms)); } -async_test(function(t) { - const scope = 'resources/simple.html?headers'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) +promise_test(async t => { + const scope = 'resources/'; + const registration = + await service_worker_unregister_and_register(t, worker, scope); + await wait_for_state(t, registration.installing, 'activated'); + promise_test(t => { + return registration.unregister(); + }, 'restore global state'); + }, 'global setup'); + +promise_test(t => { + const page_url = 'resources/simple.html?headers'; + return with_iframe(page_url) .then(function(frame) { - t.add_cleanup(function() { frame.remove(); }); + t.add_cleanup(() => { frame.remove(); }); const headers = JSON.parse(frame.contentDocument.body.textContent); const header_names = {}; for (const [name, value] of headers) { @@ -29,20 +35,14 @@ async_test(function(t) { header_names.hasOwnProperty('accept'), 'request includes "Accept" header as inserted by Fetch' ); - - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker headers in the request of a fetch event'); -async_test(function(t) { - var scope = 'resources/simple.html?string'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) +promise_test(t => { + const page_url = 'resources/simple.html?string'; + return with_iframe(page_url) .then(function(frame) { + t.add_cleanup(() => { frame.remove(); }); assert_equals( frame.contentDocument.body.textContent, 'Test string', @@ -55,23 +55,17 @@ async_test(function(t) { frame.contentDocument.characterSet, 'UTF-8', 'The character set of the response created with a string should be UTF-8'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with string'); -async_test(function(t) { - var scope = 'resources/simple.html?string'; +promise_test(t => { + const page_url = 'resources/simple.html?string'; var frame; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope) }) + return with_iframe(page_url) .then(function(f) { frame = f; - return frame.contentWindow.fetch(scope + "#foo") + t.add_cleanup(() => { frame.remove(); }); + return frame.contentWindow.fetch(page_url + "#foo") }) .then(function(response) { return response.text() }) .then(function(text) { @@ -79,58 +73,40 @@ async_test(function(t) { text, 'Test string', 'Service Worker should respond to fetch with a test string'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event using request fragment with string'); -async_test(function(t) { - var scope = 'resources/simple.html?blob'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) - .then(function(frame) { +promise_test(t => { + const page_url = 'resources/simple.html?blob'; + return with_iframe(page_url) + .then(frame => { + t.add_cleanup(() => { frame.remove(); }); assert_equals( frame.contentDocument.body.textContent, 'Test blob', 'Service Worker should respond to fetch with a test string'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with blob body'); -async_test(function(t) { - var scope = 'resources/simple.html?referrer'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) - .then(function(frame) { +promise_test(t => { + const page_url = 'resources/simple.html?referrer'; + return with_iframe(page_url) + .then(frame => { + t.add_cleanup(() => { frame.remove(); }); assert_equals( frame.contentDocument.body.textContent, 'Referrer: ' + document.location.href, 'Service Worker should respond to fetch with the referrer URL'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with the referrer URL'); -async_test(function(t) { - var scope = 'resources/simple.html?clientId'; +promise_test(t => { + const page_url = 'resources/simple.html?clientId'; var frame; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) + return with_iframe(page_url) .then(function(f) { frame = f; + t.add_cleanup(() => { frame.remove(); }); assert_equals( frame.contentDocument.body.textContent, 'Client ID Not Found', @@ -144,61 +120,40 @@ async_test(function(t) { response_text.substr(0, 15), 'Client ID Found', 'Service Worker should respond to fetch with an existing client id'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with an existing client id'); -async_test(function(t) { - var scope = 'resources/simple.html?ignore'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) +promise_test(t => { + const page_url = 'resources/simple.html?ignore'; + return with_iframe(page_url) .then(function(frame) { + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentDocument.body.textContent, 'Here\'s a simple html file.\n', 'Response should come from fallback to native fetch'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker does not respond to fetch event'); -async_test(function(t) { - var scope = 'resources/simple.html?null'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) +promise_test(t => { + const page_url = 'resources/simple.html?null'; + return with_iframe(page_url) .then(function(frame) { + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentDocument.body.textContent, '', 'Response should be the empty string'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with null response body'); -async_test(function(t) { - var scope = 'resources/simple.html?fetch'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) +promise_test(t => { + const page_url = 'resources/simple.html?fetch'; + return with_iframe(page_url) .then(function(frame) { + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentDocument.body.textContent, 'Here\'s an other html file.\n', 'Response should come from fetched other file'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker fetches other file in fetch event'); // Creates a form and an iframe and does a form submission that navigates the @@ -232,82 +187,54 @@ function submit_form(action_url) { } promise_test(t => { - const scope = 'resources/simple.html?form-post'; - let registration; - return service_worker_unregister_and_register(t, worker, scope) - .then(reg => { - registration = reg; - add_completion_callback(() => { reg.unregister(); }); - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(() => { - return submit_form(scope); - }) + const page_url = 'resources/simple.html?form-post'; + return submit_form(page_url) .then(frame => { + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentDocument.body.textContent, 'POST:application/x-www-form-urlencoded:' + 'testName1=testValue1&testName2=testValue2'); - frame.remove(); - return registration.unregister(); }); }, 'Service Worker responds to fetch event with POST form'); promise_test(t => { - // Add '?ignore' to scope so the service worker falls back to network. - const scope = 'resources/echo-content.py?ignore'; - let registration; - return service_worker_unregister_and_register(t, worker, scope) - .then(reg => { - registration = reg; - add_completion_callback(() => { reg.unregister(); }); - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(() => { - return submit_form(scope); - }) + // Add '?ignore' so the service worker falls back to network. + const page_url = 'resources/echo-content.py?ignore'; + return submit_form(page_url) .then(frame => { + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentDocument.body.textContent, 'testName1=testValue1&testName2=testValue2'); - frame.remove(); - return registration.unregister(); }); }, 'Service Worker falls back to network in fetch event with POST form'); -async_test(function(t) { - var scope = 'resources/simple.html?multiple-respond-with'; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) - .then(function(frame) { +promise_test(t => { + const page_url = 'resources/simple.html?multiple-respond-with'; + return with_iframe(page_url) + .then(frame => { + t.add_cleanup(() => { frame.remove(); }); assert_equals( frame.contentDocument.body.textContent, '(0)(1)[InvalidStateError](2)[InvalidStateError]', 'Multiple calls of respondWith must throw InvalidStateErrors.'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Multiple calls of respondWith must throw InvalidStateErrors'); -async_test(function(t) { - var scope = 'resources/simple.html?used-check'; +promise_test(t => { + const page_url = 'resources/simple.html?used-check'; var first_frame; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) + return with_iframe(page_url) .then(function(frame) { assert_equals(frame.contentDocument.body.textContent, 'Here\'s an other html file.\n', 'Response should come from fetched other file'); first_frame = frame; - return with_iframe(scope); + t.add_cleanup(() => { first_frame.remove(); }); + return with_iframe(page_url); }) .then(function(frame) { - // When we access to the scope in the second time, the content of the + t.add_cleanup(() => { frame.remove(); }); + // When we access to the page_url in the second time, the content of the // response is generated inside the ServiceWorker. The body contains // the value of bodyUsed of the first response which is already // consumed by FetchEvent.respondWith method. @@ -315,46 +242,33 @@ async_test(function(t) { frame.contentDocument.body.textContent, 'bodyUsed: true', 'event.respondWith must set the used flag.'); - first_frame.remove(); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker event.respondWith must set the used flag'); -async_test(function(t) { - var scope = 'resources/simple.html?fragment-check'; +promise_test(t => { + const page_url = 'resources/simple.html?fragment-check'; var fragment = '#/some/fragment'; var first_frame; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope + fragment); }) + return with_iframe(page_url + fragment) .then(function(frame) { + t.add_cleanup(() => { frame.remove(); }); assert_equals( frame.contentDocument.body.textContent, 'Fragment Found :' + fragment, 'Service worker should expose URL fragments in request.'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker should expose FetchEvent URL fragments.'); -async_test(function(t) { - var scope = 'resources/simple.html?cache'; +promise_test(t => { + const page_url = 'resources/simple.html?cache'; var frame; var cacheTypes = [ undefined, 'default', 'no-store', 'reload', 'no-cache', 'force-cache', 'only-if-cached' ]; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) + return with_iframe(page_url) .then(function(f) { frame = f; + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentWindow.document.body.textContent, 'default'); var tests = cacheTypes.map(function(type) { return new Promise(function(resolve, reject) { @@ -364,7 +278,7 @@ async_test(function(t) { // requires the mode to be same-origin. init.mode = 'same-origin'; } - return frame.contentWindow.fetch(scope + '=' + type, init) + return frame.contentWindow.fetch(page_url + '=' + type, init) .then(function(response) { return response.text(); }) .then(function(response_text) { var expected = (type === undefined) ? 'default' : type; @@ -391,21 +305,16 @@ async_test(function(t) { }); frame.contentWindow.location.reload(); }); - }) - .then(function() { - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with the correct cache types'); -async_test(function(t) { - var scope = 'resources/simple.html?eventsource'; +promise_test(t => { + const page_url = 'resources/simple.html?eventsource'; var frame; function test_eventsource(opts) { return new Promise(function(resolve, reject) { - var eventSource = new frame.contentWindow.EventSource(scope, opts); + var eventSource = new frame.contentWindow.EventSource(page_url, opts); eventSource.addEventListener('message', function(msg) { eventSource.close(); try { @@ -430,73 +339,54 @@ async_test(function(t) { }); } - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) + return with_iframe(page_url) .then(function(f) { frame = f; + t.add_cleanup(() => { frame.remove(); }); return test_eventsource({ withCredentials: false }); }) .then(function() { return test_eventsource({ withCredentials: true }); - }) - .then(function() { - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker should intercept EventSource'); -async_test(function(t) { - var scope = 'resources/simple.html?integrity'; +promise_test(t => { + const page_url = 'resources/simple.html?integrity'; var frame; var integrity_metadata = 'gs0nqru8KbsrIt5YToQqS9fYao4GQJXtcId610g7cCU='; - service_worker_unregister_and_register(t, worker, scope) - .then(function(reg) { - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(function() { return with_iframe(scope); }) + return with_iframe(page_url) .then(function(f) { frame = f; + t.add_cleanup(() => { frame.remove(); }); // A request has associated integrity metadata (a string). // Unless stated otherwise, it is the empty string. assert_equals( frame.contentDocument.body.textContent, ''); - return frame.contentWindow.fetch(scope, {'integrity': integrity_metadata}); + return frame.contentWindow.fetch(page_url, {'integrity': integrity_metadata}); }) .then(response => { return response.text(); }) .then(response_text => { assert_equals(response_text, integrity_metadata, 'integrity'); - frame.remove(); - return service_worker_unregister_and_done(t, scope); - }) - .catch(unreached_rejection(t)); + }); }, 'Service Worker responds to fetch event with the correct integrity_metadata'); // Test that the service worker can read FetchEvent#body when it is a string. // It responds with request body it read. promise_test(t => { - // Set scope to "?ignore" so the service worker falls back to network + // Set page_url to "?ignore" so the service worker falls back to network // for the main resource request, and add a suffix to avoid colliding // with other tests. - const scope = 'resources/simple.html?ignore-for-request-body-string'; + const page_url = 'resources/simple.html?ignore-for-request-body-string'; let frame; - return service_worker_unregister_and_register(t, worker, scope) - .then(reg => { - add_completion_callback(() => { reg.unregister(); }); - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(() => { - return with_iframe(scope); }) + return with_iframe(page_url) .then(f => { frame = f; + t.add_cleanup(() => { frame.remove(); }); return frame.contentWindow.fetch('simple.html?request-body', { method: 'POST', body: 'i am the request body' @@ -506,7 +396,6 @@ promise_test(t => { return response.text(); }) .then(response_text => { - frame.remove(); assert_equals(response_text, 'i am the request body'); }); }, 'FetchEvent#body is a string'); @@ -514,21 +403,16 @@ promise_test(t => { // Test that the request body is sent to network upon network fallback, // for a string body. promise_test(t => { - // Set scope to "?ignore" so the service worker falls back to network + // Set page_url to "?ignore" so the service worker falls back to network // for the main resource request, and add a suffix to avoid colliding // with other tests. - const scope = 'resources/?ignore-for-request-body-fallback-string'; + const page_url = 'resources/?ignore-for-request-body-fallback-string'; let frame; - return service_worker_unregister_and_register(t, worker, scope) - .then(reg => { - add_completion_callback(() => { reg.unregister(); }); - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(() => { - return with_iframe(scope); }) + return with_iframe(page_url) .then(f => { frame = f; + t.add_cleanup(() => { frame.remove(); }); // Add "?ignore" so the service worker falls back to echo-content.py. const echo_url = '/fetch/api/resources/echo-content.py?ignore'; return frame.contentWindow.fetch(echo_url, { @@ -540,7 +424,6 @@ promise_test(t => { return response.text(); }) .then(response_text => { - frame.remove(); assert_equals( response_text, 'i am the request body', @@ -551,21 +434,16 @@ promise_test(t => { // Test that the service worker can read FetchEvent#body when it is a blob. // It responds with request body it read. promise_test(t => { - // Set scope to "?ignore" so the service worker falls back to network + // Set page_url to "?ignore" so the service worker falls back to network // for the main resource request, and add a suffix to avoid colliding // with other tests. - const scope = 'resources/simple.html?ignore-for-request-body-blob'; + const page_url = 'resources/simple.html?ignore-for-request-body-blob'; let frame; - return service_worker_unregister_and_register(t, worker, scope) - .then(reg => { - add_completion_callback(() => { reg.unregister(); }); - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(() => { - return with_iframe(scope); }) + return with_iframe(page_url) .then(f => { frame = f; + t.add_cleanup(() => { frame.remove(); }); const blob = new Blob(['it\'s me the blob', ' ', 'and more blob!']); return frame.contentWindow.fetch('simple.html?request-body', { method: 'POST', @@ -576,7 +454,6 @@ promise_test(t => { return response.text(); }) .then(response_text => { - frame.remove(); assert_equals(response_text, 'it\'s me the blob and more blob!'); }); }, 'FetchEvent#body is a blob'); @@ -584,21 +461,16 @@ promise_test(t => { // Test that the request body is sent to network upon network fallback, // for a blob body. promise_test(t => { - // Set scope to "?ignore" so the service worker falls back to network + // Set page_url to "?ignore" so the service worker falls back to network // for the main resource request, and add a suffix to avoid colliding // with other tests. - const scope = 'resources/simple.html?ignore-for-request-body-fallback-blob'; + const page_url = 'resources/simple.html?ignore-for-request-body-fallback-blob'; let frame; - return service_worker_unregister_and_register(t, worker, scope) - .then(reg => { - add_completion_callback(() => { reg.unregister(); }); - return wait_for_state(t, reg.installing, 'activated'); - }) - .then(() => { - return with_iframe(scope); }) + return with_iframe(page_url) .then(f => { frame = f; + t.add_cleanup(() => { frame.remove(); }); const blob = new Blob(['it\'s me the blob', ' ', 'and more blob!']); // Add "?ignore" so the service worker falls back to echo-content.py. const echo_url = '/fetch/api/resources/echo-content.py?ignore'; @@ -611,7 +483,6 @@ promise_test(t => { return response.text(); }) .then(response_text => { - frame.remove(); assert_equals( response_text, 'it\'s me the blob and more blob!', @@ -620,461 +491,316 @@ promise_test(t => { }, 'FetchEvent#body is a blob and is passed to network fallback'); promise_test(async (t) => { - const scope = 'resources/simple.html?keepalive'; - - 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); + const page_url = 'resources/simple.html?keepalive'; + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); assert_equals(frame.contentDocument.body.textContent, 'false'); - const response = await frame.contentWindow.fetch(scope, {keepalive: true}); + const response = await frame.contentWindow.fetch(page_url, {keepalive: true}); const text = await response.text(); assert_equals(text, 'true'); - frame.remove(); - await service_worker_unregister_and_done(t, scope); }, 'Service Worker responds to fetch event with the correct keepalive value'); promise_test(async (t) => { - const scope = 'resources/simple.html?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, - 'method = GET, isReloadNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.location.reload(); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isReloadNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isReloadNavigation'; + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.location.reload(); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = true'); }, 'FetchEvent#request.isReloadNavigation is true (location.reload())'); promise_test(async (t) => { - const scope = 'resources/simple.html?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, - 'method = GET, isReloadNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(0); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isReloadNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isReloadNavigation'; + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(0); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = true'); }, 'FetchEvent#request.isReloadNavigation is true (history.go(0))'); promise_test(async (t) => { - const scope = 'resources/simple.html?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, - 'method = GET, isReloadNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - const form = frame.contentDocument.createElement('form'); - form.method = 'POST'; - form.name = 'form'; - form.action = new Request(scope).url; - frame.contentDocument.body.appendChild(form); - form.submit(); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = POST, isReloadNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.location.reload(); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = POST, isReloadNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isReloadNavigation'; + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + const form = frame.contentDocument.createElement('form'); + form.method = 'POST'; + form.name = 'form'; + form.action = new Request(page_url).url; + frame.contentDocument.body.appendChild(form); + form.submit(); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = POST, isReloadNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.location.reload(); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = POST, isReloadNavigation = true'); }, 'FetchEvent#request.isReloadNavigation is true (POST + location.reload())'); promise_test(async (t) => { - const scope = 'resources/simple.html?isReloadNavigation'; + const page_url = 'resources/simple.html?isReloadNavigation'; const anotherUrl = new Request('resources/simple.html').url; - 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, - 'method = GET, isReloadNavigation = false'); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = anotherUrl; - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-1); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isReloadNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(0); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isReloadNavigation = true'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(1); - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + let frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = false'); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = anotherUrl; + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-1); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(0); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isReloadNavigation = true'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(1); + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); }, 'FetchEvent#request.isReloadNavigation is true (with history traversal)'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - 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, - 'method = GET, isHistoryNavigation = false'); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = anotherUrl; - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-1); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = anotherUrl; + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-1); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = true'); }, 'FetchEvent#request.isHistoryNavigation is true (with history.go(-1))'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - 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(anotherUrl); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = scope; - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-1); - }); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(1); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const frame = await with_iframe(anotherUrl); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = page_url; + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-1); + }); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(1); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = true'); }, 'FetchEvent#request.isHistoryNavigation is true (with history.go(1))'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - 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(anotherUrl); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = scope; - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-1); - }); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(1); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = true'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(0); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = false'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const frame = await with_iframe(anotherUrl); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = page_url; + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-1); + }); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(1); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = true'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(0); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); }, 'FetchEvent#request.isHistoryNavigation is false (with history.go(0))'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - 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(anotherUrl); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = scope; - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-1); - }); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(1); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = true'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.location.reload(); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = false'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const frame = await with_iframe(anotherUrl); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = page_url; + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-1); + }); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(1); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = true'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.location.reload(); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); }, 'FetchEvent#request.isHistoryNavigation is false (with location.reload)'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - const oneAnotherUrl = new Request('resources/simple.html?').url; - let frame; - let reg; + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const oneAnotherUrl = new Request('resources/simple.html?ignore2').url; - 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, - 'method = GET, isHistoryNavigation = false'); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = anotherUrl; - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = oneAnotherUrl; - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-2); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = anotherUrl; + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = oneAnotherUrl; + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-2); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = true'); }, 'FetchEvent#request.isHistoryNavigation is true (with history.go(-2))'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - const oneAnotherUrl = new Request('resources/simple.html?').url; - 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(anotherUrl); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = oneAnotherUrl; - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = scope; - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-2); - }); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(2); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = GET, isHistoryNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const oneAnotherUrl = new Request('resources/simple.html?ignore2').url; + const frame = await with_iframe(anotherUrl); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = oneAnotherUrl; + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = page_url; + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-2); + }); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(2); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = true'); }, 'FetchEvent#request.isHistoryNavigation is true (with history.go(2))'); promise_test(async (t) => { - const scope = 'resources/simple.html?isHistoryNavigation'; - const anotherUrl = new Request('resources/simple.html').url; - 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, - 'method = GET, isHistoryNavigation = false'); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - const form = frame.contentDocument.createElement('form'); - form.method = 'POST'; - form.name = 'form'; - form.action = new Request(scope).url; - frame.contentDocument.body.appendChild(form); - form.submit(); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = POST, isHistoryNavigation = false'); - // Use step_timeout(0) to ensure the history entry is created for Blink - // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.src = anotherUrl; - }); - assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); - await wait(0); - await new Promise((resolve) => { - frame.addEventListener('load', resolve); - frame.contentWindow.history.go(-1); - }); - assert_equals(frame.contentDocument.body.textContent, - 'method = POST, isHistoryNavigation = true'); - } finally { - if (frame) { - frame.remove(); - } - if (reg) { - await reg.unregister(); - } - } + const page_url = 'resources/simple.html?isHistoryNavigation'; + const anotherUrl = new Request('resources/simple.html?ignore').url; + const frame = await with_iframe(page_url); + t.add_cleanup(() => { frame.remove(); }); + assert_equals(frame.contentDocument.body.textContent, + 'method = GET, isHistoryNavigation = false'); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + const form = frame.contentDocument.createElement('form'); + form.method = 'POST'; + form.name = 'form'; + form.action = new Request(page_url).url; + frame.contentDocument.body.appendChild(form); + form.submit(); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = POST, isHistoryNavigation = false'); + // Use step_timeout(0) to ensure the history entry is created for Blink + // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861. + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.src = anotherUrl; + }); + assert_equals(frame.contentDocument.body.textContent, "Here's a simple html file.\n"); + await wait(0); + await new Promise((resolve) => { + frame.addEventListener('load', resolve); + frame.contentWindow.history.go(-1); + }); + assert_equals(frame.contentDocument.body.textContent, + 'method = POST, isHistoryNavigation = true'); }, 'FetchEvent#request.isHistoryNavigation is true (POST + history.go(-1))'); -