OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 &result)); | 593 &result)); |
594 base::RunLoop().RunUntilIdle(); | 594 base::RunLoop().RunUntilIdle(); |
595 ASSERT_TRUE(was_called); | 595 ASSERT_TRUE(was_called); |
596 EXPECT_EQ(SERVICE_WORKER_OK, result); | 596 EXPECT_EQ(SERVICE_WORKER_OK, result); |
597 EXPECT_EQ(2u, verify_ids.size()); | 597 EXPECT_EQ(2u, verify_ids.size()); |
598 verify_ids.clear(); | 598 verify_ids.clear(); |
599 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 599 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
600 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 600 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
601 EXPECT_TRUE(verify_ids.empty()); | 601 EXPECT_TRUE(verify_ids.empty()); |
602 | 602 |
| 603 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, |
| 604 registration_->waiting_version()->status()); |
| 605 |
603 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); | 606 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); |
604 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); | 607 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); |
605 } | 608 } |
606 | 609 |
607 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) { | 610 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) { |
608 // Promote the worker to active and add a controllee. | 611 // Promote the worker to active and add a controllee. |
609 registration_->SetActiveVersion(registration_->waiting_version()); | 612 ServiceWorkerVersion* version = registration_->waiting_version(); |
| 613 version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 614 registration_->SetActiveVersion(version); |
610 storage()->UpdateToActiveState( | 615 storage()->UpdateToActiveState( |
611 registration_, base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 616 registration_, base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
612 scoped_ptr<ServiceWorkerProviderHost> host( | 617 scoped_ptr<ServiceWorkerProviderHost> host( |
613 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 618 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
614 1 /* dummy provider_id */, | 619 1 /* dummy provider_id */, |
615 context_->AsWeakPtr(), | 620 context_->AsWeakPtr(), |
616 NULL)); | 621 NULL)); |
617 registration_->active_version()->AddControllee(host.get()); | 622 version->AddControllee(host.get()); |
618 | 623 |
619 bool was_called = false; | 624 bool was_called = false; |
620 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | 625 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; |
621 std::set<int64> verify_ids; | 626 std::set<int64> verify_ids; |
622 | 627 |
623 // Deleting the registration should move the resources to the purgeable list | 628 // Deleting the registration should move the resources to the purgeable list |
624 // but keep them available. | 629 // but keep them available. |
625 storage()->DeleteRegistration( | 630 storage()->DeleteRegistration( |
626 registration_->id(), | 631 registration_->id(), |
627 scope_.GetOrigin(), | 632 scope_.GetOrigin(), |
628 base::Bind(&VerifyPurgeableListStatusCallback, | 633 base::Bind(&VerifyPurgeableListStatusCallback, |
629 base::Unretained(storage()->database_.get()), | 634 base::Unretained(storage()->database_.get()), |
630 &verify_ids, | 635 &verify_ids, |
631 &was_called, | 636 &was_called, |
632 &result)); | 637 &result)); |
633 base::RunLoop().RunUntilIdle(); | 638 base::RunLoop().RunUntilIdle(); |
634 ASSERT_TRUE(was_called); | 639 ASSERT_TRUE(was_called); |
635 EXPECT_EQ(SERVICE_WORKER_OK, result); | 640 EXPECT_EQ(SERVICE_WORKER_OK, result); |
636 EXPECT_EQ(2u, verify_ids.size()); | 641 EXPECT_EQ(2u, verify_ids.size()); |
637 verify_ids.clear(); | 642 verify_ids.clear(); |
638 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 643 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
639 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 644 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
640 EXPECT_EQ(2u, verify_ids.size()); | 645 EXPECT_EQ(2u, verify_ids.size()); |
641 | 646 |
642 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); | 647 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); |
643 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, true)); | 648 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, true)); |
644 | 649 |
| 650 // The live version should still be activated. |
| 651 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
| 652 |
645 // Removing the controllee should cause the resources to be deleted. | 653 // Removing the controllee should cause the resources to be deleted. |
646 registration_->active_version()->RemoveControllee(host.get()); | 654 version->RemoveControllee(host.get()); |
647 base::RunLoop().RunUntilIdle(); | 655 base::RunLoop().RunUntilIdle(); |
648 verify_ids.clear(); | 656 verify_ids.clear(); |
649 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 657 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
650 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 658 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
651 EXPECT_TRUE(verify_ids.empty()); | 659 EXPECT_TRUE(verify_ids.empty()); |
652 | 660 |
653 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); | 661 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); |
654 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); | 662 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); |
| 663 |
| 664 // The live version should now be redundant. |
| 665 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
655 } | 666 } |
656 | 667 |
657 // Android has flaky IO error: http://crbug.com/387045 | 668 // Android has flaky IO error: http://crbug.com/387045 |
658 #if defined(OS_ANDROID) | 669 #if defined(OS_ANDROID) |
659 #define MAYBE_CleanupOnRestart DISABLED_CleanupOnRestart | 670 #define MAYBE_CleanupOnRestart DISABLED_CleanupOnRestart |
660 #else | 671 #else |
661 #define MAYBE_CleanupOnRestart CleanupOnRestart | 672 #define MAYBE_CleanupOnRestart CleanupOnRestart |
662 #endif | 673 #endif |
663 TEST_F(ServiceWorkerResourceStorageDiskTest, MAYBE_CleanupOnRestart) { | 674 TEST_F(ServiceWorkerResourceStorageDiskTest, MAYBE_CleanupOnRestart) { |
664 // Promote the worker to active and add a controllee. | 675 // Promote the worker to active and add a controllee. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 verify_ids.clear(); | 727 verify_ids.clear(); |
717 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 728 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
718 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 729 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
719 EXPECT_TRUE(verify_ids.empty()); | 730 EXPECT_TRUE(verify_ids.empty()); |
720 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); | 731 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); |
721 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); | 732 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); |
722 } | 733 } |
723 | 734 |
724 TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) { | 735 TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) { |
725 // Promote the worker to active worker and add a controllee. | 736 // Promote the worker to active worker and add a controllee. |
726 registration_->SetActiveVersion(registration_->waiting_version()); | 737 ServiceWorkerVersion* version = registration_->waiting_version(); |
| 738 version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 739 registration_->SetActiveVersion(version); |
727 storage()->UpdateToActiveState( | 740 storage()->UpdateToActiveState( |
728 registration_, base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 741 registration_, base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
729 scoped_ptr<ServiceWorkerProviderHost> host( | 742 scoped_ptr<ServiceWorkerProviderHost> host( |
730 new ServiceWorkerProviderHost(33 /* dummy render process id */, | 743 new ServiceWorkerProviderHost(33 /* dummy render process id */, |
731 1 /* dummy provider_id */, | 744 1 /* dummy provider_id */, |
732 context_->AsWeakPtr(), | 745 context_->AsWeakPtr(), |
733 NULL)); | 746 NULL)); |
734 registration_->active_version()->AddControllee(host.get()); | 747 version->AddControllee(host.get()); |
735 | 748 |
736 bool was_called = false; | 749 bool was_called = false; |
737 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | 750 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; |
738 std::set<int64> verify_ids; | 751 std::set<int64> verify_ids; |
739 | 752 |
740 // Make an updated registration. | 753 // Make an updated registration. |
741 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 754 scoped_refptr<ServiceWorkerVersion> new_version = new ServiceWorkerVersion( |
742 registration_, storage()->NewVersionId(), context_ptr_); | 755 registration_, storage()->NewVersionId(), context_ptr_); |
743 live_version->SetStatus(ServiceWorkerVersion::NEW); | 756 new_version->SetStatus(ServiceWorkerVersion::NEW); |
744 registration_->SetWaitingVersion(live_version); | 757 registration_->SetWaitingVersion(new_version); |
745 | 758 |
746 // Writing the registration should move the old version's resources to the | 759 // Writing the registration should move the old version's resources to the |
747 // purgeable list but keep them available. | 760 // purgeable list but keep them available. |
748 storage()->StoreRegistration( | 761 storage()->StoreRegistration( |
749 registration_, | 762 registration_, |
750 registration_->waiting_version(), | 763 registration_->waiting_version(), |
751 base::Bind(&VerifyPurgeableListStatusCallback, | 764 base::Bind(&VerifyPurgeableListStatusCallback, |
752 base::Unretained(storage()->database_.get()), | 765 base::Unretained(storage()->database_.get()), |
753 &verify_ids, | 766 &verify_ids, |
754 &was_called, | 767 &was_called, |
755 &result)); | 768 &result)); |
756 base::RunLoop().RunUntilIdle(); | 769 base::RunLoop().RunUntilIdle(); |
757 ASSERT_TRUE(was_called); | 770 ASSERT_TRUE(was_called); |
758 EXPECT_EQ(SERVICE_WORKER_OK, result); | 771 EXPECT_EQ(SERVICE_WORKER_OK, result); |
759 EXPECT_EQ(2u, verify_ids.size()); | 772 EXPECT_EQ(2u, verify_ids.size()); |
760 verify_ids.clear(); | 773 verify_ids.clear(); |
761 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 774 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
762 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 775 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
763 EXPECT_EQ(2u, verify_ids.size()); | 776 EXPECT_EQ(2u, verify_ids.size()); |
764 | 777 |
765 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false)); | 778 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false)); |
766 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, false)); | 779 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, false)); |
767 | 780 |
| 781 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); |
| 782 |
768 // Removing the controllee should cause the old version's resources to be | 783 // Removing the controllee should cause the old version's resources to be |
769 // deleted. | 784 // deleted. |
770 registration_->active_version()->RemoveControllee(host.get()); | 785 version->RemoveControllee(host.get()); |
771 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
772 verify_ids.clear(); | 787 verify_ids.clear(); |
773 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 788 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
774 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 789 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
775 EXPECT_TRUE(verify_ids.empty()); | 790 EXPECT_TRUE(verify_ids.empty()); |
776 | 791 |
777 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); | 792 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); |
778 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); | 793 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); |
| 794 |
| 795 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); |
779 } | 796 } |
780 | 797 |
781 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { | 798 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { |
782 const GURL kDocumentUrl("http://www.example.com/scope/foo"); | 799 const GURL kDocumentUrl("http://www.example.com/scope/foo"); |
783 scoped_refptr<ServiceWorkerRegistration> found_registration; | 800 scoped_refptr<ServiceWorkerRegistration> found_registration; |
784 | 801 |
785 // Registration for "/scope/*". | 802 // Registration for "/scope/*". |
786 const GURL kScope1("http://www.example.com/scope/*"); | 803 const GURL kScope1("http://www.example.com/scope/*"); |
787 const GURL kScript1("http://www.example.com/script1.js"); | 804 const GURL kScript1("http://www.example.com/script1.js"); |
788 const int64 kRegistrationId1 = 1; | 805 const int64 kRegistrationId1 = 1; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 storage()->NotifyDoneInstallingRegistration( | 868 storage()->NotifyDoneInstallingRegistration( |
852 live_registration3, NULL, SERVICE_WORKER_OK); | 869 live_registration3, NULL, SERVICE_WORKER_OK); |
853 | 870 |
854 // Find a registration among installed ones. | 871 // Find a registration among installed ones. |
855 EXPECT_EQ(SERVICE_WORKER_OK, | 872 EXPECT_EQ(SERVICE_WORKER_OK, |
856 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 873 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
857 EXPECT_EQ(live_registration2, found_registration); | 874 EXPECT_EQ(live_registration2, found_registration); |
858 } | 875 } |
859 | 876 |
860 } // namespace content | 877 } // namespace content |
OLD | NEW |