Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/navigation-redirect.html |
| diff --git a/LayoutTests/http/tests/serviceworker/navigation-redirect.html b/LayoutTests/http/tests/serviceworker/navigation-redirect.html |
| index e8b64f5ed2a075f012513a833a17a73781c1b57e..6b1ea96fc2d0a02127d7bd14204d104cb057fd8e 100644 |
| --- a/LayoutTests/http/tests/serviceworker/navigation-redirect.html |
| +++ b/LayoutTests/http/tests/serviceworker/navigation-redirect.html |
| @@ -6,6 +6,62 @@ |
| <script src="resources/test-helpers.js"></script> |
| <body> |
| <script> |
| + |
| +var host_info = get_host_info(); |
| + |
| +// This test registers three Service Workers at SCOPE1, SCOPE2 and |
| +// OTHER_ORIGIN_SCOPE. And checks the redirected page's URL and the requests |
| +// which are intercepted by Service Worker while loading redirect page. |
| +var BASE_URL = host_info['HTTP_ORIGIN'] + base_path(); |
| +var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] + base_path(); |
| + |
| +var SCOPE1 = BASE_URL + 'resources/navigation-redirect-scope1.php?'; |
| +var SCOPE2 = BASE_URL + 'resources/navigation-redirect-scope2.php?'; |
| +var OUT_SCOPE = BASE_URL + 'resources/navigation-redirect-out-scope.php?'; |
| +var SCRIPT = 'resources/navigation-redirect-worker.js'; |
| + |
| +var OTHER_ORIGIN_IFRAME_URL = |
| + OTHER_BASE_URL + 'resources/navigation-redirect-other-origin.html'; |
| +var OTHER_ORIGIN_SCOPE = |
| + OTHER_BASE_URL + 'resources/navigation-redirect-scope1.php?'; |
| +var OTHER_ORIGIN_OUT_SCOPE = |
| + OTHER_BASE_URL + 'resources/navigation-redirect-out-scope.php?'; |
| + |
| +var workers; |
| +var other_origin_frame; |
| +var setup_environment_promise; |
| + |
| +function setup_environment(t) { |
| + if (setup_environment_promise) |
| + return setup_environment_promise; |
| + setup_environment_promise = |
| + with_iframe(OTHER_ORIGIN_IFRAME_URL) |
| + .then(function(f) { |
| + // In this frame we register a Service Worker at OTHER_ORIGIN_SCOPE. |
| + // And will use this frame to communicate with the worker. |
| + other_origin_frame = f; |
| + return Promise.all( |
| + [service_worker_unregister_and_register(t, SCRIPT, SCOPE1), |
| + service_worker_unregister_and_register(t, SCRIPT, SCOPE2)]); |
| + }) |
| + .then(function(registrations) { |
| + add_completion_callback(function() { |
|
falken
2015/08/26 07:25:48
ahh.. that's a handy function
|
| + registrations[0].unregister(); |
| + registrations[1].unregister(); |
| + send_to_iframe(other_origin_frame, 'unregister') |
| + .then(function() { other_origin_frame.remove(); }); |
| + }); |
| + workers = registrations.map(get_effective_worker); |
| + return Promise.all([ |
| + wait_for_state(t, workers[0], 'activated'), |
| + wait_for_state(t, workers[1], 'activated'), |
| + // This promise will resolve when |wait_for_worker_promise| |
| + // in OTHER_ORIGIN_IFRAME_URL resolves. |
| + send_to_iframe(other_origin_frame, "wait_for_worker")]); |
|
falken
2015/08/26 07:25:48
single quotes
horo
2015/08/28 07:05:41
Done.
|
| + }); |
| + return setup_environment_promise; |
| +} |
| + |
| function get_effective_worker(registration) { |
| if (registration.active) |
| return registration.active; |
| @@ -15,7 +71,41 @@ function get_effective_worker(registration) { |
| return registration.installing; |
| } |
| -var host_info = get_host_info(); |
| +function check_all_intercepted_urls(expected_urls) { |
| + return Promise.all([ |
| + // Gets the request URLs which are intercepted by SCOPE1's SW. |
| + get_intercepted_urls(workers[0]), |
| + // Gets the request URLs which are intercepted by SCOPE2's SW. |
| + get_intercepted_urls(workers[1]), |
| + // Gets the request URLs which are intercepted by OTHER_ORIGIN_SCOPE's |
| + // SW. This promise will resolve when get_intercepted_urls() in |
| + // OTHER_ORIGIN_IFRAME_URL resolves. |
| + send_to_iframe(other_origin_frame, 'get_intercepted_urls')]) |
| + .then(function(urls) { |
|
falken
2015/08/26 07:25:48
indent looks wrong
horo
2015/08/28 07:05:41
Changed the position of brackets.
|
| + assert_object_equals( |
| + urls, expected_urls, |
| + 'Intercepted URLs should match.'); |
| + }); |
| +} |
| + |
| +function test_redirect(url, expected_last_url, |
| + expected_intercepted_urls) { |
| + var message_promise = new Promise(function(resolve) { |
| + // A message which ID is 'last_url' will be sent from the iframe. |
| + message_resolvers['last_url'] = resolve; |
|
falken
2015/08/26 07:25:48
maybe message_resolvers and the other globals shou
horo
2015/08/28 07:05:40
Done.
|
| + }); |
| + return with_iframe(url) |
| + .then(function(f) { |
| + f.remove(); |
| + return check_all_intercepted_urls(expected_intercepted_urls); |
| + }) |
| + .then(function() { return message_promise; }) |
| + .then(function(last_url) { |
| + assert_equals( |
| + last_url, expected_last_url, |
| + 'Last URL should match.'); |
| + }); |
| +} |
| window.addEventListener('message', on_message, false); |
| @@ -51,361 +141,282 @@ function get_intercepted_urls(worker) { |
| }); |
| } |
| -async_test(function(t) { |
| - // This test registers three Service Workers at SCOPE1, SCOPE2 and |
| - // OTHER_ORIGIN_SCOPE. And checks the redirected page's URL and the requests |
| - // which are intercepted by Service Worker while loading redirect page. |
| - var BASE_URL = host_info['HTTP_ORIGIN'] + base_path(); |
| - var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] + base_path(); |
| - |
| - var SCOPE1 = BASE_URL + 'resources/navigation-redirect-scope1.php?'; |
| - var SCOPE2 = BASE_URL + 'resources/navigation-redirect-scope2.php?'; |
| - var OUT_SCOPE = BASE_URL + 'resources/navigation-redirect-out-scope.php?'; |
| - var SCRIPT = 'resources/navigation-redirect-worker.js'; |
| - |
| - var OTHER_ORIGIN_IFRAME_URL = |
| - OTHER_BASE_URL + 'resources/navigation-redirect-other-origin.html'; |
| - var OTHER_ORIGIN_SCOPE = |
| - OTHER_BASE_URL + 'resources/navigation-redirect-scope1.php?'; |
| - var OTHER_ORIGIN_OUT_SCOPE = |
| - OTHER_BASE_URL + 'resources/navigation-redirect-out-scope.php?'; |
| - |
| - var workers; |
| - var other_origin_frame; |
| - |
| - function check_all_intercepted_urls(expected_urls, description) { |
| - return Promise.all([ |
| - // Gets the request URLs which are intercepted by SCOPE1's SW. |
| - get_intercepted_urls(workers[0]), |
| - // Gets the request URLs which are intercepted by SCOPE2's SW. |
| - get_intercepted_urls(workers[1]), |
| - // Gets the request URLs which are intercepted by OTHER_ORIGIN_SCOPE's |
| - // SW. This promise will resolve when get_intercepted_urls() in |
| - // OTHER_ORIGIN_IFRAME_URL resolves. |
| - send_to_iframe(other_origin_frame, 'get_intercepted_urls')]) |
| - .then(function(urls) { |
| - assert_object_equals( |
| - urls, expected_urls, |
| - 'Intercepted URLs should match: ' + description); |
| - }); |
| - } |
| - |
| - function test_redirect(url, expected_last_url, |
| - expected_intercepted_urls, description) { |
| - var message_promise = new Promise(function(resolve) { |
| - // A message which ID is 'last_url' will be sent from the iframe. |
| - message_resolvers['last_url'] = resolve; |
| - }); |
| - return with_iframe(url) |
| - .then(function(f) { |
| - f.remove(); |
| - return check_all_intercepted_urls(expected_intercepted_urls, |
| - description); |
| - }) |
| - .then(function() { return message_promise; }) |
| - .then(function(last_url) { |
| - assert_equals( |
| - last_url, expected_last_url, |
| - 'Last URL should match: ' + description); |
| - }); |
| - } |
| - |
| - with_iframe(OTHER_ORIGIN_IFRAME_URL) |
| - .then(function(f) { |
| - // In this frame we register a Service Worker at OTHER_ORIGIN_SCOPE. |
| - // And will use this frame to communicate with the worker. |
| - other_origin_frame = f; |
| - return Promise.all( |
| - [service_worker_unregister_and_register(t, SCRIPT, SCOPE1), |
| - service_worker_unregister_and_register(t, SCRIPT, SCOPE2)]); |
| - }) |
| - .then(function(registrations) { |
| - workers = registrations.map(get_effective_worker); |
| - return Promise.all([ |
| - wait_for_state(t, workers[0], 'activated'), |
| - wait_for_state(t, workers[1], 'activated'), |
| - // This promise will resolve when |wait_for_worker_promise| |
| - // in OTHER_ORIGIN_IFRAME_URL resolves. |
| - send_to_iframe(other_origin_frame, "wait_for_worker")]); |
| - }) |
| - // Normal redirect. |
| - .then(function() { |
| - return test_redirect( |
| - OUT_SCOPE + "url=" + encodeURIComponent(SCOPE1), |
| - SCOPE1, |
| - [[SCOPE1], [], []], |
| - 'Normal redirect to same-origin scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - OUT_SCOPE + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| - OTHER_ORIGIN_SCOPE, |
| - [[], [], [OTHER_ORIGIN_SCOPE]], |
| - 'Normal redirect to other-origin scope.'); |
| - }) |
| +// Normal redirect. |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + OUT_SCOPE + "url=" + encodeURIComponent(SCOPE1), |
|
falken
2015/08/26 07:25:48
double quotes should be single quotes here and thr
horo
2015/08/28 07:05:41
Done.
|
| + SCOPE1, |
| + [[SCOPE1], [], []]); |
| + }); |
| + }, 'Normal redirect to same-origin scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + OUT_SCOPE + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| + OTHER_ORIGIN_SCOPE, |
| + [[], [], [OTHER_ORIGIN_SCOPE]]); |
| + }); |
| + }, 'Normal redirect to other-origin scope.'); |
| - // SW fallbacked redirect. SW doesn't handle the fetch request. |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE), |
| - OUT_SCOPE, |
| - [[SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE)], |
| - [], |
| - []], |
| - 'SW-fallbacked redirect to same-origin out-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "url=" + encodeURIComponent(SCOPE1), |
| - SCOPE1, |
| - [[SCOPE1 + "url=" + encodeURIComponent(SCOPE1), SCOPE1], |
| - [], |
| - []], |
| - 'SW-fallbacked redirect to same-origin same-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "url=" + encodeURIComponent(SCOPE2), |
| - SCOPE2, |
| - [[SCOPE1 + "url=" + encodeURIComponent(SCOPE2)], |
| - [SCOPE2], |
| - []], |
| - 'SW-fallbacked redirect to same-origin other-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| - OTHER_ORIGIN_OUT_SCOPE, |
| - [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| - [], |
| - []], |
| - 'SW-fallbacked redirect to other-origin out-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| - OTHER_ORIGIN_SCOPE, |
| - [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| - [], |
| - [OTHER_ORIGIN_SCOPE]], |
| - 'SW-fallbacked redirect to other-origin in-scope.'); |
| - }) |
| +// SW fallbacked redirect. SW doesn't handle the fetch request. |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE), |
| + OUT_SCOPE, |
| + [[SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE)], [], []]); |
| + }); |
| + }, 'SW-fallbacked redirect to same-origin out-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "url=" + encodeURIComponent(SCOPE1), |
| + SCOPE1, |
| + [[SCOPE1 + "url=" + encodeURIComponent(SCOPE1), SCOPE1], [], []]); |
| + }); |
| + }, 'SW-fallbacked redirect to same-origin same-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "url=" + encodeURIComponent(SCOPE2), |
| + SCOPE2, |
| + [[SCOPE1 + "url=" + encodeURIComponent(SCOPE2)], [SCOPE2], []]); |
| + }); |
| + }, 'SW-fallbacked redirect to same-origin other-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| + OTHER_ORIGIN_OUT_SCOPE, |
| + [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, 'SW-fallbacked redirect to other-origin out-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| + OTHER_ORIGIN_SCOPE, |
| + [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| + [], |
| + [OTHER_ORIGIN_SCOPE]]); |
| + }); |
| + }, 'SW-fallbacked redirect to other-origin in-scope.'); |
| - // SW generated redirect. |
| - // SW: event.respondWith(Response.redirect(params['url'])); |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE), |
| - OUT_SCOPE, |
| - [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE)], |
| - [], |
| - []], |
| - 'SW-generated redirect to same-origin out-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), |
| - SCOPE1, |
| - [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), SCOPE1], |
| - [], |
| - []], |
| - 'SW-generated redirect to same-origin same-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2), |
| - SCOPE2, |
| - [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2)], |
| - [SCOPE2], |
| - []], |
| - 'SW-generated redirect to same-origin other-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=gen&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| - OTHER_ORIGIN_OUT_SCOPE, |
| - [[SCOPE1 + "sw=gen&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| - [], |
| - []], |
| - 'SW-generated redirect to other-origin out-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| - OTHER_ORIGIN_SCOPE, |
| - [[SCOPE1 + "sw=gen&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| - [], |
| - [OTHER_ORIGIN_SCOPE]], |
| - 'SW-generated redirect to other-origin in-scope.'); |
| - }) |
| +// SW generated redirect. |
| +// SW: event.respondWith(Response.redirect(params['url'])); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE), |
| + OUT_SCOPE, |
| + [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE)], [], []]); |
| + }); |
| + }, 'SW-generated redirect to same-origin out-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), |
| + SCOPE1, |
| + [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), SCOPE1], |
| + [], |
| + []]); |
| + }); |
| + }, 'SW-generated redirect to same-origin same-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2), |
| + SCOPE2, |
| + [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2)], |
| + [SCOPE2], |
| + []]); |
| + }); |
| + }, 'SW-generated redirect to same-origin other-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| + OTHER_ORIGIN_OUT_SCOPE, |
| + [[SCOPE1 + "sw=gen&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, 'SW-generated redirect to other-origin out-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| + OTHER_ORIGIN_SCOPE, |
| + [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| + [], |
| + [OTHER_ORIGIN_SCOPE]]); |
| + }); |
| + }, 'SW-generated redirect to other-origin in-scope.'); |
| - // SW fetched redirect. |
| - // SW: event.respondWith(fetch(event.request)); |
| - // TODO(horo): When we change Request.redirect of navigation requests to |
| - // 'manual', the expected last URL shuold be changed. (crbug.com/510650) |
| - // Spec Issue: https://github.com/whatwg/fetch/issues/106 |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), |
| - SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), |
| - [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE)], |
| - [], |
| - []], |
| - 'SW-fetched redirect to same-origin out-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), |
| - SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), |
| - [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1)], |
| - [], |
| - []], |
| - 'SW-fetched redirect to same-origin same-scope.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), |
| - SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), |
| - [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2)], |
| - [], |
| - []], |
| - 'SW fetched redirect to same-origin other-scope.'); |
| - }) |
| +// SW fetched redirect. |
| +// SW: event.respondWith(fetch(event.request)); |
| +// TODO(horo): When we change Request.redirect of navigation requests to |
| +// 'manual', the expected last URL shuold be changed. (crbug.com/510650) |
| +// Spec Issue: https://github.com/whatwg/fetch/issues/106 |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), |
| + SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), |
| + [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, 'SW-fetched redirect to same-origin out-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), |
| + SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), |
| + [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1)], [], []]); |
| + }); |
| + }, 'SW-fetched redirect to same-origin same-scope.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), |
| + SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), |
| + [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2)], [], []]); |
| + }); |
| + }, 'SW fetched redirect to same-origin other-scope.'); |
| - // Opaque redirect. |
| - // SW: event.respondWith(fetch( |
| - // new Request(event.request.url, {redirect: 'manual'}))); |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE), |
| - OUT_SCOPE, |
| - [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE)], |
| - [], |
| - []], |
| - 'Redirect to same-origin out-scope with opaque redirect ' + |
| - 'response.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), |
| - SCOPE1, |
| - [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), SCOPE1], |
| - [], |
| - []], |
| - 'Redirect to same-origin same-scope with opaque redirect ' + |
| - 'response.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2), |
| - SCOPE2, |
| - [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2)], |
| - [SCOPE2], |
| - []], |
| - 'Redirect to same-origin other-scope with opaque redirect ' + |
| - 'response.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaque&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| - OTHER_ORIGIN_OUT_SCOPE, |
| - [[SCOPE1 + "sw=opaque&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| - [], |
| - []], |
| - 'Redirect to other-origin out-scope with opaque redirect ' + |
| - 'response.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaque&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| - OTHER_ORIGIN_SCOPE, |
| - [[SCOPE1 + "sw=opaque&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| - [], |
| - [OTHER_ORIGIN_SCOPE]], |
| - 'Redirect to other-origin in-scope with opaque redirect ' + |
| - 'response.'); |
| - }) |
| +// Opaque redirect. |
| +// SW: event.respondWith(fetch( |
| +// new Request(event.request.url, {redirect: 'manual'}))); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE), |
| + OUT_SCOPE, |
| + [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, 'Redirect to same-origin out-scope with opaque redirect response.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), |
| + SCOPE1, |
| + [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), SCOPE1], |
| + [], |
| + []]); |
| + }); |
| + }, 'Redirect to same-origin same-scope with opaque redirect response.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2), |
| + SCOPE2, |
| + [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2)], |
| + [SCOPE2], |
| + []]); |
| + }); |
| + }, 'Redirect to same-origin other-scope with opaque redirect response.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=opaque&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| + OTHER_ORIGIN_OUT_SCOPE, |
| + [[SCOPE1 + "sw=opaque&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, 'Redirect to other-origin out-scope with opaque redirect response.'); |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| + OTHER_ORIGIN_SCOPE, |
| + [[SCOPE1 + "sw=opaque&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| + [], |
| + [OTHER_ORIGIN_SCOPE]]); |
| + }); |
| + }, 'Redirect to other-origin in-scope with opaque redirect response.'); |
| - // Opaque redirect passed through Cache. |
| - // SW responds with an opaque redirectresponse from the Cache API. |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(OUT_SCOPE), |
| - OUT_SCOPE, |
| - [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(OUT_SCOPE)], |
| - [], |
| - []], |
| - 'Redirect to same-origin out-scope with opaque redirect ' + |
| - 'response which is passed through Cache.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(SCOPE1), |
| - SCOPE1, |
| - [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(SCOPE1), SCOPE1], |
| - [], |
| - []], |
| - 'Redirect to same-origin same-scope with opaque redirect ' + |
| - 'response which is passed through Cache.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(SCOPE2), |
| - SCOPE2, |
| - [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(SCOPE2)], |
| - [SCOPE2], |
| - []], |
| - 'Redirect to same-origin other-scope with opaque redirect ' + |
| - 'response which is passed through Cache.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| - OTHER_ORIGIN_OUT_SCOPE, |
| - [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| - [], |
| - []], |
| - 'Redirect to other-origin out-scope with opaque redirect ' + |
| - 'response which is passed through Cache.'); |
| - }) |
| - .then(function() { |
| - return test_redirect( |
| - SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| - OTHER_ORIGIN_SCOPE, |
| - [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| - encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| - [], |
| - [OTHER_ORIGIN_SCOPE]], |
| - 'Redirect to other-origin in-scope with opaque redirect ' + |
| - 'response which is passed through Cache.'); |
| - }) |
| - .then(function() { |
| - return Promise.all( |
| - [service_worker_unregister(t, SCOPE1), |
| - service_worker_unregister(t, SCOPE2), |
| - send_to_iframe(other_origin_frame, 'unregister')]); |
| - }) |
| - .then(function() { |
| - other_origin_frame.remove(); |
| - t.done(); |
| - }) |
| - .catch(unreached_rejection(t)); |
| - }, 'Verify the behavior of navigation redirection with Service Worker.'); |
| +// Opaque redirect passed through Cache. |
| +// SW responds with an opaque redirectresponse from the Cache API. |
| +promise_test(function(t) { |
| + return setup_environment(t).then(function() { |
| + return test_redirect( |
| + SCOPE1 + "sw=opaqueThroughCache&url=" + |
| + encodeURIComponent(OUT_SCOPE), |
| + OUT_SCOPE, |
| + [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| + encodeURIComponent(OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, |
| + 'Redirect to same-origin out-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&url=" + |
| + encodeURIComponent(SCOPE1), |
| + SCOPE1, |
| + [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| + encodeURIComponent(SCOPE1), SCOPE1], |
| + [], |
| + []]); |
| + }); |
| + }, |
| + 'Redirect to same-origin same-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&url=" + |
| + encodeURIComponent(SCOPE2), |
| + SCOPE2, |
| + [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| + encodeURIComponent(SCOPE2)], |
| + [SCOPE2], |
| + []]); |
| + }); |
| + }, |
| + 'Redirect to same-origin other-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&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
| + OTHER_ORIGIN_OUT_SCOPE, |
| + [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
| + [], |
| + []]); |
| + }); |
| + }, |
| + 'Redirect to other-origin out-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&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
| + OTHER_ORIGIN_SCOPE, |
| + [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
| + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
| + [], |
| + [OTHER_ORIGIN_SCOPE]]); |
| + }); |
| + }, |
| + 'Redirect to other-origin in-scope with opaque redirect response which ' + |
| + 'is passed through Cache.'); |
| </script> |
| </body> |