Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..995b52e7c345352d79cf1f2b789da46fda0debf9 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html |
| @@ -0,0 +1,223 @@ |
| +<!DOCTYPE html> |
| +<!-- This test is prefixed with `chromium.` because it asserts internal |
| + implementation details using non-standard API that is only available via |
| + Chromium's content_shell. It should be maintained only in so far as those |
| + implementation details need to be held stable; assertions that can be |
| + expressed using standard interfaces should be added to the equivalent version |
| + of this test in the Web Platform Tests project. --> |
|
falken
2017/05/18 01:48:06
To make more clear the purpose of this test, and t
mike3
2017/05/18 17:49:29
Done.
|
| +<title>Service Worker: Redirected response</title> |
|
falken
2017/05/18 01:48:07
maybe modify the title to say "Redirected response
mike3
2017/05/18 17:49:28
Done.
|
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="../resources/get-host-info.js?pipe=sub"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script> |
| +// Tests redirect behavior. It calls fetch_method(url, fetch_option) and tests |
| +// the resulting response against the expected values. It also adds the |
| +// response to |cache| and checks the cached response matches the expected |
| +// values. |
| +// |
| +// |options|: a dictionary of parameters for the test |
| +// |options.url|: the URL to fetch |
| +// |options.fetch_option|: the options passed to |fetch_method| |
| +// |options.fetch_method|: the method used to fetch. Useful for testing an |
| +// iframe's fetch() vs. this page's fetch(). |
| +// |options.cache|: A Cache to add the response to |
| +// |options.options.expected_redirected|: The value of response.redirected |
|
falken
2017/05/18 01:48:06
can remove this one
mike3
2017/05/18 17:49:28
Done.
|
| +// |options.expected_url_list|: an array of string values describing the |
| +// internal URL list; this information is not |
| +// available via a standard API |
| +function redirected_test(options) { |
| + return options.fetch_method.call(null, options.url, options.fetch_option).then(response => { |
| + var cloned_response = response.clone(); |
| + assert_equals( |
| + response.redirected, options.expected_redirected, |
| + 'The redirected flag of response must match. URL: ' + options.url); |
| + assert_equals( |
| + cloned_response.redirected, options.expected_redirected, |
| + 'The redirected flag of cloned response must match. URL: ' + options.url); |
| + if (self.internals) { |
|
falken
2017/05/18 01:48:07
can remove lines 32-38
mike3
2017/05/18 17:49:29
Done.
|
| + assert_array_equals( |
| + self.internals.getInternalResponseURLList(response), |
| + options.expected_url_list, |
| + 'The URL list of response must match. URL: ' + options.url); |
| + assert_array_equals( |
| + self.internals.getInternalResponseURLList(cloned_response), |
| + options.expected_url_list, |
| + 'The URL list of cloned response must match. URL: ' + options.url); |
| + } |
| + return options.cache.put(options.url, response); |
| + }) |
| + .then(_ => options.cache.match(options.url)) |
| + .then(response => { |
| + assert_equals(response.redirected, options.expected_redirected, |
| + 'The redirected flag of response in CacheStorage must match. URL: ' + |
| + options.url); |
| + if (self.internals) { |
|
falken
2017/05/18 01:48:07
can remove lines 52-55
mike3
2017/05/18 17:49:28
Done.
|
| + assert_array_equals( |
| + self.internals.getInternalResponseURLList(response), |
| + options.expected_url_list, |
| + 'The URL list of response in CacheStorage must match. URL: ' + |
| + options.url); |
| + } |
| + }); |
| +} |
| + |
| +var host_info = get_host_info(); |
| +var REDIRECT_URL = host_info['HTTP_ORIGIN'] + |
| + '/serviceworker/resources/redirect.php?Redirect='; |
| +var TARGET_URL = host_info['HTTP_ORIGIN'] + |
| + '/serviceworker/resources/simple.txt'; |
| +var REDIRECT_TO_TARGET_URL = REDIRECT_URL + encodeURIComponent(TARGET_URL); |
| +var frame; |
| +var cache; |
| +var setup; |
| + |
| +promise_test(t => { |
| + var SCOPE = 'resources/blank.html?redirected-response'; |
| + var SCRIPT = 'resources/fetch-rewrite-worker.js'; |
| + var CACHE_NAME = 'serviceworker/redirected-response'; |
|
falken
2017/05/18 01:48:07
if (!self.internals) return Promise.reject('this t
mike3
2017/05/18 17:49:29
I took a slightly different approach here: rejecti
|
| + setup = service_worker_unregister_and_register(t, SCRIPT, SCOPE) |
| + .then(registration => { |
| + promise_test(function() { |
| + return registration.unregister(); |
| + }, 'restore global state (service worker registration)'); |
| + |
| + return wait_for_state(t, registration.installing, 'activated'); |
| + }) |
| + .then(_ => self.caches.open(CACHE_NAME)) |
| + .then(c => { |
| + cache = c; |
| + |
| + promise_test(function() { |
| + return self.caches.delete(CACHE_NAME); |
| + }, 'restore global state (caches)'); |
| + |
| + return with_iframe(SCOPE); |
| + }) |
| + .then(f => { |
| + frame = f; |
| + |
| + add_completion_callback(function() { |
| + f.remove(); |
| + }); |
| + }); |
| + return setup; |
| + }, 'initialize global state (service worker registration and caches)'); |
| + |
| +// Tests without service workers. |
| +promise_test(t => setup |
| + .then(() => redirected_test({url: TARGET_URL, |
| + fetch_option: {}, |
| + fetch_method: self.fetch, |
| + cache: cache, |
| + expected_redirected: false, |
| + expected_url_list: [TARGET_URL]})), |
| + 'mode: "follow", non-intercepted request, no server redirect'); |
| + |
| +promise_test(t => setup |
| + .then(() => redirected_test({url: REDIRECT_TO_TARGET_URL, |
| + fetch_option: {}, |
| + fetch_method: self.fetch, |
| + cache: cache, |
| + expected_redirected: true, |
| + expected_url_list: [REDIRECT_TO_TARGET_URL, TARGET_URL]})), |
| + 'mode: "follow", non-intercepted request'); |
| + |
| +promise_test(t => setup |
| + .then(() => redirected_test({url: REDIRECT_TO_TARGET_URL + '&manual', |
| + fetch_option: {redirect: 'manual'}, |
| + fetch_method: self.fetch, |
| + cache: cache, |
| + expected_redirected: false, |
| + expected_url_list: [REDIRECT_TO_TARGET_URL + '&manual']})), |
| + 'mode: "manual", non-intercepted request'); |
| + |
| +promise_test(t => setup |
| + .then(() => promise_rejects( |
| + t, new TypeError(), |
| + self.fetch(REDIRECT_TO_TARGET_URL + '&error', |
| + {redirect:'error'}), |
| + 'The redirect response from the server should be treated as' + |
| + ' an error when the redirect flag of request was \'error\'.')), |
| + 'mode: "error", non-intercepted request'); |
|
falken
2017/05/18 01:48:06
we can remove these ones that don't call redirecte
mike3
2017/05/18 17:49:29
Done.
|
| + |
| +promise_test(t => setup |
| + .then(() => redirected_test({url: './?url=' + encodeURIComponent(TARGET_URL), |
| + fetch_option: {}, |
| + fetch_method: frame.contentWindow.fetch, |
| + cache: cache, |
| + expected_redirected: false, |
| + expected_url_list: [TARGET_URL]})), |
| + 'mode: "follow", no mode change, no server redirect'); |
| + |
| + |
| + // The service worker returns a redirected response. |
| +promise_test(t => setup |
| + .then(() => redirected_test({url: './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) + |
| + '&original-redirect-mode=follow', |
| + fetch_option: {redirect: 'follow'}, |
| + fetch_method: frame.contentWindow.fetch, |
| + cache: cache, |
| + expected_redirected: true, |
| + expected_url_list: [REDIRECT_TO_TARGET_URL, TARGET_URL]})), |
| + 'mode: "follow", no mode change'); |
| + |
| +promise_test(t => setup |
| + .then(() => promise_rejects( |
| + t, new TypeError(), |
| + frame.contentWindow.fetch( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) + |
| + '&original-redirect-mode=error&redirect-mode=follow', |
| + {redirect: 'error'}), |
| + 'The redirected response from the service worker should be ' + |
| + 'treated as an error when the redirect flag of request was ' + |
| + '\'error\'.')), |
| + 'mode: "error", mode change: "follow"'); |
|
falken
2017/05/18 01:48:07
remove
mike3
2017/05/18 17:49:29
Done.
|
| + |
| +promise_test(t => setup |
| + .then(() => promise_rejects( |
| + t, new TypeError(), |
| + frame.contentWindow.fetch( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) + |
| + '&original-redirect-mode=manual&redirect-mode=follow', |
| + {redirect: 'manual'}), |
| + 'The redirected response from the service worker should be ' + |
| + 'treated as an error when the redirect flag of request was ' + |
| + '\'manual\'.')), |
| + 'mode: "manual", mode change: "follow"'); |
|
falken
2017/05/18 01:48:07
remove
mike3
2017/05/18 17:49:28
Done.
|
| + |
| +// The service worker returns an opaqueredirect response. |
| +promise_test(t => setup |
| + .then(() => promise_rejects( |
| + t, new TypeError(), |
| + frame.contentWindow.fetch( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) + |
| + '&original-redirect-mode=follow&redirect-mode=manual', |
| + {redirect: 'follow'}), |
| + 'The opaqueredirect response from the service worker should ' + |
| + 'be treated as an error when the redirect flag of request was' + |
| + ' \'follow\'.')), |
| + 'mode: "follow", mode change: "redirect"'); |
|
falken
2017/05/18 01:48:06
remove
mike3
2017/05/18 17:49:28
Done.
|
| + |
| +promise_test(t => setup |
| + .then(() => promise_rejects( |
| + t, new TypeError(), |
| + frame.contentWindow.fetch( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) + |
| + '&original-redirect-mode=error&redirect-mode=manual', |
| + {redirect: 'error'}), |
| + 'The opaqueredirect response from the service worker should ' + |
| + 'be treated as an error when the redirect flag of request was' + |
| + ' \'error\'.')), |
| + 'mode: "error", mode change: "manual"'); |
|
falken
2017/05/18 01:48:06
remove
mike3
2017/05/18 17:49:28
Done.
|
| + |
| +promise_test(t => setup |
| + .then(() => redirected_test({url: './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) + |
| + '&original-redirect-mode=manual&redirect-mode=manual', |
| + fetch_option: {redirect: 'manual'}, |
| + fetch_method: frame.contentWindow.fetch, |
| + cache: cache, |
| + expected_redirected: false, |
| + expected_url_list: [REDIRECT_TO_TARGET_URL]})), |
| + 'mode: "manual", no mode change'); |
| +</script> |