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

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

Issue 2878003003: Upstream srvc wrkr "redirected resp" test to WPT (Closed)
Patch Set: Improve in-line comments Created 3 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Service Worker: Redirected response</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="../resources/get-host-info.js?pipe=sub"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
8
9 function redirected_test(url,
10 fetch_option,
11 fetch_method,
12 cache,
13 expected_redirected,
14 expected_url_list) {
15 return fetch_method(url, fetch_option).then(response => {
16 var cloned_response = response.clone();
17 assert_equals(
18 response.redirected, expected_redirected,
19 'The redirected flag of response must match. URL: ' + url);
20 assert_equals(
21 cloned_response.redirected, expected_redirected,
22 'The redirected flag of cloned response must match. URL: ' + url);
23 if (self.internals) {
24 assert_array_equals(
25 self.internals.getInternalResponseURLList(response),
26 expected_url_list,
27 'The URL list of response must match. URL: ' + url);
28 assert_array_equals(
29 self.internals.getInternalResponseURLList(cloned_response),
30 expected_url_list,
31 'The URL list of cloned response must match. URL: ' + url);
32 }
33 return cache.put(url, response);
34 })
35 .then(_ => cache.match(url))
36 .then(response => {
37 assert_equals(response.redirected, expected_redirected,
38 'The redirected flag of response in CacheStorage must match. URL: ' +
39 url);
40 if (self.internals) {
41 assert_array_equals(
42 self.internals.getInternalResponseURLList(response),
43 expected_url_list,
44 'The URL list of response in CacheStorage must match. URL: ' +
45 url);
46 }
47 });
48 }
49
50 promise_test(t => {
51 var SCOPE = 'resources/blank.html?redirected-response';
52 var SCRIPT = 'resources/fetch-rewrite-worker.js';
53 var host_info = get_host_info();
54 var REDIRECT_URL = host_info['HTTP_ORIGIN'] +
55 '/serviceworker/resources/redirect.php?Redirect=';
56 var TARGET_URL = host_info['HTTP_ORIGIN'] +
57 '/serviceworker/resources/simple.txt';
58 var REDIRECT_TO_TARGET_URL = REDIRECT_URL + encodeURIComponent(TARGET_URL);
59 var CACHE_NAME = 'serviceworker/redirected-response';
60
61 var frame;
62 var cache;
63 return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
64 .then(registration => {
65 return wait_for_state(t, registration.installing, 'activated');
66 })
67 .then(_ => self.caches.open(CACHE_NAME))
68 .then(c => {
69 cache = c;
70 return with_iframe(SCOPE);
71 })
72 .then(f => {
73 frame = f;
74 return Promise.all([
75 // Tests without service workers.
76 redirected_test(TARGET_URL, {}, self.fetch, cache,
77 false /* expected_redirected */,
78 [TARGET_URL]),
79 redirected_test(REDIRECT_TO_TARGET_URL, {}, self.fetch, cache,
80 true /* expected_redirected */,
81 [REDIRECT_TO_TARGET_URL, TARGET_URL]),
82 redirected_test(REDIRECT_TO_TARGET_URL + '&manual',
83 {redirect: 'manual'}, self.fetch, cache,
84 false /* expected_redirected */,
85 [REDIRECT_TO_TARGET_URL + '&manual']),
86 promise_rejects(
87 t, new TypeError(),
88 self.fetch(REDIRECT_TO_TARGET_URL + '&error',
89 {redirect:'error'}),
90 'The redirect response from the server should be treated as' +
91 ' an error when the redirect flag of request was \'error\'.'),
92
93 // Tests without redirects with service worker.
94 redirected_test('./?url=' + encodeURIComponent(TARGET_URL),
95 {},
96 frame.contentWindow.fetch,
97 cache,
98 false /* expected_redirected */,
99 [TARGET_URL]),
100
101 // The service worker returns a redirected response.
102 redirected_test(
103 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
104 '&original-redirect-mode=follow',
105 {redirect: 'follow'},
106 frame.contentWindow.fetch,
107 cache,
108 true /* expected_redirected */,
109 [REDIRECT_TO_TARGET_URL, TARGET_URL]),
110 promise_rejects(
111 t, new TypeError(),
112 frame.contentWindow.fetch(
113 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
114 '&original-redirect-mode=error',
115 {redirect: 'error'}),
116 'The redirected response from the service worker should be ' +
117 'treated as an error when the redirect flag of request was ' +
118 '\'error\'.'),
119 promise_rejects(
120 t, new TypeError(),
121 frame.contentWindow.fetch(
122 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
123 '&original-redirect-mode=manual',
124 {redirect: 'manual'}),
125 'The redirected response from the service worker should be ' +
126 'treated as an error when the redirect flag of request was ' +
127 '\'manual\'.'),
128
129 // The service worker returns an opaqueredirect response.
130 promise_rejects(
131 t, new TypeError(),
132 frame.contentWindow.fetch(
133 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
134 '&original-redirect-mode=follow&redirect-mode=manual',
135 {redirect: 'follow'}),
136 'The opaqueredirect response from the service worker should ' +
137 'be treated as an error when the redirect flag of request was' +
138 ' \'follow\'.'),
139 promise_rejects(
140 t, new TypeError(),
141 frame.contentWindow.fetch(
142 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
143 '&original-redirect-mode=error&redirect-mode=manual',
144 {redirect: 'error'}),
145 'The opaqueredirect response from the service worker should ' +
146 'be treated as an error when the redirect flag of request was' +
147 ' \'error\'.'),
148 redirected_test(
149 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
150 '&original-redirect-mode=manual&redirect-mode=manual',
151 {redirect: 'manual'},
152 frame.contentWindow.fetch,
153 cache,
154 false /* expected_redirected */,
155 [REDIRECT_TO_TARGET_URL]),
156 ]);
157 })
158 .then(_ => self.caches.delete(CACHE_NAME))
159 .then(_ => {
160 frame.remove();
161 return service_worker_unregister(t, SCOPE);
162 });
163 }, 'Verify redirected flag of responses.');
164 </script>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698