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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 void EvictOriginData(const GURL& origin, | 144 void EvictOriginData(const GURL& origin, |
145 StorageType type) { | 145 StorageType type) { |
146 quota_status_ = kQuotaStatusUnknown; | 146 quota_status_ = kQuotaStatusUnknown; |
147 quota_manager_->EvictOriginData(origin, type, | 147 quota_manager_->EvictOriginData(origin, type, |
148 callback_factory_.NewCallback( | 148 callback_factory_.NewCallback( |
149 &QuotaManagerTest::DidEvictOriginData)); | 149 &QuotaManagerTest::DidEvictOriginData)); |
150 } | 150 } |
151 | 151 |
152 void GetAvailableSpace() { | 152 void GetAvailableSpace() { |
153 quota_status_ = kQuotaStatusUnknown; | 153 quota_status_ = kQuotaStatusUnknown; |
154 quota_ = -1; | 154 available_space_ = -1; |
155 quota_manager_->GetAvailableSpace( | 155 quota_manager_->GetAvailableSpace( |
156 callback_factory_.NewCallback( | 156 callback_factory_.NewCallback( |
157 &QuotaManagerTest::DidGetQuota)); | 157 &QuotaManagerTest::DidGetAvailableSpace)); |
| 158 } |
| 159 |
| 160 void GetUsageAndQuotaForEviction() { |
| 161 quota_status_ = kQuotaStatusUnknown; |
| 162 usage_ = -1; |
| 163 quota_ = -1; |
| 164 available_space_ = -1; |
| 165 quota_manager_->GetUsageAndQuotaForEviction( |
| 166 callback_factory_.NewCallback( |
| 167 &QuotaManagerTest::DidGetUsageAndQuotaForEviction)); |
158 } | 168 } |
159 | 169 |
160 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 170 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
161 quota_status_ = status; | 171 quota_status_ = status; |
162 usage_ = usage; | 172 usage_ = usage; |
163 quota_ = quota; | 173 quota_ = quota; |
164 } | 174 } |
165 | 175 |
166 void DidGetQuota(QuotaStatusCode status, int64 quota) { | 176 void DidGetQuota(QuotaStatusCode status, int64 quota) { |
167 quota_status_ = status; | 177 quota_status_ = status; |
168 quota_ = quota; | 178 quota_ = quota; |
169 } | 179 } |
170 | 180 |
| 181 void DidGetAvailableSpace(QuotaStatusCode status, int64 available_space) { |
| 182 quota_status_ = status; |
| 183 available_space_ = available_space; |
| 184 } |
| 185 |
171 void DidGetHostQuota(QuotaStatusCode status, | 186 void DidGetHostQuota(QuotaStatusCode status, |
172 const std::string& host, int64 quota) { | 187 const std::string& host, int64 quota) { |
173 quota_status_ = status; | 188 quota_status_ = status; |
174 host_ = host; | 189 host_ = host; |
175 quota_ = quota; | 190 quota_ = quota; |
176 } | 191 } |
177 | 192 |
178 void DidGetGlobalUsage(int64 usage) { | 193 void DidGetGlobalUsage(int64 usage) { |
179 usage_ = usage; | 194 usage_ = usage; |
180 } | 195 } |
181 | 196 |
182 void DidGetHostUsage(const std::string&, int64 usage) { | 197 void DidGetHostUsage(const std::string&, int64 usage) { |
183 usage_ = usage; | 198 usage_ = usage; |
184 } | 199 } |
185 | 200 |
186 void DidDeleteClientOriginData(QuotaStatusCode status) { | 201 void DidDeleteClientOriginData(QuotaStatusCode status) { |
187 quota_status_ = status; | 202 quota_status_ = status; |
188 } | 203 } |
189 | 204 |
190 void DidEvictOriginData(QuotaStatusCode status) { | 205 void DidEvictOriginData(QuotaStatusCode status) { |
191 quota_status_ = status; | 206 quota_status_ = status; |
192 } | 207 } |
193 | 208 |
| 209 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, |
| 210 int64 usage, int64 quota, int64 available_space) { |
| 211 quota_status_ = status; |
| 212 usage_ = usage; |
| 213 quota_ = quota; |
| 214 available_space_ = available_space; |
| 215 } |
| 216 |
194 void set_additional_callback_count(int c) { additional_callback_count_ = c; } | 217 void set_additional_callback_count(int c) { additional_callback_count_ = c; } |
195 int additional_callback_count() const { return additional_callback_count_; } | 218 int additional_callback_count() const { return additional_callback_count_; } |
196 void DidGetUsageAndQuotaAdditional( | 219 void DidGetUsageAndQuotaAdditional( |
197 QuotaStatusCode status, int64 usage, int64 quota) { | 220 QuotaStatusCode status, int64 usage, int64 quota) { |
198 ++additional_callback_count_; | 221 ++additional_callback_count_; |
199 } | 222 } |
200 | 223 |
201 QuotaManager* quota_manager() const { return quota_manager_.get(); } | 224 QuotaManager* quota_manager() const { return quota_manager_.get(); } |
202 void set_quota_manager(QuotaManager* quota_manager) { | 225 void set_quota_manager(QuotaManager* quota_manager) { |
203 quota_manager_ = quota_manager; | 226 quota_manager_ = quota_manager; |
204 } | 227 } |
205 | 228 |
206 QuotaStatusCode status() const { return quota_status_; } | 229 QuotaStatusCode status() const { return quota_status_; } |
207 int64 usage() const { return usage_; } | 230 int64 usage() const { return usage_; } |
208 int64 quota() const { return quota_; } | 231 int64 quota() const { return quota_; } |
| 232 int64 available_space() const { return available_space_; } |
209 FilePath profile_path() const { return data_dir_.path(); } | 233 FilePath profile_path() const { return data_dir_.path(); } |
210 | 234 |
211 private: | 235 private: |
212 ScopedTempDir data_dir_; | 236 ScopedTempDir data_dir_; |
213 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; | 237 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; |
214 | 238 |
215 scoped_refptr<QuotaManager> quota_manager_; | 239 scoped_refptr<QuotaManager> quota_manager_; |
216 | 240 |
217 QuotaStatusCode quota_status_; | 241 QuotaStatusCode quota_status_; |
218 std::string host_; | 242 std::string host_; |
219 int64 usage_; | 243 int64 usage_; |
220 int64 quota_; | 244 int64 quota_; |
| 245 int64 available_space_; |
221 | 246 |
222 int additional_callback_count_; | 247 int additional_callback_count_; |
223 | 248 |
224 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); | 249 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); |
225 }; | 250 }; |
226 | 251 |
227 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { | 252 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { |
228 static const MockOriginData kData[] = { | 253 static const MockOriginData kData[] = { |
229 { "http://foo.com/", kStorageTypeTemporary, 10 }, | 254 { "http://foo.com/", kStorageTypeTemporary, 10 }, |
230 { "http://foo.com/", kStorageTypePersistent, 80 }, | 255 { "http://foo.com/", kStorageTypePersistent, 80 }, |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 763 |
739 GetHostUsage("foo.com", kStorageTypePersistent); | 764 GetHostUsage("foo.com", kStorageTypePersistent); |
740 MessageLoop::current()->RunAllPending(); | 765 MessageLoop::current()->RunAllPending(); |
741 EXPECT_EQ(predelete_host_pers, usage()); | 766 EXPECT_EQ(predelete_host_pers, usage()); |
742 } | 767 } |
743 | 768 |
744 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { | 769 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { |
745 GetAvailableSpace(); | 770 GetAvailableSpace(); |
746 MessageLoop::current()->RunAllPending(); | 771 MessageLoop::current()->RunAllPending(); |
747 EXPECT_EQ(kQuotaStatusOk, status()); | 772 EXPECT_EQ(kQuotaStatusOk, status()); |
748 EXPECT_LE(0, quota()); | 773 EXPECT_LE(0, available_space()); |
749 int64 direct_called = base::SysInfo::AmountOfFreeDiskSpace(profile_path()); | |
750 EXPECT_EQ(direct_called, quota()); | |
751 } | 774 } |
752 | 775 |
753 TEST_F(QuotaManagerTest, EvictOriginData) { | 776 TEST_F(QuotaManagerTest, EvictOriginData) { |
754 static const MockOriginData kData1[] = { | 777 static const MockOriginData kData1[] = { |
755 { "http://foo.com/", kStorageTypeTemporary, 1 }, | 778 { "http://foo.com/", kStorageTypeTemporary, 1 }, |
756 { "http://foo.com:1/", kStorageTypeTemporary, 20 }, | 779 { "http://foo.com:1/", kStorageTypeTemporary, 20 }, |
757 { "http://foo.com/", kStorageTypePersistent, 300 }, | 780 { "http://foo.com/", kStorageTypePersistent, 300 }, |
758 { "http://bar.com/", kStorageTypeTemporary, 4000 }, | 781 { "http://bar.com/", kStorageTypeTemporary, 4000 }, |
759 }; | 782 }; |
760 static const MockOriginData kData2[] = { | 783 static const MockOriginData kData2[] = { |
(...skipping 29 matching lines...) Expand all Loading... |
790 | 813 |
791 GetHostUsage("foo.com", kStorageTypeTemporary); | 814 GetHostUsage("foo.com", kStorageTypeTemporary); |
792 MessageLoop::current()->RunAllPending(); | 815 MessageLoop::current()->RunAllPending(); |
793 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); | 816 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); |
794 | 817 |
795 GetHostUsage("foo.com", kStorageTypePersistent); | 818 GetHostUsage("foo.com", kStorageTypePersistent); |
796 MessageLoop::current()->RunAllPending(); | 819 MessageLoop::current()->RunAllPending(); |
797 EXPECT_EQ(predelete_host_pers, usage()); | 820 EXPECT_EQ(predelete_host_pers, usage()); |
798 } | 821 } |
799 | 822 |
| 823 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { |
| 824 static const MockOriginData kData[] = { |
| 825 { "http://foo.com/", kStorageTypeTemporary, 1 }, |
| 826 { "http://foo.com:1/", kStorageTypeTemporary, 20 }, |
| 827 { "http://foo.com/", kStorageTypePersistent, 300 }, |
| 828 { "http://bar.com/", kStorageTypeTemporary, 4000 }, |
| 829 }; |
| 830 |
| 831 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData)); |
| 832 RegisterClient(client); |
| 833 |
| 834 SetTemporaryGlobalQuota(10000000); |
| 835 MessageLoop::current()->RunAllPending(); |
| 836 |
| 837 GetUsageAndQuotaForEviction(); |
| 838 MessageLoop::current()->RunAllPending(); |
| 839 EXPECT_EQ(kQuotaStatusOk, status()); |
| 840 EXPECT_EQ(4021, usage()); |
| 841 EXPECT_EQ(10000000, quota()); |
| 842 EXPECT_LE(0, available_space()); |
| 843 } |
| 844 |
800 } // namespace quota | 845 } // namespace quota |
OLD | NEW |