OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 protected: | 123 protected: |
124 TestBrowserThreadBundle browser_thread_bundle_; | 124 TestBrowserThreadBundle browser_thread_bundle_; |
125 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 125 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
126 int render_process_id_; | 126 int render_process_id_; |
127 }; | 127 }; |
128 | 128 |
129 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { | 129 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { |
130 scoped_refptr<ServiceWorkerRegistration> original_registration; | 130 scoped_refptr<ServiceWorkerRegistration> original_registration; |
131 bool called; | 131 bool called; |
132 job_coordinator()->Register( | 132 job_coordinator()->Register( |
133 GURL("http://www.example.com/*"), | 133 GURL("http://www.example.com/"), |
134 GURL("http://www.example.com/service_worker.js"), | 134 GURL("http://www.example.com/service_worker.js"), |
135 render_process_id_, | 135 render_process_id_, |
136 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | 136 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
137 EXPECT_FALSE(called); | 137 EXPECT_FALSE(called); |
138 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
139 EXPECT_TRUE(called); | 139 EXPECT_TRUE(called); |
140 | 140 |
141 scoped_refptr<ServiceWorkerRegistration> registration1; | 141 scoped_refptr<ServiceWorkerRegistration> registration1; |
142 storage()->FindRegistrationForDocument( | 142 storage()->FindRegistrationForDocument( |
143 GURL("http://www.example.com/"), | 143 GURL("http://www.example.com/"), |
144 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); | 144 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); |
145 scoped_refptr<ServiceWorkerRegistration> registration2; | 145 scoped_refptr<ServiceWorkerRegistration> registration2; |
146 storage()->FindRegistrationForDocument( | 146 storage()->FindRegistrationForDocument( |
147 GURL("http://www.example.com/"), | 147 GURL("http://www.example.com/"), |
148 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); | 148 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); |
149 base::RunLoop().RunUntilIdle(); | 149 base::RunLoop().RunUntilIdle(); |
150 EXPECT_TRUE(called); | 150 EXPECT_TRUE(called); |
151 ASSERT_TRUE(registration1); | 151 ASSERT_TRUE(registration1); |
152 ASSERT_EQ(registration1, original_registration); | 152 ASSERT_EQ(registration1, original_registration); |
153 ASSERT_EQ(registration1, registration2); | 153 ASSERT_EQ(registration1, registration2); |
154 } | 154 } |
155 | 155 |
156 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { | 156 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { |
157 bool called; | 157 bool called; |
158 scoped_refptr<ServiceWorkerRegistration> original_registration; | 158 scoped_refptr<ServiceWorkerRegistration> original_registration; |
159 job_coordinator()->Register( | 159 job_coordinator()->Register( |
160 GURL("http://www.example.com/*"), | 160 GURL("http://www.example.com/"), |
161 GURL("http://www.example.com/service_worker.js"), | 161 GURL("http://www.example.com/service_worker.js"), |
162 render_process_id_, | 162 render_process_id_, |
163 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); | 163 SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
164 EXPECT_FALSE(called); | 164 EXPECT_FALSE(called); |
165 base::RunLoop().RunUntilIdle(); | 165 base::RunLoop().RunUntilIdle(); |
166 EXPECT_TRUE(called); | 166 EXPECT_TRUE(called); |
167 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), | 167 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), |
168 original_registration.get()); | 168 original_registration.get()); |
169 | 169 |
170 scoped_refptr<ServiceWorkerRegistration> registration1; | 170 scoped_refptr<ServiceWorkerRegistration> registration1; |
(...skipping 10 matching lines...) Expand all Loading... |
181 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
182 EXPECT_TRUE(called); | 182 EXPECT_TRUE(called); |
183 ASSERT_EQ(registration1, original_registration); | 183 ASSERT_EQ(registration1, original_registration); |
184 ASSERT_EQ(registration1, registration2); | 184 ASSERT_EQ(registration1, registration2); |
185 } | 185 } |
186 | 186 |
187 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { | 187 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { |
188 bool called1; | 188 bool called1; |
189 scoped_refptr<ServiceWorkerRegistration> original_registration1; | 189 scoped_refptr<ServiceWorkerRegistration> original_registration1; |
190 job_coordinator()->Register( | 190 job_coordinator()->Register( |
191 GURL("http://www.example.com/one/*"), | 191 GURL("http://www.example.com/one/"), |
192 GURL("http://www.example.com/service_worker.js"), | 192 GURL("http://www.example.com/service_worker.js"), |
193 render_process_id_, | 193 render_process_id_, |
194 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); | 194 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); |
195 | 195 |
196 bool called2; | 196 bool called2; |
197 scoped_refptr<ServiceWorkerRegistration> original_registration2; | 197 scoped_refptr<ServiceWorkerRegistration> original_registration2; |
198 job_coordinator()->Register( | 198 job_coordinator()->Register( |
199 GURL("http://www.example.com/two/*"), | 199 GURL("http://www.example.com/two/"), |
200 GURL("http://www.example.com/service_worker.js"), | 200 GURL("http://www.example.com/service_worker.js"), |
201 render_process_id_, | 201 render_process_id_, |
202 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); | 202 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); |
203 | 203 |
204 EXPECT_FALSE(called1); | 204 EXPECT_FALSE(called1); |
205 EXPECT_FALSE(called2); | 205 EXPECT_FALSE(called2); |
206 base::RunLoop().RunUntilIdle(); | 206 base::RunLoop().RunUntilIdle(); |
207 EXPECT_TRUE(called2); | 207 EXPECT_TRUE(called2); |
208 EXPECT_TRUE(called1); | 208 EXPECT_TRUE(called1); |
209 | 209 |
(...skipping 10 matching lines...) Expand all Loading... |
220 EXPECT_TRUE(called2); | 220 EXPECT_TRUE(called2); |
221 EXPECT_TRUE(called1); | 221 EXPECT_TRUE(called1); |
222 ASSERT_NE(registration1, registration2); | 222 ASSERT_NE(registration1, registration2); |
223 } | 223 } |
224 | 224 |
225 // Make sure basic registration is working. | 225 // Make sure basic registration is working. |
226 TEST_F(ServiceWorkerJobTest, Register) { | 226 TEST_F(ServiceWorkerJobTest, Register) { |
227 bool called = false; | 227 bool called = false; |
228 scoped_refptr<ServiceWorkerRegistration> registration; | 228 scoped_refptr<ServiceWorkerRegistration> registration; |
229 job_coordinator()->Register( | 229 job_coordinator()->Register( |
230 GURL("http://www.example.com/*"), | 230 GURL("http://www.example.com/"), |
231 GURL("http://www.example.com/service_worker.js"), | 231 GURL("http://www.example.com/service_worker.js"), |
232 render_process_id_, | 232 render_process_id_, |
233 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 233 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
234 | 234 |
235 ASSERT_FALSE(called); | 235 ASSERT_FALSE(called); |
236 base::RunLoop().RunUntilIdle(); | 236 base::RunLoop().RunUntilIdle(); |
237 ASSERT_TRUE(called); | 237 ASSERT_TRUE(called); |
238 | 238 |
239 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 239 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
240 } | 240 } |
241 | 241 |
242 // Make sure registrations are cleaned up when they are unregistered. | 242 // Make sure registrations are cleaned up when they are unregistered. |
243 TEST_F(ServiceWorkerJobTest, Unregister) { | 243 TEST_F(ServiceWorkerJobTest, Unregister) { |
244 GURL pattern("http://www.example.com/*"); | 244 GURL pattern("http://www.example.com/"); |
245 | 245 |
246 bool called; | 246 bool called; |
247 scoped_refptr<ServiceWorkerRegistration> registration; | 247 scoped_refptr<ServiceWorkerRegistration> registration; |
248 job_coordinator()->Register( | 248 job_coordinator()->Register( |
249 pattern, | 249 pattern, |
250 GURL("http://www.example.com/service_worker.js"), | 250 GURL("http://www.example.com/service_worker.js"), |
251 render_process_id_, | 251 render_process_id_, |
252 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 252 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
253 | 253 |
254 ASSERT_FALSE(called); | 254 ASSERT_FALSE(called); |
(...skipping 15 matching lines...) Expand all Loading... |
270 &called, ®istration)); | 270 &called, ®istration)); |
271 | 271 |
272 ASSERT_FALSE(called); | 272 ASSERT_FALSE(called); |
273 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
274 ASSERT_TRUE(called); | 274 ASSERT_TRUE(called); |
275 | 275 |
276 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 276 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
277 } | 277 } |
278 | 278 |
279 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { | 279 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { |
280 GURL pattern("http://www.example.com/*"); | 280 GURL pattern("http://www.example.com/"); |
281 | 281 |
282 bool called; | 282 bool called; |
283 job_coordinator()->Unregister(pattern, | 283 job_coordinator()->Unregister(pattern, |
284 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 284 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
285 | 285 |
286 ASSERT_FALSE(called); | 286 ASSERT_FALSE(called); |
287 base::RunLoop().RunUntilIdle(); | 287 base::RunLoop().RunUntilIdle(); |
288 ASSERT_TRUE(called); | 288 ASSERT_TRUE(called); |
289 } | 289 } |
290 | 290 |
291 // Make sure that when a new registration replaces an existing | 291 // Make sure that when a new registration replaces an existing |
292 // registration, that the old one is cleaned up. | 292 // registration, that the old one is cleaned up. |
293 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { | 293 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
294 GURL pattern("http://www.example.com/*"); | 294 GURL pattern("http://www.example.com/"); |
295 | 295 |
296 bool called; | 296 bool called; |
297 scoped_refptr<ServiceWorkerRegistration> old_registration; | 297 scoped_refptr<ServiceWorkerRegistration> old_registration; |
298 job_coordinator()->Register( | 298 job_coordinator()->Register( |
299 pattern, | 299 pattern, |
300 GURL("http://www.example.com/service_worker.js"), | 300 GURL("http://www.example.com/service_worker.js"), |
301 render_process_id_, | 301 render_process_id_, |
302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 302 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
303 | 303 |
304 ASSERT_FALSE(called); | 304 ASSERT_FALSE(called); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 ASSERT_FALSE(called); | 342 ASSERT_FALSE(called); |
343 base::RunLoop().RunUntilIdle(); | 343 base::RunLoop().RunUntilIdle(); |
344 ASSERT_TRUE(called); | 344 ASSERT_TRUE(called); |
345 | 345 |
346 ASSERT_NE(new_registration_by_pattern, old_registration); | 346 ASSERT_NE(new_registration_by_pattern, old_registration); |
347 } | 347 } |
348 | 348 |
349 // Make sure that when registering a duplicate pattern+script_url | 349 // Make sure that when registering a duplicate pattern+script_url |
350 // combination, that the same registration is used. | 350 // combination, that the same registration is used. |
351 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { | 351 TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { |
352 GURL pattern("http://www.example.com/*"); | 352 GURL pattern("http://www.example.com/"); |
353 GURL script_url("http://www.example.com/service_worker.js"); | 353 GURL script_url("http://www.example.com/service_worker.js"); |
354 | 354 |
355 bool called; | 355 bool called; |
356 scoped_refptr<ServiceWorkerRegistration> old_registration; | 356 scoped_refptr<ServiceWorkerRegistration> old_registration; |
357 job_coordinator()->Register( | 357 job_coordinator()->Register( |
358 pattern, | 358 pattern, |
359 script_url, | 359 script_url, |
360 render_process_id_, | 360 render_process_id_, |
361 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); | 361 SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
362 | 362 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 417 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
418 } | 418 } |
419 }; | 419 }; |
420 | 420 |
421 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 421 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
422 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); | 422 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); |
423 | 423 |
424 bool called = false; | 424 bool called = false; |
425 scoped_refptr<ServiceWorkerRegistration> registration; | 425 scoped_refptr<ServiceWorkerRegistration> registration; |
426 job_coordinator()->Register( | 426 job_coordinator()->Register( |
427 GURL("http://www.example.com/*"), | 427 GURL("http://www.example.com/"), |
428 GURL("http://www.example.com/service_worker.js"), | 428 GURL("http://www.example.com/service_worker.js"), |
429 render_process_id_, | 429 render_process_id_, |
430 SaveRegistration( | 430 SaveRegistration( |
431 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, ®istration)); | 431 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, ®istration)); |
432 | 432 |
433 ASSERT_FALSE(called); | 433 ASSERT_FALSE(called); |
434 base::RunLoop().RunUntilIdle(); | 434 base::RunLoop().RunUntilIdle(); |
435 | 435 |
436 ASSERT_TRUE(called); | 436 ASSERT_TRUE(called); |
437 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 437 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
438 } | 438 } |
439 | 439 |
440 // Register and then unregister the pattern, in parallel. Job coordinator should | 440 // Register and then unregister the pattern, in parallel. Job coordinator should |
441 // process jobs until the last job. | 441 // process jobs until the last job. |
442 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { | 442 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { |
443 GURL pattern("http://www.example.com/*"); | 443 GURL pattern("http://www.example.com/"); |
444 GURL script_url("http://www.example.com/service_worker.js"); | 444 GURL script_url("http://www.example.com/service_worker.js"); |
445 | 445 |
446 bool registration_called = false; | 446 bool registration_called = false; |
447 scoped_refptr<ServiceWorkerRegistration> registration; | 447 scoped_refptr<ServiceWorkerRegistration> registration; |
448 job_coordinator()->Register( | 448 job_coordinator()->Register( |
449 pattern, | 449 pattern, |
450 script_url, | 450 script_url, |
451 render_process_id_, | 451 render_process_id_, |
452 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); | 452 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
453 | 453 |
(...skipping 16 matching lines...) Expand all Loading... |
470 | 470 |
471 base::RunLoop().RunUntilIdle(); | 471 base::RunLoop().RunUntilIdle(); |
472 | 472 |
473 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 473 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
474 } | 474 } |
475 | 475 |
476 // Register conflicting scripts for the same pattern. The most recent | 476 // Register conflicting scripts for the same pattern. The most recent |
477 // registration should win, and the old registration should have been | 477 // registration should win, and the old registration should have been |
478 // shutdown. | 478 // shutdown. |
479 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { | 479 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
480 GURL pattern("http://www.example.com/*"); | 480 GURL pattern("http://www.example.com/"); |
481 | 481 |
482 GURL script_url1("http://www.example.com/service_worker1.js"); | 482 GURL script_url1("http://www.example.com/service_worker1.js"); |
483 bool registration1_called = false; | 483 bool registration1_called = false; |
484 scoped_refptr<ServiceWorkerRegistration> registration1; | 484 scoped_refptr<ServiceWorkerRegistration> registration1; |
485 job_coordinator()->Register( | 485 job_coordinator()->Register( |
486 pattern, | 486 pattern, |
487 script_url1, | 487 script_url1, |
488 render_process_id_, | 488 render_process_id_, |
489 SaveRegistration( | 489 SaveRegistration( |
490 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | 490 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); |
(...skipping 23 matching lines...) Expand all Loading... |
514 | 514 |
515 base::RunLoop().RunUntilIdle(); | 515 base::RunLoop().RunUntilIdle(); |
516 | 516 |
517 ASSERT_EQ(registration2, registration); | 517 ASSERT_EQ(registration2, registration); |
518 } | 518 } |
519 | 519 |
520 // Register the exact same pattern + script. Requests should be | 520 // Register the exact same pattern + script. Requests should be |
521 // coalesced such that both callers get the exact same registration | 521 // coalesced such that both callers get the exact same registration |
522 // object. | 522 // object. |
523 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { | 523 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
524 GURL pattern("http://www.example.com/*"); | 524 GURL pattern("http://www.example.com/"); |
525 | 525 |
526 GURL script_url("http://www.example.com/service_worker1.js"); | 526 GURL script_url("http://www.example.com/service_worker1.js"); |
527 bool registration1_called = false; | 527 bool registration1_called = false; |
528 scoped_refptr<ServiceWorkerRegistration> registration1; | 528 scoped_refptr<ServiceWorkerRegistration> registration1; |
529 job_coordinator()->Register( | 529 job_coordinator()->Register( |
530 pattern, | 530 pattern, |
531 script_url, | 531 script_url, |
532 render_process_id_, | 532 render_process_id_, |
533 SaveRegistration( | 533 SaveRegistration( |
534 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | 534 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); |
(...skipping 21 matching lines...) Expand all Loading... |
556 pattern, | 556 pattern, |
557 SaveFoundRegistration( | 557 SaveFoundRegistration( |
558 SERVICE_WORKER_OK, &find_called, ®istration)); | 558 SERVICE_WORKER_OK, &find_called, ®istration)); |
559 | 559 |
560 base::RunLoop().RunUntilIdle(); | 560 base::RunLoop().RunUntilIdle(); |
561 ASSERT_EQ(registration, registration1); | 561 ASSERT_EQ(registration, registration1); |
562 } | 562 } |
563 | 563 |
564 // Call simulataneous unregister calls. | 564 // Call simulataneous unregister calls. |
565 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { | 565 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { |
566 GURL pattern("http://www.example.com/*"); | 566 GURL pattern("http://www.example.com/"); |
567 | 567 |
568 GURL script_url("http://www.example.com/service_worker.js"); | 568 GURL script_url("http://www.example.com/service_worker.js"); |
569 bool unregistration1_called = false; | 569 bool unregistration1_called = false; |
570 job_coordinator()->Unregister( | 570 job_coordinator()->Unregister( |
571 pattern, | 571 pattern, |
572 SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); | 572 SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); |
573 | 573 |
574 bool unregistration2_called = false; | 574 bool unregistration2_called = false; |
575 job_coordinator()->Unregister( | 575 job_coordinator()->Unregister( |
576 pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); | 576 pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); |
(...skipping 12 matching lines...) Expand all Loading... |
589 storage()->FindRegistrationForPattern( | 589 storage()->FindRegistrationForPattern( |
590 pattern, | 590 pattern, |
591 SaveFoundRegistration( | 591 SaveFoundRegistration( |
592 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | 592 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); |
593 | 593 |
594 base::RunLoop().RunUntilIdle(); | 594 base::RunLoop().RunUntilIdle(); |
595 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 595 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
596 } | 596 } |
597 | 597 |
598 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { | 598 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { |
599 GURL pattern1("http://www1.example.com/*"); | 599 GURL pattern1("http://www1.example.com/"); |
600 GURL pattern2("http://www2.example.com/*"); | 600 GURL pattern2("http://www2.example.com/"); |
601 GURL script_url1("http://www1.example.com/service_worker.js"); | 601 GURL script_url1("http://www1.example.com/service_worker.js"); |
602 GURL script_url2("http://www2.example.com/service_worker.js"); | 602 GURL script_url2("http://www2.example.com/service_worker.js"); |
603 | 603 |
604 bool registration_called1 = false; | 604 bool registration_called1 = false; |
605 scoped_refptr<ServiceWorkerRegistration> registration1; | 605 scoped_refptr<ServiceWorkerRegistration> registration1; |
606 job_coordinator()->Register( | 606 job_coordinator()->Register( |
607 pattern1, | 607 pattern1, |
608 script_url1, | 608 script_url1, |
609 render_process_id_, | 609 render_process_id_, |
610 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | 610 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, |
(...skipping 29 matching lines...) Expand all Loading... |
640 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called2, ®istration2)); | 640 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called2, ®istration2)); |
641 | 641 |
642 base::RunLoop().RunUntilIdle(); | 642 base::RunLoop().RunUntilIdle(); |
643 ASSERT_TRUE(find_called1); | 643 ASSERT_TRUE(find_called1); |
644 ASSERT_TRUE(find_called2); | 644 ASSERT_TRUE(find_called2); |
645 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1); | 645 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1); |
646 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2); | 646 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2); |
647 } | 647 } |
648 | 648 |
649 TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { | 649 TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { |
650 GURL pattern1("http://www1.example.com/*"); | 650 GURL pattern1("http://www1.example.com/"); |
651 GURL pattern2("http://www2.example.com/*"); | 651 GURL pattern2("http://www2.example.com/"); |
652 | 652 |
653 bool unregistration_called1 = false; | 653 bool unregistration_called1 = false; |
654 scoped_refptr<ServiceWorkerRegistration> registration1; | 654 scoped_refptr<ServiceWorkerRegistration> registration1; |
655 job_coordinator()->Unregister( | 655 job_coordinator()->Unregister( |
656 pattern1, | 656 pattern1, |
657 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | 657 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, |
658 &unregistration_called1)); | 658 &unregistration_called1)); |
659 | 659 |
660 bool unregistration_called2 = false; | 660 bool unregistration_called2 = false; |
661 job_coordinator()->Unregister( | 661 job_coordinator()->Unregister( |
662 pattern2, | 662 pattern2, |
663 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | 663 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, |
664 &unregistration_called2)); | 664 &unregistration_called2)); |
665 | 665 |
666 ASSERT_FALSE(unregistration_called1); | 666 ASSERT_FALSE(unregistration_called1); |
667 ASSERT_FALSE(unregistration_called2); | 667 ASSERT_FALSE(unregistration_called2); |
668 job_coordinator()->AbortAll(); | 668 job_coordinator()->AbortAll(); |
669 | 669 |
670 base::RunLoop().RunUntilIdle(); | 670 base::RunLoop().RunUntilIdle(); |
671 ASSERT_TRUE(unregistration_called1); | 671 ASSERT_TRUE(unregistration_called1); |
672 ASSERT_TRUE(unregistration_called2); | 672 ASSERT_TRUE(unregistration_called2); |
673 } | 673 } |
674 | 674 |
675 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { | 675 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { |
676 GURL pattern("http://www.example.com/*"); | 676 GURL pattern("http://www.example.com/"); |
677 GURL script_url("http://www.example.com/service_worker.js"); | 677 GURL script_url("http://www.example.com/service_worker.js"); |
678 | 678 |
679 bool registration_called = false; | 679 bool registration_called = false; |
680 scoped_refptr<ServiceWorkerRegistration> registration; | 680 scoped_refptr<ServiceWorkerRegistration> registration; |
681 job_coordinator()->Register( | 681 job_coordinator()->Register( |
682 pattern, | 682 pattern, |
683 script_url, | 683 script_url, |
684 render_process_id_, | 684 render_process_id_, |
685 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | 685 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, |
686 ®istration_called, ®istration)); | 686 ®istration_called, ®istration)); |
(...skipping 22 matching lines...) Expand all Loading... |
709 ASSERT_TRUE(find_called); | 709 ASSERT_TRUE(find_called); |
710 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 710 EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
711 } | 711 } |
712 | 712 |
713 // Tests that the waiting worker enters the 'redundant' state upon | 713 // Tests that the waiting worker enters the 'redundant' state upon |
714 // unregistration. | 714 // unregistration. |
715 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { | 715 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { |
716 scoped_refptr<ServiceWorkerRegistration> registration; | 716 scoped_refptr<ServiceWorkerRegistration> registration; |
717 bool called = false; | 717 bool called = false; |
718 job_coordinator()->Register( | 718 job_coordinator()->Register( |
719 GURL("http://www.example.com/*"), | 719 GURL("http://www.example.com/"), |
720 GURL("http://www.example.com/service_worker.js"), | 720 GURL("http://www.example.com/service_worker.js"), |
721 render_process_id_, | 721 render_process_id_, |
722 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 722 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
723 base::RunLoop().RunUntilIdle(); | 723 base::RunLoop().RunUntilIdle(); |
724 ASSERT_TRUE(called); | 724 ASSERT_TRUE(called); |
725 ASSERT_TRUE(registration); | 725 ASSERT_TRUE(registration); |
726 | 726 |
727 // Manually create the waiting worker since there is no way to become a | 727 // Manually create the waiting worker since there is no way to become a |
728 // waiting worker until Update is implemented. | 728 // waiting worker until Update is implemented. |
729 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 729 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
730 registration, 1L, helper_->context()->AsWeakPtr()); | 730 registration, 1L, helper_->context()->AsWeakPtr()); |
731 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 731 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
732 version->StartWorker(CreateReceiverOnCurrentThread(&status)); | 732 version->StartWorker(CreateReceiverOnCurrentThread(&status)); |
733 base::RunLoop().RunUntilIdle(); | 733 base::RunLoop().RunUntilIdle(); |
734 ASSERT_EQ(SERVICE_WORKER_OK, status); | 734 ASSERT_EQ(SERVICE_WORKER_OK, status); |
735 | 735 |
736 version->SetStatus(ServiceWorkerVersion::INSTALLED); | 736 version->SetStatus(ServiceWorkerVersion::INSTALLED); |
737 registration->SetWaitingVersion(version); | 737 registration->SetWaitingVersion(version); |
738 EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 738 EXPECT_EQ(ServiceWorkerVersion::RUNNING, |
739 version->running_status()); | 739 version->running_status()); |
740 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 740 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); |
741 | 741 |
742 called = false; | 742 called = false; |
743 job_coordinator()->Unregister(GURL("http://www.example.com/*"), | 743 job_coordinator()->Unregister(GURL("http://www.example.com/"), |
744 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 744 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
745 base::RunLoop().RunUntilIdle(); | 745 base::RunLoop().RunUntilIdle(); |
746 ASSERT_TRUE(called); | 746 ASSERT_TRUE(called); |
747 | 747 |
748 // The version should be stopped since there is no controllee after | 748 // The version should be stopped since there is no controllee after |
749 // unregistration. | 749 // unregistration. |
750 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 750 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); |
751 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 751 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
752 } | 752 } |
753 | 753 |
754 // Tests that the active worker enters the 'redundant' state upon | 754 // Tests that the active worker enters the 'redundant' state upon |
755 // unregistration. | 755 // unregistration. |
756 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { | 756 TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { |
757 scoped_refptr<ServiceWorkerRegistration> registration; | 757 scoped_refptr<ServiceWorkerRegistration> registration; |
758 bool called = false; | 758 bool called = false; |
759 job_coordinator()->Register( | 759 job_coordinator()->Register( |
760 GURL("http://www.example.com/*"), | 760 GURL("http://www.example.com/"), |
761 GURL("http://www.example.com/service_worker.js"), | 761 GURL("http://www.example.com/service_worker.js"), |
762 render_process_id_, | 762 render_process_id_, |
763 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 763 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
764 base::RunLoop().RunUntilIdle(); | 764 base::RunLoop().RunUntilIdle(); |
765 ASSERT_TRUE(called); | 765 ASSERT_TRUE(called); |
766 ASSERT_TRUE(registration); | 766 ASSERT_TRUE(registration); |
767 | 767 |
768 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 768 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
769 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 769 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
770 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 770 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
771 | 771 |
772 called = false; | 772 called = false; |
773 job_coordinator()->Unregister(GURL("http://www.example.com/*"), | 773 job_coordinator()->Unregister(GURL("http://www.example.com/"), |
774 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 774 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
775 base::RunLoop().RunUntilIdle(); | 775 base::RunLoop().RunUntilIdle(); |
776 ASSERT_TRUE(called); | 776 ASSERT_TRUE(called); |
777 | 777 |
778 // The version should be stopped since there is no controllee after | 778 // The version should be stopped since there is no controllee after |
779 // unregistration. | 779 // unregistration. |
780 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 780 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); |
781 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 781 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
782 } | 782 } |
783 | 783 |
784 // Tests that the active worker enters the 'redundant' state upon | 784 // Tests that the active worker enters the 'redundant' state upon |
785 // unregistration. | 785 // unregistration. |
786 TEST_F(ServiceWorkerJobTest, | 786 TEST_F(ServiceWorkerJobTest, |
787 UnregisterActiveSetsRedundant_WaitForNoControllee) { | 787 UnregisterActiveSetsRedundant_WaitForNoControllee) { |
788 scoped_refptr<ServiceWorkerRegistration> registration; | 788 scoped_refptr<ServiceWorkerRegistration> registration; |
789 bool called = false; | 789 bool called = false; |
790 job_coordinator()->Register( | 790 job_coordinator()->Register( |
791 GURL("http://www.example.com/*"), | 791 GURL("http://www.example.com/"), |
792 GURL("http://www.example.com/service_worker.js"), | 792 GURL("http://www.example.com/service_worker.js"), |
793 render_process_id_, | 793 render_process_id_, |
794 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 794 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
795 base::RunLoop().RunUntilIdle(); | 795 base::RunLoop().RunUntilIdle(); |
796 ASSERT_TRUE(called); | 796 ASSERT_TRUE(called); |
797 ASSERT_TRUE(registration); | 797 ASSERT_TRUE(registration); |
798 | 798 |
799 scoped_ptr<ServiceWorkerProviderHost> host( | 799 scoped_ptr<ServiceWorkerProviderHost> host( |
800 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 800 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
801 1 /* dummy provider_id */, | 801 1 /* dummy provider_id */, |
802 context()->AsWeakPtr(), | 802 context()->AsWeakPtr(), |
803 NULL)); | 803 NULL)); |
804 registration->active_version()->AddControllee(host.get()); | 804 registration->active_version()->AddControllee(host.get()); |
805 | 805 |
806 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); | 806 scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); |
807 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 807 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
808 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 808 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
809 | 809 |
810 called = false; | 810 called = false; |
811 job_coordinator()->Unregister(GURL("http://www.example.com/*"), | 811 job_coordinator()->Unregister(GURL("http://www.example.com/"), |
812 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 812 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
813 base::RunLoop().RunUntilIdle(); | 813 base::RunLoop().RunUntilIdle(); |
814 ASSERT_TRUE(called); | 814 ASSERT_TRUE(called); |
815 | 815 |
816 // The version should be running since there is still a controllee. | 816 // The version should be running since there is still a controllee. |
817 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); | 817 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); |
818 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); | 818 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
819 | 819 |
820 registration->active_version()->RemoveControllee(host.get()); | 820 registration->active_version()->RemoveControllee(host.get()); |
821 base::RunLoop().RunUntilIdle(); | 821 base::RunLoop().RunUntilIdle(); |
822 | 822 |
823 // The version should be stopped since there is no controllee. | 823 // The version should be stopped since there is no controllee. |
824 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); | 824 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status()); |
825 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); | 825 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
826 } | 826 } |
827 | 827 |
828 namespace { // Helpers for the update job tests. | 828 namespace { // Helpers for the update job tests. |
829 | 829 |
830 const GURL kNoChangeOrigin("http://nochange/"); | 830 const GURL kNoChangeOrigin("http://nochange/"); |
831 const GURL kNewVersionOrigin("http://newversion/"); | 831 const GURL kNewVersionOrigin("http://newversion/"); |
832 const std::string kScope("scope/*"); | 832 const std::string kScope("scope/"); |
833 const std::string kScript("script.js"); | 833 const std::string kScript("script.js"); |
834 | 834 |
835 void RunNestedUntilIdle() { | 835 void RunNestedUntilIdle() { |
836 base::MessageLoop::ScopedNestableTaskAllower allow( | 836 base::MessageLoop::ScopedNestableTaskAllower allow( |
837 base::MessageLoop::current()); | 837 base::MessageLoop::current()); |
838 base::MessageLoop::current()->RunUntilIdle(); | 838 base::MessageLoop::current()->RunUntilIdle(); |
839 } | 839 } |
840 | 840 |
841 void OnIOComplete(int* rv_out, int rv) { | 841 void OnIOComplete(int* rv_out, int rv) { |
842 *rv_out = rv; | 842 *rv_out = rv; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 1089 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, |
1090 update_helper->state_change_log_[3].status); | 1090 update_helper->state_change_log_[3].status); |
1091 | 1091 |
1092 EXPECT_EQ(registration->active_version()->version_id(), | 1092 EXPECT_EQ(registration->active_version()->version_id(), |
1093 update_helper->state_change_log_[4].version_id); | 1093 update_helper->state_change_log_[4].version_id); |
1094 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1094 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
1095 update_helper->state_change_log_[4].status); | 1095 update_helper->state_change_log_[4].status); |
1096 } | 1096 } |
1097 | 1097 |
1098 } // namespace content | 1098 } // namespace content |
OLD | NEW |