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