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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 } | 570 } |
571 | 571 |
572 virtual base::FilePath GetUserDataDirectory() OVERRIDE { | 572 virtual base::FilePath GetUserDataDirectory() OVERRIDE { |
573 return user_data_directory_.path(); | 573 return user_data_directory_.path(); |
574 } | 574 } |
575 | 575 |
576 protected: | 576 protected: |
577 base::ScopedTempDir user_data_directory_; | 577 base::ScopedTempDir user_data_directory_; |
578 }; | 578 }; |
579 | 579 |
580 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_NoLiveVersion) { | |
581 bool was_called = false; | |
582 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | |
583 std::set<int64> verify_ids; | |
584 | |
585 registration_->SetWaitingVersion(NULL); | |
michaeln
2014/07/11 01:16:05
maybe drop the registration_ altogether by setting
falken
2014/07/11 12:08:12
Done.
| |
586 | |
587 // Deleting the registration should result in the resources being added to the | |
588 // purgeable list and then doomed in the disk cache and removed from that | |
589 // list. | |
590 storage()->DeleteRegistration( | |
591 registration_->id(), | |
592 scope_.GetOrigin(), | |
593 base::Bind(&VerifyPurgeableListStatusCallback, | |
594 base::Unretained(storage()->database_.get()), | |
595 &verify_ids, | |
596 &was_called, | |
597 &result)); | |
598 base::RunLoop().RunUntilIdle(); | |
599 ASSERT_TRUE(was_called); | |
600 EXPECT_EQ(SERVICE_WORKER_OK, result); | |
601 EXPECT_EQ(2u, verify_ids.size()); | |
602 verify_ids.clear(); | |
603 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | |
604 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | |
605 EXPECT_TRUE(verify_ids.empty()); | |
606 | |
607 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); | |
608 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); | |
609 } | |
610 | |
580 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) { | 611 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) { |
581 bool was_called = false; | 612 bool was_called = false; |
582 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | 613 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; |
583 std::set<int64> verify_ids; | 614 std::set<int64> verify_ids; |
584 | 615 |
585 // Deleting the registration should result in the resources being added to the | 616 // Deleting the registration should result in the resources being added to the |
586 // purgeable list and then doomed in the disk cache and removed from that | 617 // purgeable list and then doomed in the disk cache and removed from that |
587 // list. | 618 // list. |
588 storage()->DeleteRegistration( | 619 storage()->DeleteRegistration( |
589 registration_->id(), | 620 registration_->id(), |
590 scope_.GetOrigin(), | 621 scope_.GetOrigin(), |
591 base::Bind(&VerifyPurgeableListStatusCallback, | 622 base::Bind(&VerifyPurgeableListStatusCallback, |
592 base::Unretained(storage()->database_.get()), | 623 base::Unretained(storage()->database_.get()), |
593 &verify_ids, | 624 &verify_ids, |
594 &was_called, | 625 &was_called, |
595 &result)); | 626 &result)); |
596 base::RunLoop().RunUntilIdle(); | 627 base::RunLoop().RunUntilIdle(); |
597 ASSERT_TRUE(was_called); | 628 ASSERT_TRUE(was_called); |
598 EXPECT_EQ(SERVICE_WORKER_OK, result); | 629 EXPECT_EQ(SERVICE_WORKER_OK, result); |
599 EXPECT_EQ(2u, verify_ids.size()); | 630 EXPECT_EQ(2u, verify_ids.size()); |
600 verify_ids.clear(); | 631 verify_ids.clear(); |
601 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 632 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
602 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 633 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
634 EXPECT_EQ(2u, verify_ids.size()); | |
635 | |
636 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false)); | |
637 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, false)); | |
638 | |
639 // Doom the version, now it happens. | |
640 registration_->waiting_version()->Doom(); | |
641 base::RunLoop().RunUntilIdle(); | |
642 EXPECT_EQ(SERVICE_WORKER_OK, result); | |
643 EXPECT_EQ(2u, verify_ids.size()); | |
644 verify_ids.clear(); | |
645 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | |
646 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | |
603 EXPECT_TRUE(verify_ids.empty()); | 647 EXPECT_TRUE(verify_ids.empty()); |
604 | 648 |
605 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); | 649 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); |
606 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); | 650 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); |
607 } | 651 } |
608 | 652 |
609 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) { | 653 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) { |
610 // Promote the worker to active and add a controllee. | 654 // Promote the worker to active and add a controllee. |
611 registration_->SetActiveVersion(registration_->waiting_version()); | 655 registration_->SetActiveVersion(registration_->waiting_version()); |
612 storage()->UpdateToActiveState( | 656 storage()->UpdateToActiveState( |
(...skipping 12 matching lines...) Expand all Loading... | |
625 // Deleting the registration should move the resources to the purgeable list | 669 // Deleting the registration should move the resources to the purgeable list |
626 // but keep them available. | 670 // but keep them available. |
627 storage()->DeleteRegistration( | 671 storage()->DeleteRegistration( |
628 registration_->id(), | 672 registration_->id(), |
629 scope_.GetOrigin(), | 673 scope_.GetOrigin(), |
630 base::Bind(&VerifyPurgeableListStatusCallback, | 674 base::Bind(&VerifyPurgeableListStatusCallback, |
631 base::Unretained(storage()->database_.get()), | 675 base::Unretained(storage()->database_.get()), |
632 &verify_ids, | 676 &verify_ids, |
633 &was_called, | 677 &was_called, |
634 &result)); | 678 &result)); |
679 registration_->active_version()->Doom(); | |
635 base::RunLoop().RunUntilIdle(); | 680 base::RunLoop().RunUntilIdle(); |
636 ASSERT_TRUE(was_called); | 681 ASSERT_TRUE(was_called); |
637 EXPECT_EQ(SERVICE_WORKER_OK, result); | 682 EXPECT_EQ(SERVICE_WORKER_OK, result); |
638 EXPECT_EQ(2u, verify_ids.size()); | 683 EXPECT_EQ(2u, verify_ids.size()); |
639 verify_ids.clear(); | 684 verify_ids.clear(); |
640 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 685 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
641 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 686 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
642 EXPECT_EQ(2u, verify_ids.size()); | 687 EXPECT_EQ(2u, verify_ids.size()); |
643 | 688 |
644 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); | 689 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 // Writing the registration should move the old version's resources to the | 819 // Writing the registration should move the old version's resources to the |
775 // purgeable list but keep them available. | 820 // purgeable list but keep them available. |
776 storage()->StoreRegistration( | 821 storage()->StoreRegistration( |
777 registration_, | 822 registration_, |
778 registration_->waiting_version(), | 823 registration_->waiting_version(), |
779 base::Bind(&VerifyPurgeableListStatusCallback, | 824 base::Bind(&VerifyPurgeableListStatusCallback, |
780 base::Unretained(storage()->database_.get()), | 825 base::Unretained(storage()->database_.get()), |
781 &verify_ids, | 826 &verify_ids, |
782 &was_called, | 827 &was_called, |
783 &result)); | 828 &result)); |
829 registration_->active_version()->Doom(); | |
784 base::RunLoop().RunUntilIdle(); | 830 base::RunLoop().RunUntilIdle(); |
785 ASSERT_TRUE(was_called); | 831 ASSERT_TRUE(was_called); |
786 EXPECT_EQ(SERVICE_WORKER_OK, result); | 832 EXPECT_EQ(SERVICE_WORKER_OK, result); |
787 EXPECT_EQ(2u, verify_ids.size()); | 833 EXPECT_EQ(2u, verify_ids.size()); |
788 verify_ids.clear(); | 834 verify_ids.clear(); |
789 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 835 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
790 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 836 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
791 EXPECT_EQ(2u, verify_ids.size()); | 837 EXPECT_EQ(2u, verify_ids.size()); |
792 | 838 |
793 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false)); | 839 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 storage()->NotifyDoneInstallingRegistration( | 925 storage()->NotifyDoneInstallingRegistration( |
880 live_registration3, NULL, SERVICE_WORKER_OK); | 926 live_registration3, NULL, SERVICE_WORKER_OK); |
881 | 927 |
882 // Find a registration among installed ones. | 928 // Find a registration among installed ones. |
883 EXPECT_EQ(SERVICE_WORKER_OK, | 929 EXPECT_EQ(SERVICE_WORKER_OK, |
884 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 930 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
885 EXPECT_EQ(live_registration2, found_registration); | 931 EXPECT_EQ(live_registration2, found_registration); |
886 } | 932 } |
887 | 933 |
888 } // namespace content | 934 } // namespace content |
OLD | NEW |