OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
6 #include <sstream> | 6 #include <sstream> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 using base::MessageLoopProxy; | 26 using base::MessageLoopProxy; |
27 | 27 |
28 namespace quota { | 28 namespace quota { |
29 | 29 |
30 // For shorter names. | 30 // For shorter names. |
31 const StorageType kTemp = kStorageTypeTemporary; | 31 const StorageType kTemp = kStorageTypeTemporary; |
32 const StorageType kPerm = kStorageTypePersistent; | 32 const StorageType kPerm = kStorageTypePersistent; |
33 | 33 |
34 const int kAllClients = QuotaClient::kAllClientsMask; | 34 const int kAllClients = QuotaClient::kAllClientsMask; |
35 | 35 |
| 36 // Returns a deterministic value for the amount of available disk space. |
| 37 int64 GetAvailableDiskSpaceForTest(const FilePath&) { |
| 38 return 13377331; |
| 39 } |
| 40 |
36 class QuotaManagerTest : public testing::Test { | 41 class QuotaManagerTest : public testing::Test { |
37 protected: | 42 protected: |
38 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; | 43 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; |
39 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; | 44 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; |
40 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; | 45 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; |
41 | 46 |
42 public: | 47 public: |
43 QuotaManagerTest() | 48 QuotaManagerTest() |
44 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 49 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
45 mock_time_counter_(0) { | 50 mock_time_counter_(0) { |
46 } | 51 } |
47 | 52 |
48 void SetUp() { | 53 void SetUp() { |
49 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 54 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
50 mock_special_storage_policy_ = new MockSpecialStoragePolicy; | 55 mock_special_storage_policy_ = new MockSpecialStoragePolicy; |
51 quota_manager_ = new QuotaManager( | 56 quota_manager_ = new QuotaManager( |
52 false /* is_incognito */, | 57 false /* is_incognito */, |
53 data_dir_.path(), | 58 data_dir_.path(), |
54 MessageLoopProxy::current(), | 59 MessageLoopProxy::current(), |
55 MessageLoopProxy::current(), | 60 MessageLoopProxy::current(), |
56 mock_special_storage_policy_); | 61 mock_special_storage_policy_); |
57 // Don't (automatically) start the eviction for testing. | 62 // Don't (automatically) start the eviction for testing. |
58 quota_manager_->eviction_disabled_ = true; | 63 quota_manager_->eviction_disabled_ = true; |
| 64 // Don't query the hard disk for remaining capacity. |
| 65 quota_manager_->get_disk_space_fn_ = &GetAvailableDiskSpaceForTest; |
59 additional_callback_count_ = 0; | 66 additional_callback_count_ = 0; |
60 } | 67 } |
61 | 68 |
62 void TearDown() { | 69 void TearDown() { |
63 // Make sure the quota manager cleans up correctly. | 70 // Make sure the quota manager cleans up correctly. |
64 quota_manager_ = NULL; | 71 quota_manager_ = NULL; |
65 MessageLoop::current()->RunAllPending(); | 72 MessageLoop::current()->RunAllPending(); |
66 } | 73 } |
67 | 74 |
68 protected: | 75 protected: |
69 MockStorageClient* CreateClient( | 76 MockStorageClient* CreateClient( |
70 const MockOriginData* mock_data, | 77 const MockOriginData* mock_data, |
71 size_t mock_data_size, | 78 size_t mock_data_size, |
72 QuotaClient::ID id) { | 79 QuotaClient::ID id) { |
73 return new MockStorageClient(quota_manager_->proxy(), | 80 return new MockStorageClient(quota_manager_->proxy(), |
74 mock_data, id, mock_data_size); | 81 mock_data, id, mock_data_size); |
75 } | 82 } |
76 | 83 |
77 void RegisterClient(MockStorageClient* client) { | 84 void RegisterClient(MockStorageClient* client) { |
78 quota_manager_->proxy()->RegisterClient(client); | 85 quota_manager_->proxy()->RegisterClient(client); |
79 } | 86 } |
80 | 87 |
81 void GetUsageInfo() { | 88 void GetUsageInfo() { |
82 usage_info_.clear(); | 89 usage_info_.clear(); |
83 quota_manager_->GetUsageInfo( | 90 quota_manager_->GetUsageInfo( |
84 base::Bind(&QuotaManagerTest::DidGetUsageInfo, | 91 base::Bind(&QuotaManagerTest::DidGetUsageInfo, |
85 weak_factory_.GetWeakPtr())); | 92 weak_factory_.GetWeakPtr())); |
86 } | 93 } |
87 | 94 |
88 void GetUsageAndQuota(const GURL& origin, StorageType type) { | 95 void GetUsageAndQuota(const GURL& origin, |
| 96 StorageType type) { |
89 quota_status_ = kQuotaStatusUnknown; | 97 quota_status_ = kQuotaStatusUnknown; |
90 usage_ = -1; | 98 usage_ = -1; |
91 quota_ = -1; | 99 quota_ = -1; |
92 quota_manager_->GetUsageAndQuota( | 100 quota_manager_->GetUsageAndQuota( |
93 origin, type, | 101 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, |
94 base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, | 102 weak_factory_.GetWeakPtr())); |
95 weak_factory_.GetWeakPtr())); | |
96 } | 103 } |
97 | 104 |
98 void GetTemporaryGlobalQuota() { | 105 void GetTemporaryGlobalQuota() { |
99 quota_status_ = kQuotaStatusUnknown; | 106 quota_status_ = kQuotaStatusUnknown; |
100 quota_ = -1; | 107 quota_ = -1; |
101 quota_manager_->GetTemporaryGlobalQuota( | 108 quota_manager_->GetTemporaryGlobalQuota( |
102 base::Bind(&QuotaManagerTest::DidGetQuota, | 109 base::Bind(&QuotaManagerTest::DidGetQuota, |
103 weak_factory_.GetWeakPtr())); | 110 weak_factory_.GetWeakPtr())); |
104 } | 111 } |
105 | 112 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 162 } |
156 | 163 |
157 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { | 164 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { |
158 quota_manager_->GetUsageAndQuota( | 165 quota_manager_->GetUsageAndQuota( |
159 origin, type, | 166 origin, type, |
160 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional, | 167 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional, |
161 weak_factory_.GetWeakPtr())); | 168 weak_factory_.GetWeakPtr())); |
162 } | 169 } |
163 | 170 |
164 void DeleteClientOriginData(QuotaClient* client, | 171 void DeleteClientOriginData(QuotaClient* client, |
165 const GURL& origin, | 172 const GURL& origin, |
166 StorageType type) { | 173 StorageType type) { |
167 DCHECK(client); | 174 DCHECK(client); |
168 quota_status_ = kQuotaStatusUnknown; | 175 quota_status_ = kQuotaStatusUnknown; |
169 client->DeleteOriginData( | 176 client->DeleteOriginData( |
170 origin, type, | 177 origin, type, |
171 base::Bind(&QuotaManagerTest::StatusCallback, | 178 base::Bind(&QuotaManagerTest::StatusCallback, |
172 weak_factory_.GetWeakPtr())); | 179 weak_factory_.GetWeakPtr())); |
173 } | 180 } |
174 | 181 |
175 void EvictOriginData(const GURL& origin, | 182 void EvictOriginData(const GURL& origin, |
176 StorageType type) { | 183 StorageType type) { |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 595 |
589 GetUsageAndQuota(GURL("http://bar.com/"), kTemp); | 596 GetUsageAndQuota(GURL("http://bar.com/"), kTemp); |
590 MessageLoop::current()->RunAllPending(); | 597 MessageLoop::current()->RunAllPending(); |
591 EXPECT_EQ(kQuotaStatusOk, status()); | 598 EXPECT_EQ(kQuotaStatusOk, status()); |
592 EXPECT_EQ(5 + 7, usage()); | 599 EXPECT_EQ(5 + 7, usage()); |
593 EXPECT_EQ(kPerHostQuota, quota()); | 600 EXPECT_EQ(kPerHostQuota, quota()); |
594 } | 601 } |
595 | 602 |
596 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { | 603 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { |
597 static const MockOriginData kData1[] = { | 604 static const MockOriginData kData1[] = { |
598 { "http://foo.com/", kTemp, 10 }, | 605 { "http://foo.com/", kTemp, 10 }, |
599 { "http://bar.com/", kTemp, 20 }, | 606 { "http://bar.com/", kTemp, 20 }, |
600 { "http://bar.com/", kPerm, 50 }, | 607 { "http://bar.com/", kPerm, 50 }, |
601 { "http://unlimited/", kPerm, 1 }, | 608 { "http://unlimited/", kPerm, 1 }, |
| 609 { "http://installed/", kPerm, 1 }, |
602 }; | 610 }; |
603 static const MockOriginData kData2[] = { | 611 static const MockOriginData kData2[] = { |
604 { "https://foo.com/", kTemp, 30 }, | 612 { "https://foo.com/", kTemp, 30 }, |
605 { "http://example.com/", kPerm, 40 }, | 613 { "http://example.com/", kPerm, 40 }, |
606 { "http://unlimited/", kTemp, 1 }, | 614 { "http://unlimited/", kTemp, 1 }, |
| 615 { "http://installed/", kTemp, 1 }, |
607 }; | 616 }; |
608 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 617 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
| 618 mock_special_storage_policy()->AddInstalledApp(GURL("http://installed/")); |
609 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 619 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
610 QuotaClient::kFileSystem)); | 620 QuotaClient::kFileSystem)); |
611 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 621 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
612 QuotaClient::kDatabase)); | 622 QuotaClient::kDatabase)); |
613 | 623 |
614 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 624 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
615 MessageLoop::current()->RunAllPending(); | 625 MessageLoop::current()->RunAllPending(); |
616 EXPECT_EQ(kQuotaStatusOk, status()); | 626 EXPECT_EQ(kQuotaStatusOk, status()); |
617 EXPECT_EQ(10 + 30, usage()); | 627 EXPECT_EQ(10 + 30, usage()); |
618 | 628 |
619 GetUsageAndQuota(GURL("http://bar.com/"), kPerm); | 629 GetUsageAndQuota(GURL("http://bar.com/"), kPerm); |
620 MessageLoop::current()->RunAllPending(); | 630 MessageLoop::current()->RunAllPending(); |
621 EXPECT_EQ(kQuotaStatusOk, status()); | 631 EXPECT_EQ(kQuotaStatusOk, status()); |
622 EXPECT_EQ(50, usage()); | 632 EXPECT_EQ(50, usage()); |
623 | 633 |
624 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 634 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
625 MessageLoop::current()->RunAllPending(); | 635 MessageLoop::current()->RunAllPending(); |
626 EXPECT_EQ(kQuotaStatusOk, status()); | 636 EXPECT_EQ(kQuotaStatusOk, status()); |
627 EXPECT_EQ(1, usage()); | 637 EXPECT_EQ(1, usage()); |
628 EXPECT_EQ(kint64max, quota()); | 638 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
629 | 639 |
630 GetUsageAndQuota(GURL("http://unlimited/"), kPerm); | 640 GetUsageAndQuota(GURL("http://unlimited/"), kPerm); |
631 MessageLoop::current()->RunAllPending(); | 641 MessageLoop::current()->RunAllPending(); |
632 EXPECT_EQ(kQuotaStatusOk, status()); | 642 EXPECT_EQ(kQuotaStatusOk, status()); |
633 EXPECT_EQ(1, usage()); | 643 EXPECT_EQ(1, usage()); |
634 EXPECT_EQ(kint64max, quota()); | 644 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
| 645 |
| 646 GetAvailableSpace(); |
| 647 MessageLoop::current()->RunAllPending(); |
| 648 EXPECT_EQ(kQuotaStatusOk, status()); |
| 649 EXPECT_LE(0, available_space()); |
| 650 |
| 651 GetUsageAndQuota(GURL("http://installed/"), kTemp); |
| 652 MessageLoop::current()->RunAllPending(); |
| 653 EXPECT_EQ(kQuotaStatusOk, status()); |
| 654 EXPECT_EQ(1, usage()); |
| 655 EXPECT_EQ(available_space(), quota()); |
| 656 |
| 657 GetUsageAndQuota(GURL("http://installed/"), kPerm); |
| 658 MessageLoop::current()->RunAllPending(); |
| 659 EXPECT_EQ(kQuotaStatusOk, status()); |
| 660 EXPECT_EQ(1, usage()); |
| 661 EXPECT_EQ(available_space(), quota()); |
635 | 662 |
636 GetGlobalUsage(kTemp); | 663 GetGlobalUsage(kTemp); |
637 MessageLoop::current()->RunAllPending(); | 664 MessageLoop::current()->RunAllPending(); |
638 EXPECT_EQ(kQuotaStatusOk, status()); | 665 EXPECT_EQ(kQuotaStatusOk, status()); |
639 EXPECT_EQ(10 + 20 + 30 + 1, usage()); | 666 EXPECT_EQ(10 + 20 + 30 + 1 + 1, usage()); |
640 EXPECT_EQ(1, unlimited_usage()); | 667 EXPECT_EQ(2, unlimited_usage()); |
641 | 668 |
642 GetGlobalUsage(kPerm); | 669 GetGlobalUsage(kPerm); |
643 MessageLoop::current()->RunAllPending(); | 670 MessageLoop::current()->RunAllPending(); |
644 EXPECT_EQ(kQuotaStatusOk, status()); | 671 EXPECT_EQ(kQuotaStatusOk, status()); |
645 EXPECT_EQ(40 + 50 + 1, usage()); | 672 EXPECT_EQ(40 + 50 + 1 + 1, usage()); |
646 EXPECT_EQ(1, unlimited_usage()); | 673 EXPECT_EQ(2, unlimited_usage()); |
647 } | 674 } |
648 | 675 |
649 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { | 676 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { |
650 const MockOriginData data[] = { | 677 const MockOriginData data[] = { |
651 { "http://foo.com/", type, 10 }, | 678 { "http://foo.com/", type, 10 }, |
652 { "http://foo.com:1/", type, 20 }, | 679 { "http://foo.com:1/", type, 20 }, |
653 }; | 680 }; |
654 MockStorageClient* client = CreateClient(data, ARRAYSIZE_UNSAFE(data), | 681 MockStorageClient* client = CreateClient(data, ARRAYSIZE_UNSAFE(data), |
655 QuotaClient::kFileSystem); | 682 QuotaClient::kFileSystem); |
656 RegisterClient(client); | 683 RegisterClient(client); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 732 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
706 MessageLoop::current()->RunAllPending(); | 733 MessageLoop::current()->RunAllPending(); |
707 EXPECT_EQ(kQuotaStatusOk, status()); | 734 EXPECT_EQ(kQuotaStatusOk, status()); |
708 EXPECT_EQ(10 + 20, usage()); | 735 EXPECT_EQ(10 + 20, usage()); |
709 EXPECT_EQ(kPerHostQuota, quota()); | 736 EXPECT_EQ(kPerHostQuota, quota()); |
710 | 737 |
711 set_additional_callback_count(0); | 738 set_additional_callback_count(0); |
712 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 739 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
713 kTemp); | 740 kTemp); |
714 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 741 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
715 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | 742 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kTemp); |
716 kTemp); | |
717 MessageLoop::current()->RunAllPending(); | 743 MessageLoop::current()->RunAllPending(); |
718 EXPECT_EQ(kQuotaStatusOk, status()); | 744 EXPECT_EQ(kQuotaStatusOk, status()); |
719 EXPECT_EQ(10 + 20, usage()); | 745 EXPECT_EQ(10 + 20, usage()); |
720 EXPECT_EQ(kPerHostQuota, quota()); | 746 EXPECT_EQ(kPerHostQuota, quota()); |
721 EXPECT_EQ(2, additional_callback_count()); | 747 EXPECT_EQ(2, additional_callback_count()); |
722 } | 748 } |
723 | 749 |
724 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { | 750 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { |
725 static const MockOriginData kData[] = { | 751 static const MockOriginData kData[] = { |
726 { "http://foo.com/", kTemp, 10 }, | 752 { "http://foo.com/", kTemp, 10 }, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 GetUsageAndQuota(GURL("http://usage50/"), kTemp); | 839 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
814 MessageLoop::current()->RunAllPending(); | 840 MessageLoop::current()->RunAllPending(); |
815 EXPECT_EQ(kQuotaStatusOk, status()); | 841 EXPECT_EQ(kQuotaStatusOk, status()); |
816 EXPECT_EQ(50, usage()); | 842 EXPECT_EQ(50, usage()); |
817 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 843 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
818 | 844 |
819 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 845 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
820 MessageLoop::current()->RunAllPending(); | 846 MessageLoop::current()->RunAllPending(); |
821 EXPECT_EQ(kQuotaStatusOk, status()); | 847 EXPECT_EQ(kQuotaStatusOk, status()); |
822 EXPECT_EQ(4000, usage()); | 848 EXPECT_EQ(4000, usage()); |
823 EXPECT_EQ(kint64max, quota()); | 849 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
824 | 850 |
825 // Test when overbugdet. | 851 // Test when overbugdet. |
826 SetTemporaryGlobalQuota(100); | 852 SetTemporaryGlobalQuota(100); |
827 MessageLoop::current()->RunAllPending(); | 853 MessageLoop::current()->RunAllPending(); |
828 | 854 |
829 const int kPerHostQuotaFor100 = | 855 const int kPerHostQuotaFor100 = |
830 100 / QuotaManager::kPerHostTemporaryPortion; | 856 100 / QuotaManager::kPerHostTemporaryPortion; |
831 | 857 |
832 GetUsageAndQuota(GURL("http://usage10/"), kTemp); | 858 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
833 MessageLoop::current()->RunAllPending(); | 859 MessageLoop::current()->RunAllPending(); |
834 EXPECT_EQ(kQuotaStatusOk, status()); | 860 EXPECT_EQ(kQuotaStatusOk, status()); |
835 EXPECT_EQ(10, usage()); | 861 EXPECT_EQ(10, usage()); |
836 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 862 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
837 | 863 |
838 GetUsageAndQuota(GURL("http://usage50/"), kTemp); | 864 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
839 MessageLoop::current()->RunAllPending(); | 865 MessageLoop::current()->RunAllPending(); |
840 EXPECT_EQ(kQuotaStatusOk, status()); | 866 EXPECT_EQ(kQuotaStatusOk, status()); |
841 EXPECT_EQ(50, usage()); | 867 EXPECT_EQ(50, usage()); |
842 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 868 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
843 | 869 |
844 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 870 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
845 MessageLoop::current()->RunAllPending(); | 871 MessageLoop::current()->RunAllPending(); |
846 EXPECT_EQ(kQuotaStatusOk, status()); | 872 EXPECT_EQ(kQuotaStatusOk, status()); |
847 EXPECT_EQ(4000, usage()); | 873 EXPECT_EQ(4000, usage()); |
848 EXPECT_EQ(kint64max, quota()); | 874 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
849 | 875 |
850 // Revoke the unlimited rights and make sure the change is noticed. | 876 // Revoke the unlimited rights and make sure the change is noticed. |
851 mock_special_storage_policy()->Reset(); | 877 mock_special_storage_policy()->Reset(); |
852 mock_special_storage_policy()->NotifyChanged(); | 878 mock_special_storage_policy()->NotifyChanged(); |
853 | 879 |
854 GetGlobalUsage(kTemp); | 880 GetGlobalUsage(kTemp); |
855 MessageLoop::current()->RunAllPending(); | 881 MessageLoop::current()->RunAllPending(); |
856 EXPECT_EQ(10 + 50 + 4000, usage()); | 882 EXPECT_EQ(10 + 50 + 4000, usage()); |
857 EXPECT_EQ(0, unlimited_usage()); | 883 EXPECT_EQ(0, unlimited_usage()); |
858 | 884 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 1004 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
979 MessageLoop::current()->RunAllPending(); | 1005 MessageLoop::current()->RunAllPending(); |
980 EXPECT_EQ(kQuotaStatusOk, status()); | 1006 EXPECT_EQ(kQuotaStatusOk, status()); |
981 EXPECT_EQ(10 + 20, usage()); | 1007 EXPECT_EQ(10 + 20, usage()); |
982 EXPECT_EQ(100, quota()); | 1008 EXPECT_EQ(100, quota()); |
983 | 1009 |
984 set_additional_callback_count(0); | 1010 set_additional_callback_count(0); |
985 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 1011 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
986 kPerm); | 1012 kPerm); |
987 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 1013 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
988 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | 1014 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); |
989 kPerm); | |
990 MessageLoop::current()->RunAllPending(); | 1015 MessageLoop::current()->RunAllPending(); |
991 EXPECT_EQ(kQuotaStatusOk, status()); | 1016 EXPECT_EQ(kQuotaStatusOk, status()); |
992 EXPECT_EQ(10 + 20, usage()); | 1017 EXPECT_EQ(10 + 20, usage()); |
993 EXPECT_EQ(2, additional_callback_count()); | 1018 EXPECT_EQ(2, additional_callback_count()); |
994 } | 1019 } |
995 | 1020 |
996 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) { | 1021 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) { |
997 static const MockOriginData kData[] = { | 1022 static const MockOriginData kData[] = { |
998 { "http://foo.com/", kPerm, 10 }, | 1023 { "http://foo.com/", kPerm, 10 }, |
999 { "http://foo.com:8080/", kPerm, 20 }, | 1024 { "http://foo.com:8080/", kPerm, 20 }, |
1000 { "http://bar.com/", kPerm, 13 }, | 1025 { "http://bar.com/", kPerm, 13 }, |
1001 { "http://foo.com/", kTemp, 40 }, | 1026 { "http://foo.com/", kTemp, 40 }, |
1002 }; | 1027 }; |
1003 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1028 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1004 QuotaClient::kFileSystem)); | 1029 QuotaClient::kFileSystem)); |
1005 SetPersistentHostQuota("foo.com", 100); | 1030 SetPersistentHostQuota("foo.com", 100); |
1006 | 1031 |
1007 set_additional_callback_count(0); | 1032 set_additional_callback_count(0); |
1008 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 1033 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
1009 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 1034 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), kPerm); |
1010 kPerm); | 1035 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); |
1011 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | |
1012 kPerm); | |
1013 | 1036 |
1014 // Nuke before waiting for callbacks. | 1037 // Nuke before waiting for callbacks. |
1015 set_quota_manager(NULL); | 1038 set_quota_manager(NULL); |
1016 MessageLoop::current()->RunAllPending(); | 1039 MessageLoop::current()->RunAllPending(); |
1017 EXPECT_EQ(kQuotaErrorAbort, status()); | 1040 EXPECT_EQ(kQuotaErrorAbort, status()); |
1018 } | 1041 } |
1019 | 1042 |
1020 TEST_F(QuotaManagerTest, GetUsage_Simple) { | 1043 TEST_F(QuotaManagerTest, GetUsage_Simple) { |
1021 static const MockOriginData kData[] = { | 1044 static const MockOriginData kData[] = { |
1022 { "http://foo.com/", kPerm, 1 }, | 1045 { "http://foo.com/", kPerm, 1 }, |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | 2051 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); |
2029 | 2052 |
2030 DeleteHostData("foo.com", kTemp, | 2053 DeleteHostData("foo.com", kTemp, |
2031 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); | 2054 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); |
2032 MessageLoop::current()->RunAllPending(); | 2055 MessageLoop::current()->RunAllPending(); |
2033 GetHostUsage("foo.com", kTemp); | 2056 GetHostUsage("foo.com", kTemp); |
2034 MessageLoop::current()->RunAllPending(); | 2057 MessageLoop::current()->RunAllPending(); |
2035 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | 2058 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); |
2036 } | 2059 } |
2037 } // namespace quota | 2060 } // namespace quota |
OLD | NEW |