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 <stdint.h> | 5 #include <stdint.h> |
6 #include <tuple> | 6 #include <tuple> |
7 | 7 |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints_; | 176 std::vector<ServiceWorkerRemoteProviderEndpoint> remote_endpoints_; |
177 }; | 177 }; |
178 | 178 |
179 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob( | 179 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob( |
180 const GURL& pattern, | 180 const GURL& pattern, |
181 const GURL& script_url, | 181 const GURL& script_url, |
182 ServiceWorkerStatusCode expected_status) { | 182 ServiceWorkerStatusCode expected_status) { |
183 scoped_refptr<ServiceWorkerRegistration> registration; | 183 scoped_refptr<ServiceWorkerRegistration> registration; |
184 bool called; | 184 bool called; |
185 job_coordinator()->Register( | 185 job_coordinator()->Register( |
186 pattern, script_url, NULL, | 186 script_url, ServiceWorkerRegistrationOptions(pattern), nullptr, |
187 SaveRegistration(expected_status, &called, ®istration)); | 187 SaveRegistration(expected_status, &called, ®istration)); |
188 EXPECT_FALSE(called); | 188 EXPECT_FALSE(called); |
189 base::RunLoop().RunUntilIdle(); | 189 base::RunLoop().RunUntilIdle(); |
190 EXPECT_TRUE(called); | 190 EXPECT_TRUE(called); |
191 return registration; | 191 return registration; |
192 } | 192 } |
193 | 193 |
194 void ServiceWorkerJobTest::RunUnregisterJob( | 194 void ServiceWorkerJobTest::RunUnregisterJob( |
195 const GURL& pattern, | 195 const GURL& pattern, |
196 ServiceWorkerStatusCode expected_status) { | 196 ServiceWorkerStatusCode expected_status) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 ASSERT_TRUE(registration1.get()); | 246 ASSERT_TRUE(registration1.get()); |
247 ASSERT_EQ(registration1, original_registration); | 247 ASSERT_EQ(registration1, original_registration); |
248 ASSERT_EQ(registration1, registration2); | 248 ASSERT_EQ(registration1, registration2); |
249 } | 249 } |
250 | 250 |
251 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { | 251 TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { |
252 bool called; | 252 bool called; |
253 scoped_refptr<ServiceWorkerRegistration> original_registration = | 253 scoped_refptr<ServiceWorkerRegistration> original_registration = |
254 RunRegisterJob(GURL("http://www.example.com/"), | 254 RunRegisterJob(GURL("http://www.example.com/"), |
255 GURL("http://www.example.com/service_worker.js")); | 255 GURL("http://www.example.com/service_worker.js")); |
256 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(NULL), | 256 ASSERT_NE(static_cast<ServiceWorkerRegistration*>(nullptr), |
257 original_registration.get()); | 257 original_registration.get()); |
258 | 258 |
259 scoped_refptr<ServiceWorkerRegistration> registration1; | 259 scoped_refptr<ServiceWorkerRegistration> registration1; |
260 storage()->FindRegistrationForDocument( | 260 storage()->FindRegistrationForDocument( |
261 GURL("http://www.example.com/one"), | 261 GURL("http://www.example.com/one"), |
262 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); | 262 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration1)); |
263 base::RunLoop().RunUntilIdle(); | 263 base::RunLoop().RunUntilIdle(); |
264 EXPECT_TRUE(called); | 264 EXPECT_TRUE(called); |
265 | 265 |
266 scoped_refptr<ServiceWorkerRegistration> registration2; | 266 scoped_refptr<ServiceWorkerRegistration> registration2; |
267 storage()->FindRegistrationForDocument( | 267 storage()->FindRegistrationForDocument( |
268 GURL("http://www.example.com/two"), | 268 GURL("http://www.example.com/two"), |
269 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); | 269 SaveFoundRegistration(SERVICE_WORKER_OK, &called, ®istration2)); |
270 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
271 EXPECT_TRUE(called); | 271 EXPECT_TRUE(called); |
272 ASSERT_EQ(registration1, original_registration); | 272 ASSERT_EQ(registration1, original_registration); |
273 ASSERT_EQ(registration1, registration2); | 273 ASSERT_EQ(registration1, registration2); |
274 } | 274 } |
275 | 275 |
276 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { | 276 TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { |
277 bool called1; | 277 bool called1; |
278 scoped_refptr<ServiceWorkerRegistration> original_registration1; | 278 scoped_refptr<ServiceWorkerRegistration> original_registration1; |
279 job_coordinator()->Register( | 279 job_coordinator()->Register( |
280 GURL("http://www.example.com/one/"), | |
281 GURL("http://www.example.com/service_worker.js"), | 280 GURL("http://www.example.com/service_worker.js"), |
282 NULL, | 281 ServiceWorkerRegistrationOptions(GURL("http://www.example.com/one/")), |
| 282 nullptr, |
283 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); | 283 SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); |
284 | 284 |
285 bool called2; | 285 bool called2; |
286 scoped_refptr<ServiceWorkerRegistration> original_registration2; | 286 scoped_refptr<ServiceWorkerRegistration> original_registration2; |
287 job_coordinator()->Register( | 287 job_coordinator()->Register( |
288 GURL("http://www.example.com/two/"), | |
289 GURL("http://www.example.com/service_worker.js"), | 288 GURL("http://www.example.com/service_worker.js"), |
290 NULL, | 289 ServiceWorkerRegistrationOptions(GURL("http://www.example.com/two/")), |
| 290 nullptr, |
291 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); | 291 SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); |
292 | 292 |
293 EXPECT_FALSE(called1); | 293 EXPECT_FALSE(called1); |
294 EXPECT_FALSE(called2); | 294 EXPECT_FALSE(called2); |
295 base::RunLoop().RunUntilIdle(); | 295 base::RunLoop().RunUntilIdle(); |
296 EXPECT_TRUE(called2); | 296 EXPECT_TRUE(called2); |
297 EXPECT_TRUE(called1); | 297 EXPECT_TRUE(called1); |
298 | 298 |
299 scoped_refptr<ServiceWorkerRegistration> registration1; | 299 scoped_refptr<ServiceWorkerRegistration> registration1; |
300 storage()->FindRegistrationForDocument( | 300 storage()->FindRegistrationForDocument( |
(...skipping 27 matching lines...) Expand all Loading... |
328 }; | 328 }; |
329 | 329 |
330 // Make sure basic registration is working. | 330 // Make sure basic registration is working. |
331 TEST_F(ServiceWorkerJobTest, Register) { | 331 TEST_F(ServiceWorkerJobTest, Register) { |
332 helper_.reset(new RegisterForeignFetchTestHelper); | 332 helper_.reset(new RegisterForeignFetchTestHelper); |
333 | 333 |
334 scoped_refptr<ServiceWorkerRegistration> registration = | 334 scoped_refptr<ServiceWorkerRegistration> registration = |
335 RunRegisterJob(GURL("http://www.example.com/"), | 335 RunRegisterJob(GURL("http://www.example.com/"), |
336 GURL("http://www.example.com/service_worker.js")); | 336 GURL("http://www.example.com/service_worker.js")); |
337 | 337 |
338 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 338 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(nullptr), registration); |
339 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, | 339 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install, |
340 helper_->dispatched_events()->at(0)); | 340 helper_->dispatched_events()->at(0)); |
341 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, | 341 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Activate, |
342 helper_->dispatched_events()->at(1)); | 342 helper_->dispatched_events()->at(1)); |
343 | 343 |
344 GURL valid_scope_1("http://www.example.com/test/subscope"); | 344 GURL valid_scope_1("http://www.example.com/test/subscope"); |
345 GURL valid_scope_2("http://www.example.com/test/othersubscope"); | 345 GURL valid_scope_2("http://www.example.com/test/othersubscope"); |
346 url::Origin valid_origin(GURL("https://chromium.org/")); | 346 url::Origin valid_origin(GURL("https://chromium.org/")); |
347 | 347 |
348 ServiceWorkerVersion* version_ = registration->active_version(); | 348 ServiceWorkerVersion* version_ = registration->active_version(); |
(...skipping 11 matching lines...) Expand all Loading... |
360 scoped_refptr<ServiceWorkerRegistration> registration = | 360 scoped_refptr<ServiceWorkerRegistration> registration = |
361 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); | 361 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); |
362 | 362 |
363 RunUnregisterJob(pattern); | 363 RunUnregisterJob(pattern); |
364 | 364 |
365 ASSERT_TRUE(registration->HasOneRef()); | 365 ASSERT_TRUE(registration->HasOneRef()); |
366 | 366 |
367 registration = FindRegistrationForPattern(pattern, | 367 registration = FindRegistrationForPattern(pattern, |
368 SERVICE_WORKER_ERROR_NOT_FOUND); | 368 SERVICE_WORKER_ERROR_NOT_FOUND); |
369 | 369 |
370 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 370 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(nullptr), registration); |
371 } | 371 } |
372 | 372 |
373 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { | 373 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { |
374 GURL pattern("http://www.example.com/"); | 374 GURL pattern("http://www.example.com/"); |
375 | 375 |
376 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); | 376 RunUnregisterJob(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
377 } | 377 } |
378 | 378 |
379 // Make sure registering a new script creates a new version and shares an | 379 // Make sure registering a new script creates a new version and shares an |
380 // existing registration. | 380 // existing registration. |
381 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { | 381 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
382 GURL pattern("http://www.example.com/"); | 382 GURL pattern("http://www.example.com/"); |
383 | 383 |
384 scoped_refptr<ServiceWorkerRegistration> old_registration = | 384 scoped_refptr<ServiceWorkerRegistration> old_registration = |
385 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); | 385 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); |
386 | 386 |
387 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = | 387 scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern = |
388 FindRegistrationForPattern(pattern); | 388 FindRegistrationForPattern(pattern); |
389 | 389 |
390 ASSERT_EQ(old_registration, old_registration_by_pattern); | 390 ASSERT_EQ(old_registration, old_registration_by_pattern); |
391 old_registration_by_pattern = NULL; | 391 old_registration_by_pattern = nullptr; |
392 | 392 |
393 scoped_refptr<ServiceWorkerRegistration> new_registration = | 393 scoped_refptr<ServiceWorkerRegistration> new_registration = |
394 RunRegisterJob(pattern, | 394 RunRegisterJob(pattern, |
395 GURL("http://www.example.com/service_worker_new.js")); | 395 GURL("http://www.example.com/service_worker_new.js")); |
396 | 396 |
397 ASSERT_EQ(old_registration, new_registration); | 397 ASSERT_EQ(old_registration, new_registration); |
398 | 398 |
399 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = | 399 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = |
400 FindRegistrationForPattern(pattern); | 400 FindRegistrationForPattern(pattern); |
401 | 401 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 }; | 449 }; |
450 | 450 |
451 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 451 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
452 helper_.reset(new FailToStartWorkerTestHelper); | 452 helper_.reset(new FailToStartWorkerTestHelper); |
453 | 453 |
454 scoped_refptr<ServiceWorkerRegistration> registration = | 454 scoped_refptr<ServiceWorkerRegistration> registration = |
455 RunRegisterJob(GURL("http://www.example.com/"), | 455 RunRegisterJob(GURL("http://www.example.com/"), |
456 GURL("http://www.example.com/service_worker.js"), | 456 GURL("http://www.example.com/service_worker.js"), |
457 SERVICE_WORKER_ERROR_START_WORKER_FAILED); | 457 SERVICE_WORKER_ERROR_START_WORKER_FAILED); |
458 | 458 |
459 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 459 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(nullptr), registration); |
460 } | 460 } |
461 | 461 |
462 // Register and then unregister the pattern, in parallel. Job coordinator should | 462 // Register and then unregister the pattern, in parallel. Job coordinator should |
463 // process jobs until the last job. | 463 // process jobs until the last job. |
464 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { | 464 TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { |
465 GURL pattern("http://www.example.com/"); | 465 GURL pattern("http://www.example.com/"); |
466 GURL script_url("http://www.example.com/service_worker.js"); | 466 GURL script_url("http://www.example.com/service_worker.js"); |
467 | 467 |
468 bool registration_called = false; | 468 bool registration_called = false; |
469 scoped_refptr<ServiceWorkerRegistration> registration; | 469 scoped_refptr<ServiceWorkerRegistration> registration; |
470 job_coordinator()->Register( | 470 job_coordinator()->Register( |
471 pattern, | 471 script_url, ServiceWorkerRegistrationOptions(pattern), nullptr, |
472 script_url, | |
473 NULL, | |
474 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); | 472 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
475 | 473 |
476 bool unregistration_called = false; | 474 bool unregistration_called = false; |
477 job_coordinator()->Unregister( | 475 job_coordinator()->Unregister( |
478 pattern, | 476 pattern, |
479 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | 477 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
480 | 478 |
481 ASSERT_FALSE(registration_called); | 479 ASSERT_FALSE(registration_called); |
482 ASSERT_FALSE(unregistration_called); | 480 ASSERT_FALSE(unregistration_called); |
483 base::RunLoop().RunUntilIdle(); | 481 base::RunLoop().RunUntilIdle(); |
484 ASSERT_TRUE(registration_called); | 482 ASSERT_TRUE(registration_called); |
485 ASSERT_TRUE(unregistration_called); | 483 ASSERT_TRUE(unregistration_called); |
486 | 484 |
487 registration = FindRegistrationForPattern(pattern, | 485 registration = FindRegistrationForPattern(pattern, |
488 SERVICE_WORKER_ERROR_NOT_FOUND); | 486 SERVICE_WORKER_ERROR_NOT_FOUND); |
489 | 487 |
490 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 488 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
491 } | 489 } |
492 | 490 |
493 // Register conflicting scripts for the same pattern. The most recent | 491 // Register conflicting scripts for the same pattern. The most recent |
494 // registration should win, and the old registration should have been | 492 // registration should win, and the old registration should have been |
495 // shutdown. | 493 // shutdown. |
496 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { | 494 TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
497 GURL pattern("http://www.example.com/"); | 495 GURL pattern("http://www.example.com/"); |
498 | 496 |
499 GURL script_url1("http://www.example.com/service_worker1.js"); | 497 GURL script_url1("http://www.example.com/service_worker1.js"); |
500 bool registration1_called = false; | 498 bool registration1_called = false; |
501 scoped_refptr<ServiceWorkerRegistration> registration1; | 499 scoped_refptr<ServiceWorkerRegistration> registration1; |
502 job_coordinator()->Register( | 500 job_coordinator()->Register( |
503 pattern, | 501 script_url1, ServiceWorkerRegistrationOptions(pattern), nullptr, |
504 script_url1, | 502 SaveRegistration(SERVICE_WORKER_OK, ®istration1_called, |
505 NULL, | 503 ®istration1)); |
506 SaveRegistration( | |
507 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | |
508 | 504 |
509 GURL script_url2("http://www.example.com/service_worker2.js"); | 505 GURL script_url2("http://www.example.com/service_worker2.js"); |
510 bool registration2_called = false; | 506 bool registration2_called = false; |
511 scoped_refptr<ServiceWorkerRegistration> registration2; | 507 scoped_refptr<ServiceWorkerRegistration> registration2; |
512 job_coordinator()->Register( | 508 job_coordinator()->Register( |
513 pattern, | 509 script_url2, ServiceWorkerRegistrationOptions(pattern), nullptr, |
514 script_url2, | 510 SaveRegistration(SERVICE_WORKER_OK, ®istration2_called, |
515 NULL, | 511 ®istration2)); |
516 SaveRegistration( | |
517 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | |
518 | 512 |
519 ASSERT_FALSE(registration1_called); | 513 ASSERT_FALSE(registration1_called); |
520 ASSERT_FALSE(registration2_called); | 514 ASSERT_FALSE(registration2_called); |
521 base::RunLoop().RunUntilIdle(); | 515 base::RunLoop().RunUntilIdle(); |
522 ASSERT_TRUE(registration1_called); | 516 ASSERT_TRUE(registration1_called); |
523 ASSERT_TRUE(registration2_called); | 517 ASSERT_TRUE(registration2_called); |
524 | 518 |
525 scoped_refptr<ServiceWorkerRegistration> registration = | 519 scoped_refptr<ServiceWorkerRegistration> registration = |
526 FindRegistrationForPattern(pattern); | 520 FindRegistrationForPattern(pattern); |
527 | 521 |
528 ASSERT_EQ(registration2, registration); | 522 ASSERT_EQ(registration2, registration); |
529 } | 523 } |
530 | 524 |
531 // Register the exact same pattern + script. Requests should be | 525 // Register the exact same pattern + script. Requests should be |
532 // coalesced such that both callers get the exact same registration | 526 // coalesced such that both callers get the exact same registration |
533 // object. | 527 // object. |
534 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { | 528 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
535 GURL pattern("http://www.example.com/"); | 529 GURL pattern("http://www.example.com/"); |
536 | 530 |
537 GURL script_url("http://www.example.com/service_worker1.js"); | 531 GURL script_url("http://www.example.com/service_worker1.js"); |
538 bool registration1_called = false; | 532 bool registration1_called = false; |
539 scoped_refptr<ServiceWorkerRegistration> registration1; | 533 scoped_refptr<ServiceWorkerRegistration> registration1; |
540 job_coordinator()->Register( | 534 job_coordinator()->Register( |
541 pattern, | 535 script_url, ServiceWorkerRegistrationOptions(pattern), nullptr, |
542 script_url, | 536 SaveRegistration(SERVICE_WORKER_OK, ®istration1_called, |
543 NULL, | 537 ®istration1)); |
544 SaveRegistration( | |
545 SERVICE_WORKER_OK, ®istration1_called, ®istration1)); | |
546 | 538 |
547 bool registration2_called = false; | 539 bool registration2_called = false; |
548 scoped_refptr<ServiceWorkerRegistration> registration2; | 540 scoped_refptr<ServiceWorkerRegistration> registration2; |
549 job_coordinator()->Register( | 541 job_coordinator()->Register( |
550 pattern, | 542 script_url, ServiceWorkerRegistrationOptions(pattern), nullptr, |
551 script_url, | 543 SaveRegistration(SERVICE_WORKER_OK, ®istration2_called, |
552 NULL, | 544 ®istration2)); |
553 SaveRegistration( | |
554 SERVICE_WORKER_OK, ®istration2_called, ®istration2)); | |
555 | 545 |
556 ASSERT_FALSE(registration1_called); | 546 ASSERT_FALSE(registration1_called); |
557 ASSERT_FALSE(registration2_called); | 547 ASSERT_FALSE(registration2_called); |
558 base::RunLoop().RunUntilIdle(); | 548 base::RunLoop().RunUntilIdle(); |
559 ASSERT_TRUE(registration1_called); | 549 ASSERT_TRUE(registration1_called); |
560 ASSERT_TRUE(registration2_called); | 550 ASSERT_TRUE(registration2_called); |
561 | 551 |
562 ASSERT_EQ(registration1, registration2); | 552 ASSERT_EQ(registration1, registration2); |
563 | 553 |
564 scoped_refptr<ServiceWorkerRegistration> registration = | 554 scoped_refptr<ServiceWorkerRegistration> registration = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 591 |
602 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { | 592 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { |
603 GURL pattern1("http://www1.example.com/"); | 593 GURL pattern1("http://www1.example.com/"); |
604 GURL pattern2("http://www2.example.com/"); | 594 GURL pattern2("http://www2.example.com/"); |
605 GURL script_url1("http://www1.example.com/service_worker.js"); | 595 GURL script_url1("http://www1.example.com/service_worker.js"); |
606 GURL script_url2("http://www2.example.com/service_worker.js"); | 596 GURL script_url2("http://www2.example.com/service_worker.js"); |
607 | 597 |
608 bool registration_called1 = false; | 598 bool registration_called1 = false; |
609 scoped_refptr<ServiceWorkerRegistration> registration1; | 599 scoped_refptr<ServiceWorkerRegistration> registration1; |
610 job_coordinator()->Register( | 600 job_coordinator()->Register( |
611 pattern1, | 601 script_url1, ServiceWorkerRegistrationOptions(pattern1), nullptr, |
612 script_url1, | 602 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, ®istration_called1, |
613 NULL, | 603 ®istration1)); |
614 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | |
615 ®istration_called1, ®istration1)); | |
616 | 604 |
617 bool registration_called2 = false; | 605 bool registration_called2 = false; |
618 scoped_refptr<ServiceWorkerRegistration> registration2; | 606 scoped_refptr<ServiceWorkerRegistration> registration2; |
619 job_coordinator()->Register( | 607 job_coordinator()->Register( |
620 pattern2, | 608 script_url2, ServiceWorkerRegistrationOptions(pattern2), nullptr, |
621 script_url2, | 609 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, ®istration_called2, |
622 NULL, | 610 ®istration2)); |
623 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | |
624 ®istration_called2, ®istration2)); | |
625 | 611 |
626 ASSERT_FALSE(registration_called1); | 612 ASSERT_FALSE(registration_called1); |
627 ASSERT_FALSE(registration_called2); | 613 ASSERT_FALSE(registration_called2); |
628 job_coordinator()->AbortAll(); | 614 job_coordinator()->AbortAll(); |
629 | 615 |
630 base::RunLoop().RunUntilIdle(); | 616 base::RunLoop().RunUntilIdle(); |
631 ASSERT_TRUE(registration_called1); | 617 ASSERT_TRUE(registration_called1); |
632 ASSERT_TRUE(registration_called2); | 618 ASSERT_TRUE(registration_called2); |
633 | 619 |
634 bool find_called1 = false; | 620 bool find_called1 = false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 ASSERT_TRUE(unregistration_called2); | 662 ASSERT_TRUE(unregistration_called2); |
677 } | 663 } |
678 | 664 |
679 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { | 665 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { |
680 GURL pattern("http://www.example.com/"); | 666 GURL pattern("http://www.example.com/"); |
681 GURL script_url("http://www.example.com/service_worker.js"); | 667 GURL script_url("http://www.example.com/service_worker.js"); |
682 | 668 |
683 bool registration_called = false; | 669 bool registration_called = false; |
684 scoped_refptr<ServiceWorkerRegistration> registration; | 670 scoped_refptr<ServiceWorkerRegistration> registration; |
685 job_coordinator()->Register( | 671 job_coordinator()->Register( |
686 pattern, | 672 script_url, ServiceWorkerRegistrationOptions(pattern), nullptr, |
687 script_url, | 673 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, ®istration_called, |
688 NULL, | 674 ®istration)); |
689 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | |
690 ®istration_called, ®istration)); | |
691 | 675 |
692 bool unregistration_called = false; | 676 bool unregistration_called = false; |
693 job_coordinator()->Unregister( | 677 job_coordinator()->Unregister( |
694 pattern, | 678 pattern, |
695 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | 679 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, |
696 &unregistration_called)); | 680 &unregistration_called)); |
697 | 681 |
698 ASSERT_FALSE(registration_called); | 682 ASSERT_FALSE(registration_called); |
699 ASSERT_FALSE(unregistration_called); | 683 ASSERT_FALSE(unregistration_called); |
700 job_coordinator()->AbortAll(); | 684 job_coordinator()->AbortAll(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 859 |
876 void set_force_start_worker_failure(bool force_start_worker_failure) { | 860 void set_force_start_worker_failure(bool force_start_worker_failure) { |
877 force_start_worker_failure_ = force_start_worker_failure; | 861 force_start_worker_failure_ = force_start_worker_failure; |
878 } | 862 } |
879 | 863 |
880 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( | 864 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( |
881 const GURL& test_origin) { | 865 const GURL& test_origin) { |
882 scoped_refptr<ServiceWorkerRegistration> registration; | 866 scoped_refptr<ServiceWorkerRegistration> registration; |
883 bool called = false; | 867 bool called = false; |
884 job_coordinator()->Register( | 868 job_coordinator()->Register( |
885 test_origin.Resolve(kScope), | |
886 test_origin.Resolve(kScript), | 869 test_origin.Resolve(kScript), |
887 NULL, | 870 ServiceWorkerRegistrationOptions(test_origin.Resolve(kScope)), nullptr, |
888 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 871 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
889 base::RunLoop().RunUntilIdle(); | 872 base::RunLoop().RunUntilIdle(); |
890 EXPECT_TRUE(called); | 873 EXPECT_TRUE(called); |
891 EXPECT_TRUE(registration.get()); | 874 EXPECT_TRUE(registration.get()); |
892 EXPECT_TRUE(registration->active_version()); | 875 EXPECT_TRUE(registration->active_version()); |
893 EXPECT_FALSE(registration->installing_version()); | 876 EXPECT_FALSE(registration->installing_version()); |
894 EXPECT_FALSE(registration->waiting_version()); | 877 EXPECT_FALSE(registration->waiting_version()); |
895 registration_ = registration; | 878 registration_ = registration; |
896 return registration; | 879 return registration; |
897 } | 880 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 // Update should abort after it starts and sees uninstalling. | 1283 // Update should abort after it starts and sees uninstalling. |
1301 job_coordinator()->Update(registration.get(), false); | 1284 job_coordinator()->Update(registration.get(), false); |
1302 | 1285 |
1303 EXPECT_FALSE(called); | 1286 EXPECT_FALSE(called); |
1304 base::RunLoop().RunUntilIdle(); | 1287 base::RunLoop().RunUntilIdle(); |
1305 EXPECT_TRUE(called); | 1288 EXPECT_TRUE(called); |
1306 | 1289 |
1307 // Verify the registration was not modified by the Update. | 1290 // Verify the registration was not modified by the Update. |
1308 EXPECT_TRUE(registration->is_uninstalling()); | 1291 EXPECT_TRUE(registration->is_uninstalling()); |
1309 EXPECT_EQ(active_version, registration->active_version()); | 1292 EXPECT_EQ(active_version, registration->active_version()); |
1310 EXPECT_EQ(NULL, registration->waiting_version()); | 1293 EXPECT_EQ(nullptr, registration->waiting_version()); |
1311 EXPECT_EQ(NULL, registration->installing_version()); | 1294 EXPECT_EQ(nullptr, registration->installing_version()); |
1312 } | 1295 } |
1313 | 1296 |
1314 TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { | 1297 TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { |
1315 GURL pattern("http://www.example.com/one/"); | 1298 GURL pattern("http://www.example.com/one/"); |
1316 GURL script1("http://www.example.com/service_worker.js"); | 1299 GURL script1("http://www.example.com/service_worker.js"); |
1317 GURL script2("http://www.example.com/service_worker.js?new"); | 1300 GURL script2("http://www.example.com/service_worker.js?new"); |
1318 | 1301 |
1319 scoped_refptr<ServiceWorkerRegistration> registration = | 1302 scoped_refptr<ServiceWorkerRegistration> registration = |
1320 RunRegisterJob(pattern, script1); | 1303 RunRegisterJob(pattern, script1); |
1321 scoped_refptr<base::TestSimpleTaskRunner> runner( | 1304 scoped_refptr<base::TestSimpleTaskRunner> runner( |
(...skipping 10 matching lines...) Expand all Loading... |
1332 // Register another script. | 1315 // Register another script. |
1333 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); | 1316 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); |
1334 | 1317 |
1335 EXPECT_FALSE(registration->is_uninstalling()); | 1318 EXPECT_FALSE(registration->is_uninstalling()); |
1336 EXPECT_EQ(old_version, registration->active_version()); | 1319 EXPECT_EQ(old_version, registration->active_version()); |
1337 | 1320 |
1338 scoped_refptr<ServiceWorkerVersion> new_version = | 1321 scoped_refptr<ServiceWorkerVersion> new_version = |
1339 registration->waiting_version(); | 1322 registration->waiting_version(); |
1340 | 1323 |
1341 // Verify the new version is installed but not activated yet. | 1324 // Verify the new version is installed but not activated yet. |
1342 EXPECT_EQ(NULL, registration->installing_version()); | 1325 EXPECT_EQ(nullptr, registration->installing_version()); |
1343 EXPECT_TRUE(new_version); | 1326 EXPECT_TRUE(new_version); |
1344 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); | 1327 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
1345 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); | 1328 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); |
1346 | 1329 |
1347 old_version->RemoveControllee(host.get()); | 1330 old_version->RemoveControllee(host.get()); |
1348 base::RunLoop().RunUntilIdle(); | 1331 base::RunLoop().RunUntilIdle(); |
1349 | 1332 |
1350 EXPECT_FALSE(registration->is_uninstalling()); | 1333 EXPECT_FALSE(registration->is_uninstalling()); |
1351 EXPECT_FALSE(registration->is_uninstalled()); | 1334 EXPECT_FALSE(registration->is_uninstalled()); |
1352 | 1335 |
1353 // Verify the new version is activated. | 1336 // Verify the new version is activated. |
1354 EXPECT_EQ(NULL, registration->installing_version()); | 1337 EXPECT_EQ(nullptr, registration->installing_version()); |
1355 EXPECT_EQ(NULL, registration->waiting_version()); | 1338 EXPECT_EQ(nullptr, registration->waiting_version()); |
1356 EXPECT_EQ(new_version, registration->active_version()); | 1339 EXPECT_EQ(new_version, registration->active_version()); |
1357 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1340 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1358 | 1341 |
1359 runner->RunUntilIdle(); | 1342 runner->RunUntilIdle(); |
1360 base::RunLoop().RunUntilIdle(); | 1343 base::RunLoop().RunUntilIdle(); |
1361 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); | 1344 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
1362 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); | 1345 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); |
1363 } | 1346 } |
1364 | 1347 |
1365 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { | 1348 TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 EXPECT_FALSE(registration->is_uninstalling()); | 1426 EXPECT_FALSE(registration->is_uninstalling()); |
1444 EXPECT_EQ(new_version, registration->waiting_version()); | 1427 EXPECT_EQ(new_version, registration->waiting_version()); |
1445 | 1428 |
1446 old_version->RemoveControllee(host.get()); | 1429 old_version->RemoveControllee(host.get()); |
1447 base::RunLoop().RunUntilIdle(); | 1430 base::RunLoop().RunUntilIdle(); |
1448 | 1431 |
1449 EXPECT_FALSE(registration->is_uninstalling()); | 1432 EXPECT_FALSE(registration->is_uninstalling()); |
1450 EXPECT_FALSE(registration->is_uninstalled()); | 1433 EXPECT_FALSE(registration->is_uninstalled()); |
1451 | 1434 |
1452 // Verify the new version is activated. | 1435 // Verify the new version is activated. |
1453 EXPECT_EQ(NULL, registration->installing_version()); | 1436 EXPECT_EQ(nullptr, registration->installing_version()); |
1454 EXPECT_EQ(NULL, registration->waiting_version()); | 1437 EXPECT_EQ(nullptr, registration->waiting_version()); |
1455 EXPECT_EQ(new_version, registration->active_version()); | 1438 EXPECT_EQ(new_version, registration->active_version()); |
1456 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1439 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1457 | 1440 |
1458 runner->RunUntilIdle(); | 1441 runner->RunUntilIdle(); |
1459 base::RunLoop().RunUntilIdle(); | 1442 base::RunLoop().RunUntilIdle(); |
1460 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); | 1443 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
1461 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); | 1444 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); |
1462 } | 1445 } |
1463 | 1446 |
1464 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) { | 1447 TEST_F(ServiceWorkerJobTest, RegisterMultipleTimesWhileUninstalling) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 EXPECT_FALSE(registration->is_uninstalling()); | 1482 EXPECT_FALSE(registration->is_uninstalling()); |
1500 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, second_version->status()); | 1483 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, second_version->status()); |
1501 | 1484 |
1502 first_version->RemoveControllee(host.get()); | 1485 first_version->RemoveControllee(host.get()); |
1503 base::RunLoop().RunUntilIdle(); | 1486 base::RunLoop().RunUntilIdle(); |
1504 | 1487 |
1505 EXPECT_FALSE(registration->is_uninstalling()); | 1488 EXPECT_FALSE(registration->is_uninstalling()); |
1506 EXPECT_FALSE(registration->is_uninstalled()); | 1489 EXPECT_FALSE(registration->is_uninstalled()); |
1507 | 1490 |
1508 // Verify the new version is activated. | 1491 // Verify the new version is activated. |
1509 EXPECT_EQ(NULL, registration->installing_version()); | 1492 EXPECT_EQ(nullptr, registration->installing_version()); |
1510 EXPECT_EQ(NULL, registration->waiting_version()); | 1493 EXPECT_EQ(nullptr, registration->waiting_version()); |
1511 EXPECT_EQ(third_version, registration->active_version()); | 1494 EXPECT_EQ(third_version, registration->active_version()); |
1512 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, third_version->status()); | 1495 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, third_version->status()); |
1513 | 1496 |
1514 runner->RunUntilIdle(); | 1497 runner->RunUntilIdle(); |
1515 base::RunLoop().RunUntilIdle(); | 1498 base::RunLoop().RunUntilIdle(); |
1516 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, third_version->running_status()); | 1499 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, third_version->running_status()); |
1517 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); | 1500 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); |
1518 } | 1501 } |
1519 | 1502 |
1520 class EventCallbackHelper : public EmbeddedWorkerTestHelper { | 1503 class EventCallbackHelper : public EmbeddedWorkerTestHelper { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 old_version, host.get())); | 1568 old_version, host.get())); |
1586 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); | 1569 EXPECT_EQ(registration, RunRegisterJob(pattern, script2)); |
1587 | 1570 |
1588 EXPECT_FALSE(registration->is_uninstalling()); | 1571 EXPECT_FALSE(registration->is_uninstalling()); |
1589 EXPECT_FALSE(registration->is_uninstalled()); | 1572 EXPECT_FALSE(registration->is_uninstalled()); |
1590 | 1573 |
1591 // Verify the new version is activated. | 1574 // Verify the new version is activated. |
1592 scoped_refptr<ServiceWorkerVersion> new_version = | 1575 scoped_refptr<ServiceWorkerVersion> new_version = |
1593 registration->active_version(); | 1576 registration->active_version(); |
1594 EXPECT_NE(old_version, new_version); | 1577 EXPECT_NE(old_version, new_version); |
1595 EXPECT_EQ(NULL, registration->installing_version()); | 1578 EXPECT_EQ(nullptr, registration->installing_version()); |
1596 EXPECT_EQ(NULL, registration->waiting_version()); | 1579 EXPECT_EQ(nullptr, registration->waiting_version()); |
1597 EXPECT_EQ(new_version, registration->active_version()); | 1580 EXPECT_EQ(new_version, registration->active_version()); |
1598 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); | 1581 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, new_version->running_status()); |
1599 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); | 1582 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, new_version->status()); |
1600 | 1583 |
1601 EXPECT_EQ(registration, FindRegistrationForPattern(pattern)); | 1584 EXPECT_EQ(registration, FindRegistrationForPattern(pattern)); |
1602 } | 1585 } |
1603 | 1586 |
1604 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) { | 1587 TEST_F(ServiceWorkerJobTest, RemoveControlleeDuringRejectedInstall) { |
1605 EventCallbackHelper* helper = new EventCallbackHelper; | 1588 EventCallbackHelper* helper = new EventCallbackHelper; |
1606 helper_.reset(helper); | 1589 helper_.reset(helper); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 // should not be promoted to ACTIVATED because failure occur | 1786 // should not be promoted to ACTIVATED because failure occur |
1804 // during shutdown. | 1787 // during shutdown. |
1805 runner->RunPendingTasks(); | 1788 runner->RunPendingTasks(); |
1806 base::RunLoop().RunUntilIdle(); | 1789 base::RunLoop().RunUntilIdle(); |
1807 EXPECT_EQ(new_version.get(), registration->active_version()); | 1790 EXPECT_EQ(new_version.get(), registration->active_version()); |
1808 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); | 1791 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); |
1809 registration->RemoveListener(update_helper); | 1792 registration->RemoveListener(update_helper); |
1810 } | 1793 } |
1811 | 1794 |
1812 } // namespace content | 1795 } // namespace content |
OLD | NEW |