OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_temp_dir.h" | 10 #include "base/memory/scoped_temp_dir.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 callback_factory_.NewCallback( | 125 callback_factory_.NewCallback( |
126 &QuotaManagerTest::DidGetHostUsage)); | 126 &QuotaManagerTest::DidGetHostUsage)); |
127 } | 127 } |
128 | 128 |
129 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { | 129 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { |
130 quota_manager_->GetUsageAndQuota(origin, type, | 130 quota_manager_->GetUsageAndQuota(origin, type, |
131 callback_factory_.NewCallback( | 131 callback_factory_.NewCallback( |
132 &QuotaManagerTest::DidGetUsageAndQuotaAdditional)); | 132 &QuotaManagerTest::DidGetUsageAndQuotaAdditional)); |
133 } | 133 } |
134 | 134 |
135 void DeleteOriginData(QuotaClient* client, | 135 void DeleteOriginData(QuotaClient* client, |
kinuko
2011/05/18 04:45:12
Could we rename this to DeleteClientOriginData and
Dai Mikurube (NOT FULLTIME)
2011/05/18 05:08:00
Done.
| |
136 const GURL& origin, | 136 const GURL& origin, |
137 StorageType type) { | 137 StorageType type) { |
138 quota_status_ = kQuotaStatusUnknown; | 138 quota_status_ = kQuotaStatusUnknown; |
139 client->DeleteOriginData(origin, type, | 139 client->DeleteOriginData(origin, type, |
140 callback_factory_.NewCallback( | 140 callback_factory_.NewCallback( |
141 &QuotaManagerTest::DidDelete)); | 141 &QuotaManagerTest::DidDelete)); |
142 } | 142 } |
143 | 143 |
144 void EvictOriginData(const GURL& origin, | |
145 StorageType type) { | |
146 quota_status_ = kQuotaStatusUnknown; | |
147 quota_manager_->EvictOriginData(origin, type, | |
148 callback_factory_.NewCallback( | |
149 &QuotaManagerTest::DidEvict)); | |
150 } | |
151 | |
144 void GetAvailableSpace() { | 152 void GetAvailableSpace() { |
145 quota_status_ = kQuotaStatusUnknown; | 153 quota_status_ = kQuotaStatusUnknown; |
146 quota_ = -1; | 154 quota_ = -1; |
147 quota_manager_->GetAvailableSpace( | 155 quota_manager_->GetAvailableSpace( |
148 callback_factory_.NewCallback( | 156 callback_factory_.NewCallback( |
149 &QuotaManagerTest::DidGetQuota)); | 157 &QuotaManagerTest::DidGetQuota)); |
150 } | 158 } |
151 | 159 |
152 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 160 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
153 quota_status_ = status; | 161 quota_status_ = status; |
(...skipping 18 matching lines...) Expand all Loading... | |
172 } | 180 } |
173 | 181 |
174 void DidGetHostUsage(const std::string&, int64 usage) { | 182 void DidGetHostUsage(const std::string&, int64 usage) { |
175 usage_ = usage; | 183 usage_ = usage; |
176 } | 184 } |
177 | 185 |
178 void DidDelete(QuotaStatusCode status) { | 186 void DidDelete(QuotaStatusCode status) { |
179 quota_status_ = status; | 187 quota_status_ = status; |
180 } | 188 } |
181 | 189 |
190 void DidEvict(QuotaStatusCode status) { | |
191 quota_status_ = status; | |
192 } | |
193 | |
182 void set_additional_callback_count(int c) { additional_callback_count_ = c; } | 194 void set_additional_callback_count(int c) { additional_callback_count_ = c; } |
183 int additional_callback_count() const { return additional_callback_count_; } | 195 int additional_callback_count() const { return additional_callback_count_; } |
184 void DidGetUsageAndQuotaAdditional( | 196 void DidGetUsageAndQuotaAdditional( |
185 QuotaStatusCode status, int64 usage, int64 quota) { | 197 QuotaStatusCode status, int64 usage, int64 quota) { |
186 ++additional_callback_count_; | 198 ++additional_callback_count_; |
187 } | 199 } |
188 | 200 |
189 QuotaManager* quota_manager() const { return quota_manager_.get(); } | 201 QuotaManager* quota_manager() const { return quota_manager_.get(); } |
190 void set_quota_manager(QuotaManager* quota_manager) { | 202 void set_quota_manager(QuotaManager* quota_manager) { |
191 quota_manager_ = quota_manager; | 203 quota_manager_ = quota_manager; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 } | 741 } |
730 | 742 |
731 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { | 743 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { |
732 GetAvailableSpace(); | 744 GetAvailableSpace(); |
733 MessageLoop::current()->RunAllPending(); | 745 MessageLoop::current()->RunAllPending(); |
734 EXPECT_EQ(kQuotaStatusOk, status()); | 746 EXPECT_EQ(kQuotaStatusOk, status()); |
735 EXPECT_LE(0, quota()); | 747 EXPECT_LE(0, quota()); |
736 int64 direct_called = base::SysInfo::AmountOfFreeDiskSpace(profile_path()); | 748 int64 direct_called = base::SysInfo::AmountOfFreeDiskSpace(profile_path()); |
737 EXPECT_EQ(direct_called, quota()); | 749 EXPECT_EQ(direct_called, quota()); |
738 } | 750 } |
751 | |
752 TEST_F(QuotaManagerTest, EvictOriginData) { | |
753 static const MockOriginData kData1[] = { | |
754 { "http://foo.com/", kStorageTypeTemporary, 1 }, | |
755 { "http://foo.com:1/", kStorageTypeTemporary, 20 }, | |
756 { "http://foo.com/", kStorageTypePersistent, 300 }, | |
757 { "http://bar.com/", kStorageTypeTemporary, 4000 }, | |
758 }; | |
759 static const MockOriginData kData2[] = { | |
760 { "http://foo.com/", kStorageTypeTemporary, 50000 }, | |
761 { "http://foo.com:1/", kStorageTypeTemporary, 6000 }, | |
762 { "http://foo.com/", kStorageTypePersistent, 700 }, | |
763 { "https://foo.com/", kStorageTypeTemporary, 80 }, | |
764 { "http://bar.com/", kStorageTypeTemporary, 9 }, | |
765 }; | |
766 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1)); | |
767 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2)); | |
768 RegisterClient(client1); | |
769 RegisterClient(client2); | |
770 | |
771 GetGlobalUsage(kStorageTypeTemporary); | |
772 MessageLoop::current()->RunAllPending(); | |
773 int64 predelete_global_tmp = usage(); | |
774 | |
775 GetHostUsage("foo.com", kStorageTypeTemporary); | |
776 MessageLoop::current()->RunAllPending(); | |
777 int64 predelete_host_tmp = usage(); | |
778 | |
779 GetHostUsage("foo.com", kStorageTypePersistent); | |
780 MessageLoop::current()->RunAllPending(); | |
781 int64 predelete_host_pers = usage(); | |
782 | |
783 EvictOriginData(GURL("http://foo.com/"), kStorageTypeTemporary); | |
784 MessageLoop::current()->RunAllPending(); | |
785 | |
786 GetGlobalUsage(kStorageTypeTemporary); | |
787 MessageLoop::current()->RunAllPending(); | |
788 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage()); | |
789 | |
790 GetHostUsage("foo.com", kStorageTypeTemporary); | |
791 MessageLoop::current()->RunAllPending(); | |
792 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); | |
793 | |
794 GetHostUsage("foo.com", kStorageTypePersistent); | |
795 MessageLoop::current()->RunAllPending(); | |
796 EXPECT_EQ(predelete_host_pers, usage()); | |
797 } | |
798 | |
739 } // namespace quota | 799 } // namespace quota |
OLD | NEW |