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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 bool find_called = false; | 577 bool find_called = false; |
578 storage()->FindRegistrationForPattern( | 578 storage()->FindRegistrationForPattern( |
579 pattern, | 579 pattern, |
580 SaveFoundRegistration( | 580 SaveFoundRegistration( |
581 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | 581 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); |
582 | 582 |
583 base::RunLoop().RunUntilIdle(); | 583 base::RunLoop().RunUntilIdle(); |
584 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 584 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
585 } | 585 } |
586 | 586 |
587 TEST_F(ServiceWorkerJobTest, AbortAll_Register) { | |
588 GURL pattern1("http://www1.example.com/*"); | |
589 GURL pattern2("http://www2.example.com/*"); | |
590 GURL script_url1("http://www1.example.com/service_worker.js"); | |
591 GURL script_url2("http://www2.example.com/service_worker.js"); | |
592 | |
593 bool registration_called1 = false; | |
594 scoped_refptr<ServiceWorkerRegistration> registration1; | |
595 job_coordinator()->Register( | |
596 pattern1, | |
597 script_url1, | |
598 render_process_id_, | |
599 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | |
600 ®istration_called1, ®istration1)); | |
601 | |
602 bool registration_called2 = false; | |
603 scoped_refptr<ServiceWorkerRegistration> registration2; | |
604 job_coordinator()->Register( | |
605 pattern2, | |
606 script_url2, | |
607 render_process_id_, | |
608 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | |
609 ®istration_called2, ®istration2)); | |
610 | |
611 ASSERT_FALSE(registration_called1); | |
612 ASSERT_FALSE(registration_called2); | |
613 job_coordinator()->AbortAll(); | |
614 | |
615 base::RunLoop().RunUntilIdle(); | |
616 ASSERT_TRUE(registration_called1); | |
617 ASSERT_TRUE(registration_called2); | |
618 | |
619 bool find_called1 = false; | |
620 storage()->FindRegistrationForPattern( | |
621 pattern1, | |
622 SaveFoundRegistration( | |
623 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called1, ®istration1)); | |
624 | |
625 bool find_called2 = false; | |
626 storage()->FindRegistrationForPattern( | |
627 pattern2, | |
628 SaveFoundRegistration( | |
629 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called2, ®istration2)); | |
630 | |
631 base::RunLoop().RunUntilIdle(); | |
632 ASSERT_TRUE(find_called1); | |
633 ASSERT_TRUE(find_called2); | |
634 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1); | |
635 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2); | |
falken
2014/06/19 08:10:56
nit: would it make sense to make change these last
nhiroki
2014/06/19 10:04:05
Done.
| |
636 } | |
637 | |
638 TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { | |
639 GURL pattern1("http://www1.example.com/*"); | |
640 GURL pattern2("http://www2.example.com/*"); | |
641 | |
642 bool unregistration_called1 = false; | |
643 scoped_refptr<ServiceWorkerRegistration> registration1; | |
644 job_coordinator()->Unregister( | |
645 pattern1, | |
646 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | |
647 &unregistration_called1)); | |
648 | |
649 bool unregistration_called2 = false; | |
650 job_coordinator()->Unregister( | |
651 pattern2, | |
652 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | |
653 &unregistration_called2)); | |
654 | |
655 ASSERT_FALSE(unregistration_called1); | |
656 ASSERT_FALSE(unregistration_called2); | |
657 job_coordinator()->AbortAll(); | |
658 | |
659 base::RunLoop().RunUntilIdle(); | |
660 ASSERT_TRUE(unregistration_called1); | |
661 ASSERT_TRUE(unregistration_called2); | |
662 } | |
663 | |
664 TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { | |
665 GURL pattern("http://www.example.com/*"); | |
666 GURL script_url("http://www.example.com/service_worker.js"); | |
667 | |
668 bool registration_called = false; | |
669 scoped_refptr<ServiceWorkerRegistration> registration; | |
670 job_coordinator()->Register( | |
671 pattern, | |
672 script_url, | |
673 render_process_id_, | |
674 SaveRegistration(SERVICE_WORKER_ERROR_ABORT, | |
675 ®istration_called, ®istration)); | |
676 | |
677 bool unregistration_called = false; | |
678 job_coordinator()->Unregister( | |
679 pattern, | |
680 SaveUnregistration(SERVICE_WORKER_ERROR_ABORT, | |
681 &unregistration_called)); | |
682 | |
683 ASSERT_FALSE(registration_called); | |
684 ASSERT_FALSE(unregistration_called); | |
685 job_coordinator()->AbortAll(); | |
686 | |
687 base::RunLoop().RunUntilIdle(); | |
688 ASSERT_TRUE(registration_called); | |
689 ASSERT_TRUE(unregistration_called); | |
690 | |
691 bool find_called = false; | |
692 storage()->FindRegistrationForPattern( | |
693 pattern, | |
694 SaveFoundRegistration( | |
695 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | |
696 | |
697 base::RunLoop().RunUntilIdle(); | |
698 ASSERT_TRUE(find_called); | |
699 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | |
falken
2014/06/19 08:10:56
maybe this one too
nhiroki
2014/06/19 10:04:05
Done.
| |
700 } | |
701 | |
587 } // namespace content | 702 } // namespace content |
OLD | NEW |