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

Side by Side Diff: LayoutTests/http/tests/serviceworker/fetch-event.html

Issue 531423002: ServiceWorker: Clean up fetch-event.html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script> 4 <script src="resources/test-helpers.js"></script>
5 <body> 5 <body>
6 <script> 6 <script>
7 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness 7 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness
8 // timeout before run-webkit-tests does, so it can report the particular 8 // timeout before run-webkit-tests does, so it can report the particular
9 // test that timed out. 9 // test that timed out.
10 // FIXME: Remove after the cause of timeout is fixed. 10 // FIXME: Remove after the cause of timeout is fixed.
11 var properties = {timeout: 5500}; 11 var properties = {timeout: 5500};
12 12
13 var worker = 'resources/fetch-event-test-worker.js'; 13 var worker = 'resources/fetch-event-test-worker.js';
14 14
15 async_test(function(t) { 15 async_test(function(t) {
16 var scope = 'resources/simple.html?string'; 16 var scope = 'resources/simple.html?string';
17 service_worker_unregister_and_register(t, worker, scope) 17 service_worker_unregister_and_register(t, worker, scope)
18 .then(function(registration) { 18 .then(function(registration) {
19 return wait_for_update(t, registration); 19 return wait_for_state(t, registration.installing, 'activated');
horo 2014/09/03 06:13:48 How about introducing wait_for_activated(t, regist
nhiroki 2014/09/04 06:47:09 I'd prefer to keep it as is because I think the be
horo 2014/09/04 09:07:13 I think there are many tests which just need an ac
nhiroki 2014/09/04 09:20:40 "make '.waiting' for 'activated'?" -> "make '.wait
nhiroki 2014/09/05 07:42:09 Done.
20 }) 20 })
21 .then(t.step_func(function(sw) { 21 .then(function() { return with_iframe(scope); })
22 return wait_for_state(t, sw, 'activated'); 22 .then(function(frame) {
23 }))
24 .then(t.step_func(function() { return with_iframe(scope); }))
25 .then(t.step_func(function(frame) {
26 assert_equals( 23 assert_equals(
27 frame.contentDocument.body.textContent, 24 frame.contentDocument.body.textContent,
28 'Test string', 25 'Test string',
29 'Service Worker should respond to fetch with a test string'); 26 'Service Worker should respond to fetch with a test string');
30 assert_equals( 27 assert_equals(
31 frame.contentDocument.contentType, 28 frame.contentDocument.contentType,
32 'text/plain', 29 'text/plain',
33 'The content type of the response created with a string should be te xt/plain'); 30 'The content type of the response created with a string should be te xt/plain');
34 assert_equals( 31 assert_equals(
35 frame.contentDocument.characterSet, 32 frame.contentDocument.characterSet,
36 'UTF-8', 33 'UTF-8',
37 'The character set of the response created with a string should be U TF-8'); 34 'The character set of the response created with a string should be U TF-8');
35 unload_iframe(frame);
38 return service_worker_unregister_and_done(t, scope); 36 return service_worker_unregister_and_done(t, scope);
39 })) 37 })
40 .catch(unreached_rejection(t)); 38 .catch(unreached_rejection(t));
41 }, 'Service Worker responds to fetch event with string', properties); 39 }, 'Service Worker responds to fetch event with string', properties);
42 40
43 async_test(function(t) { 41 async_test(function(t) {
44 var scope = 'resources/simple.html?blob'; 42 var scope = 'resources/simple.html?blob';
45 service_worker_unregister_and_register(t, worker, scope) 43 service_worker_unregister_and_register(t, worker, scope)
46 .then(function(registration) { 44 .then(function(registration) {
47 return wait_for_update(t, registration); 45 return wait_for_state(t, registration.installing, 'activated');
48 }) 46 })
49 .then(t.step_func(function(sw) { 47 .then(function() { return with_iframe(scope); })
50 return wait_for_state(t, sw, 'activated'); 48 .then(function(frame) {
51 }))
52 .then(t.step_func(function() { return with_iframe(scope); }))
53 .then(t.step_func(function(frame) {
54 assert_equals( 49 assert_equals(
55 frame.contentDocument.body.textContent, 50 frame.contentDocument.body.textContent,
56 'Test blob', 51 'Test blob',
57 'Service Worker should respond to fetch with a test string'); 52 'Service Worker should respond to fetch with a test string');
53 unload_iframe(frame);
58 return service_worker_unregister_and_done(t, scope); 54 return service_worker_unregister_and_done(t, scope);
59 })) 55 })
60 .catch(unreached_rejection(t)); 56 .catch(unreached_rejection(t));
61 }, 'Service Worker responds to fetch event with blob body', properties); 57 }, 'Service Worker responds to fetch event with blob body', properties);
62 58
63 async_test(function(t) { 59 async_test(function(t) {
64 var scope = 'resources/simple.html?referrer'; 60 var scope = 'resources/simple.html?referrer';
65 service_worker_unregister_and_register(t, worker, scope) 61 service_worker_unregister_and_register(t, worker, scope)
66 .then(function(registration) { 62 .then(function(registration) {
67 return wait_for_update(t, registration); 63 return wait_for_state(t, registration.installing, 'activated');
68 }) 64 })
69 .then(t.step_func(function(sw) { 65 .then(function() { return with_iframe(scope); })
70 return wait_for_state(t, sw, 'activated'); 66 .then(function(frame) {
71 }))
72 .then(t.step_func(function() { return with_iframe(scope); }))
73 .then(t.step_func(function(frame) {
74 assert_equals( 67 assert_equals(
75 frame.contentDocument.body.textContent, 68 frame.contentDocument.body.textContent,
76 'Referrer: ' + document.location.href, 69 'Referrer: ' + document.location.href,
77 'Service Worker should respond to fetch with the referrer URL'); 70 'Service Worker should respond to fetch with the referrer URL');
71 unload_iframe(frame);
78 return service_worker_unregister_and_done(t, scope); 72 return service_worker_unregister_and_done(t, scope);
79 })) 73 })
80 .catch(unreached_rejection(t)); 74 .catch(unreached_rejection(t));
81 }, 'Service Worker responds to fetch event with the referrer URL', properties) ; 75 }, 'Service Worker responds to fetch event with the referrer URL', properties) ;
82 76
83 async_test(function(t) { 77 async_test(function(t) {
84 var scope = 'resources/simple.html?ignore'; 78 var scope = 'resources/simple.html?ignore';
85 service_worker_unregister_and_register(t, worker, scope) 79 service_worker_unregister_and_register(t, worker, scope)
86 .then(function(registration) { 80 .then(function(registration) {
87 return wait_for_update(t, registration); 81 return wait_for_state(t, registration.installing, 'activated');
88 }) 82 })
89 .then(t.step_func(function(sw) { 83 .then(function() { return with_iframe(scope); })
90 return wait_for_state(t, sw, 'activated'); 84 .then(function(frame) {
91 }))
92 .then(t.step_func(function() { return with_iframe(scope); }))
93 .then(t.step_func(function(frame) {
94 assert_equals(frame.contentDocument.body.textContent, 85 assert_equals(frame.contentDocument.body.textContent,
95 'Here\'s a simple html file.\n', 86 'Here\'s a simple html file.\n',
96 'Response should come from fallback to native fetch'); 87 'Response should come from fallback to native fetch');
88 unload_iframe(frame);
97 return service_worker_unregister_and_done(t, scope); 89 return service_worker_unregister_and_done(t, scope);
98 })) 90 })
99 .catch(unreached_rejection(t)); 91 .catch(unreached_rejection(t));
100 }, 'Service Worker does not respond to fetch event', properties); 92 }, 'Service Worker does not respond to fetch event', properties);
101 93
102 async_test(function(t) { 94 async_test(function(t) {
103 var scope = 'resources/simple.html?null'; 95 var scope = 'resources/simple.html?null';
104 service_worker_unregister_and_register(t, worker, scope) 96 service_worker_unregister_and_register(t, worker, scope)
105 .then(function(registration) { 97 .then(function(registration) {
106 return wait_for_update(t, registration); 98 return wait_for_state(t, registration.installing, 'activated');
107 }) 99 })
108 .then(t.step_func(function(sw) { 100 .then(function() { return with_iframe(scope); })
109 return wait_for_state(t, sw, 'activated'); 101 .then(function(frame) {
110 }))
111 .then(t.step_func(function() { return with_iframe(scope); }))
112 .then(t.step_func(function(frame) {
113 assert_equals(frame.contentDocument.body.textContent, 102 assert_equals(frame.contentDocument.body.textContent,
114 '', 103 '',
115 'Response should be the empty string'); 104 'Response should be the empty string');
105 unload_iframe(frame);
116 return service_worker_unregister_and_done(t, scope); 106 return service_worker_unregister_and_done(t, scope);
117 })) 107 })
118 .catch(unreached_rejection(t)); 108 .catch(unreached_rejection(t));
119 }, 'Service Worker responds to fetch event with null response body', propertie s); 109 }, 'Service Worker responds to fetch event with null response body', propertie s);
120 110
121 async_test(function(t) { 111 async_test(function(t) {
122 var scope = 'resources/simple.html?reject'; 112 var scope = 'resources/simple.html?reject';
123 service_worker_unregister_and_register(t, worker, scope) 113 service_worker_unregister_and_register(t, worker, scope)
124 .then(function(registration) { 114 .then(function(registration) {
125 return wait_for_update(t, registration); 115 return wait_for_state(t, registration.installing, 'activated');
126 }) 116 })
127 .then(t.step_func(function(sw) { 117 .then(function() { return with_iframe(scope); })
128 return wait_for_state(t, sw, 'activated'); 118 .then(function(frame) {
129 }))
130 .then(t.step_func(function() { return with_iframe(scope); }))
131 .then(t.step_func(function(frame) {
132 assert_equals(frame.contentDocument.body.textContent, 119 assert_equals(frame.contentDocument.body.textContent,
133 'Here\'s a simple html file.\n', 120 'Here\'s a simple html file.\n',
134 'Response should come from fallback to native fetch'); 121 'Response should come from fallback to native fetch');
122 unload_iframe(frame);
135 return service_worker_unregister_and_done(t, scope); 123 return service_worker_unregister_and_done(t, scope);
136 })) 124 })
137 .catch(unreached_rejection(t)); 125 .catch(unreached_rejection(t));
138 }, 'Service Worker rejects fetch event', properties); 126 }, 'Service Worker rejects fetch event', properties);
139 127
140 async_test(function(t) { 128 async_test(function(t) {
141 var scope = 'resources/simple.html?fetch'; 129 var scope = 'resources/simple.html?fetch';
142 service_worker_unregister_and_register(t, worker, scope) 130 service_worker_unregister_and_register(t, worker, scope)
143 .then(function(registration) { 131 .then(function(registration) {
144 return wait_for_update(t, registration); 132 return wait_for_state(t, registration.installing, 'activated');
145 }) 133 })
146 .then(t.step_func(function(sw) { 134 .then(function() { return with_iframe(scope); })
147 return wait_for_state(t, sw, 'activated'); 135 .then(function(frame) {
148 }))
149 .then(t.step_func(function() { return with_iframe(scope); }))
150 .then(t.step_func(function(frame) {
151 assert_equals(frame.contentDocument.body.textContent, 136 assert_equals(frame.contentDocument.body.textContent,
152 'Here\'s an other html file.\n', 137 'Here\'s an other html file.\n',
153 'Response should come from fetched other file'); 138 'Response should come from fetched other file');
139 unload_iframe(frame);
154 return service_worker_unregister_and_done(t, scope); 140 return service_worker_unregister_and_done(t, scope);
155 })) 141 })
156 .catch(unreached_rejection(t)); 142 .catch(unreached_rejection(t));
157 }, 'Service Worker fetches other file in fetch event', properties); 143 }, 'Service Worker fetches other file in fetch event', properties);
158 144
159 async_test(function(t) { 145 async_test(function(t) {
160 var scope = 'resources/simple.html?form-post'; 146 var scope = 'resources/simple.html?form-post';
161 var frame_name = 'xhr-post-frame'; 147 var frame_name = 'xhr-post-frame';
162 service_worker_unregister_and_register(t, worker, scope) 148 service_worker_unregister_and_register(t, worker, scope)
163 .then(function(registration) { 149 .then(t.step_func(function(registration) {
164 return wait_for_update(t, registration); 150 return wait_for_state(t, registration.installing, 'activated');
165 })
166 .then(t.step_func(function(sw) {
167 return wait_for_state(t, sw, 'activated');
168 })) 151 }))
169 .then(t.step_func(function(sw) { 152 .then(function(sw) {
170 return new Promise(function(resolve) { 153 return new Promise(function(resolve) {
171 var frame = document.createElement('iframe'); 154 var frame = document.createElement('iframe');
172 frame.name = frame_name; 155 frame.name = frame_name;
173 document.body.appendChild(frame); 156 document.body.appendChild(frame);
174 var form = document.createElement('form'); 157 var form = document.createElement('form');
175 form.target = frame_name; 158 form.target = frame_name;
176 form.action = scope; 159 form.action = scope;
177 form.method = 'post'; 160 form.method = 'post';
178 var input1 = document.createElement('input'); 161 var input1 = document.createElement('input');
179 input1.type = 'text'; 162 input1.type = 'text';
180 input1.value = 'testValue1'; 163 input1.value = 'testValue1';
181 input1.name = 'testName1' 164 input1.name = 'testName1'
182 form.appendChild(input1); 165 form.appendChild(input1);
183 var input2 = document.createElement('input'); 166 var input2 = document.createElement('input');
184 input2.type = 'text'; 167 input2.type = 'text';
185 input2.value = 'testValue2'; 168 input2.value = 'testValue2';
186 input2.name = 'testName2' 169 input2.name = 'testName2'
187 form.appendChild(input2); 170 form.appendChild(input2);
188 document.body.appendChild(form); 171 document.body.appendChild(form);
189 frame.onload = function() { 172 frame.onload = function() {
190 document.body.removeChild(form); 173 document.body.removeChild(form);
191 resolve(frame); 174 resolve(frame);
192 }; 175 };
193 form.submit(); 176 form.submit();
194 }); 177 });
195 })) 178 })
196 .then(t.step_func(function(frame) { 179 .then(function(frame) {
197 assert_equals(frame.contentDocument.body.textContent, 180 assert_equals(frame.contentDocument.body.textContent,
198 'POST:testName1=testValue1&testName2=testValue2'); 181 'POST:testName1=testValue1&testName2=testValue2');
199 document.body.removeChild(frame); 182 document.body.removeChild(frame);
200 return service_worker_unregister_and_done(t, scope); 183 return service_worker_unregister_and_done(t, scope);
201 })) 184 })
202 .catch(unreached_rejection(t)); 185 .catch(unreached_rejection(t));
203 }, 'Service Worker responds to fetch event with POST form', properties); 186 }, 'Service Worker responds to fetch event with POST form', properties);
204 </script> 187 </script>
205 </body> 188 </body>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698