Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/redirected-response.html

Issue 2550363002: Add LayoutTests for URL list of Response (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/redirected-response.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/redirected-response.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/redirected-response.html
new file mode 100644
index 0000000000000000000000000000000000000000..b8b5270a29f5256a6a55448349b1d4581610909b
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/redirected-response.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<title>Service Worker: Redirected response</title>
+<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>
+
+function redirected_test(url,
+ fetch_method,
+ cache,
+ expected_url_list) {
+ return fetch_method(url).then(response => {
+ var cloned_response = response.clone();
+ if (self.internals) {
+ assert_array_equals(
+ self.internals.getInternalResponseURLList(response),
+ expected_url_list,
+ 'The URL list of response must match. URL: ' + url);
+ assert_array_equals(
+ self.internals.getInternalResponseURLList(cloned_response),
+ expected_url_list,
+ 'The URL list of cloned response must match. URL: ' + url);
+ }
+ return cache.put(url, response);
+ })
+ .then(_ => cache.match(url))
+ .then(response => {
+ if (self.internals) {
+ assert_array_equals(
+ self.internals.getInternalResponseURLList(response),
+ expected_url_list,
+ 'The URL list of response in CacheStorage must match. URL: ' +
+ url);
+ }
+ });
+}
+
+promise_test(t => {
+ var SCOPE = 'resources/blank.html?redirected-response';
+ var SCRIPT = 'resources/fetch-rewrite-worker.js';
+ 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 CACHE_NAME = 'serviceworker/redirected-response';
+
+ var frame;
+ var cache;
+ return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
+ .then(registration => {
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(_ => self.caches.open(CACHE_NAME))
+ .then(c => {
+ cache = c;
+ return with_iframe(SCOPE);
+ })
+ .then(f => {
+ frame = f;
+ return fetch(TARGET_URL);
falken 2016/12/09 01:54:15 What's the purpose of this fetch?
horo 2016/12/09 05:04:11 Removed.
+ })
+ .then(response => {
+ return Promise.all([
+ redirected_test(TARGET_URL, self.fetch, cache,
+ [TARGET_URL]),
+ redirected_test(REDIRECT_TO_TARGET_URL, self.fetch, cache,
+ [REDIRECT_TO_TARGET_URL, TARGET_URL]),
+ redirected_test('./?url=' + encodeURIComponent(TARGET_URL),
+ frame.contentWindow.fetch,
+ cache,
+ [TARGET_URL]),
+ redirected_test(
+ './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL),
+ frame.contentWindow.fetch,
+ cache,
+ [REDIRECT_TO_TARGET_URL, TARGET_URL]),
+ ]);
+ })
+ .then(_ => self.caches.delete(CACHE_NAME))
+ .then(_ => {
+ frame.remove();
+ service_worker_unregister_and_done(t, SCOPE);
falken 2016/12/09 01:54:15 nit: _and_done isn't needed for a promise_test. Th
horo 2016/12/09 05:04:11 Done.
+ });
+ }, 'Verify URL list of responses.');
+</script>

Powered by Google App Engine
This is Rietveld 408576698