diff --git a/service-workers/service-worker/navigation-redirect-body.https.html b/service-workers/service-worker/navigation-redirect-body.https.html new file mode 100644 index 00000000000000..0441c610b17978 --- /dev/null +++ b/service-workers/service-worker/navigation-redirect-body.https.html @@ -0,0 +1,53 @@ + +Service Worker: Navigation redirection must clear body + + + + + + + + + diff --git a/service-workers/service-worker/navigation-redirect-to-http.https.html b/service-workers/service-worker/navigation-redirect-to-http.https.html new file mode 100644 index 00000000000000..d4d2788c5891a1 --- /dev/null +++ b/service-workers/service-worker/navigation-redirect-to-http.https.html @@ -0,0 +1,25 @@ + +Service Worker: Service Worker can receive HTTP opaqueredirect response. + + + + + + + diff --git a/service-workers/service-worker/navigation-redirect.https.html b/service-workers/service-worker/navigation-redirect.https.html index 586e9036a3e9e2..e311bb635367ac 100644 --- a/service-workers/service-worker/navigation-redirect.https.html +++ b/service-workers/service-worker/navigation-redirect.https.html @@ -176,7 +176,7 @@ return test_redirect( SCOPE1 + 'url=' + encodeURIComponent(SCOPE1), SCOPE1, - [[SCOPE1 + 'url=' + encodeURIComponent(SCOPE1)], [], []]); + [[SCOPE1 + 'url=' + encodeURIComponent(SCOPE1), SCOPE1], [], []]); }); }, 'SW-fallbacked redirect to same-origin same-scope.'); promise_test(function(t) { @@ -184,7 +184,7 @@ return test_redirect( SCOPE1 + 'url=' + encodeURIComponent(SCOPE2), SCOPE2, - [[SCOPE1 + 'url=' + encodeURIComponent(SCOPE2)], [], []]); + [[SCOPE1 + 'url=' + encodeURIComponent(SCOPE2)], [SCOPE2], []]); }); }, 'SW-fallbacked redirect to same-origin other-scope.'); promise_test(function(t) { @@ -204,7 +204,7 @@ OTHER_ORIGIN_SCOPE, [[SCOPE1 + 'url=' + encodeURIComponent(OTHER_ORIGIN_SCOPE)], [], - []]); + [OTHER_ORIGIN_SCOPE]]); }); }, 'SW-fallbacked redirect to other-origin in-scope.'); @@ -372,6 +372,16 @@ [OTHER_ORIGIN_SCOPE]]); }); }, 'Redirect to other-origin in-scope with opaque redirect response.'); +promise_test(function(t) { + return setup_environment(t).then(function() { + return test_redirect( + SCOPE1 + 'sw=opaque&noLocationRedirect', + SCOPE1 + 'sw=opaque&noLocationRedirect', + [[SCOPE1 + 'sw=opaque&noLocationRedirect'], + [], + []]); + }); + }, 'No location redirect response.'); // Opaque redirect passed through Cache. // SW responds with an opaque redirectresponse from the Cache API. @@ -445,5 +455,15 @@ }, 'Redirect to other-origin in-scope with opaque redirect response which ' + 'is passed through Cache.'); +promise_test(function(t) { + return setup_environment(t).then(function() { + return test_redirect( + SCOPE1 + 'sw=opaqueThroughCache&noLocationRedirect', + SCOPE1 + 'sw=opaqueThroughCache&noLocationRedirect', + [[SCOPE1 + 'sw=opaqueThroughCache&noLocationRedirect'], + [], + []]); + }); + }, 'No location redirect response via Cache.'); diff --git a/service-workers/service-worker/resources/navigation-redirect-body-worker.js b/service-workers/service-worker/resources/navigation-redirect-body-worker.js new file mode 100644 index 00000000000000..39f11baf8cb965 --- /dev/null +++ b/service-workers/service-worker/resources/navigation-redirect-body-worker.js @@ -0,0 +1,11 @@ +self.addEventListener('fetch', function(event) { + event.respondWith( + fetch(event.request) + .then( + function(response) { + return response; + }, + function(error) { + return new Response('Error:' + error); + })); + }); diff --git a/service-workers/service-worker/resources/navigation-redirect-body.py b/service-workers/service-worker/resources/navigation-redirect-body.py new file mode 100644 index 00000000000000..601f818cff6ad4 --- /dev/null +++ b/service-workers/service-worker/resources/navigation-redirect-body.py @@ -0,0 +1,9 @@ +import os + +filename = os.path.basename(__file__) + +def main(request, response): + if request.method == 'POST': + return 302, [('Location', './%s?redirect' % filename)], '' + + return [('Content-Type', 'text/plain')], request.request_path diff --git a/service-workers/service-worker/resources/navigation-redirect-out-scope.py b/service-workers/service-worker/resources/navigation-redirect-out-scope.py index 4b40762d89ff05..0cd5ef18516fab 100644 --- a/service-workers/service-worker/resources/navigation-redirect-out-scope.py +++ b/service-workers/service-worker/resources/navigation-redirect-out-scope.py @@ -3,7 +3,12 @@ def main(request, response): headers = [("Location", request.GET["url"])] return 302, headers, '' - return [], ''' + status = 200 + + if "noLocationRedirect" in request.GET: + status = 302 + + return status, [], ''' + + diff --git a/service-workers/service-worker/resources/navigation-redirect-to-http-worker.js b/service-workers/service-worker/resources/navigation-redirect-to-http-worker.js new file mode 100644 index 00000000000000..6f2a8ae1d749bb --- /dev/null +++ b/service-workers/service-worker/resources/navigation-redirect-to-http-worker.js @@ -0,0 +1,22 @@ +importScripts('/resources/testharness.js'); + +self.addEventListener('fetch', function(event) { + event.respondWith(new Promise(function(resolve) { + Promise.resolve() + .then(function() { + assert_equals( + event.request.redirect, 'manual', + 'The redirect mode of navigation request must be manual.'); + return fetch(event.request); + }) + .then(function(response) { + assert_equals( + response.type, 'opaqueredirect', + 'The response type of 302 response must be opaqueredirect.'); + resolve(new Response('OK')); + }) + .catch(function(error) { + resolve(new Response('Failed in SW: ' + error)); + }); + })); + });