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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 142 } |
143 | 143 |
144 void GetAvailableSpace() { | 144 void GetAvailableSpace() { |
145 quota_status_ = kQuotaStatusUnknown; | 145 quota_status_ = kQuotaStatusUnknown; |
146 quota_ = -1; | 146 quota_ = -1; |
147 quota_manager_->GetAvailableSpace( | 147 quota_manager_->GetAvailableSpace( |
148 callback_factory_.NewCallback( | 148 callback_factory_.NewCallback( |
149 &QuotaManagerTest::DidGetQuota)); | 149 &QuotaManagerTest::DidGetQuota)); |
150 } | 150 } |
151 | 151 |
152 void GetUsageAndQuotaForEviction() { | |
153 quota_status_ = kQuotaStatusUnknown; | |
154 usage_ = -1; | |
155 quota_ = -1; | |
156 available_space_ = -1; | |
157 quota_manager_->GetUsageAndQuotaForEviction( | |
158 callback_factory_.NewCallback( | |
159 &QuotaManagerTest::DidGetUsageAndQuotaForEviction)); | |
160 } | |
161 | |
152 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 162 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
153 quota_status_ = status; | 163 quota_status_ = status; |
154 usage_ = usage; | 164 usage_ = usage; |
155 quota_ = quota; | 165 quota_ = quota; |
156 } | 166 } |
157 | 167 |
158 void DidGetQuota(QuotaStatusCode status, int64 quota) { | 168 void DidGetQuota(QuotaStatusCode status, int64 quota) { |
159 quota_status_ = status; | 169 quota_status_ = status; |
160 quota_ = quota; | 170 quota_ = quota; |
161 } | 171 } |
162 | 172 |
163 void DidGetHostQuota(QuotaStatusCode status, | 173 void DidGetHostQuota(QuotaStatusCode status, |
164 const std::string& host, int64 quota) { | 174 const std::string& host, int64 quota) { |
165 quota_status_ = status; | 175 quota_status_ = status; |
166 host_ = host; | 176 host_ = host; |
167 quota_ = quota; | 177 quota_ = quota; |
168 } | 178 } |
169 | 179 |
170 void DidGetGlobalUsage(int64 usage) { | 180 void DidGetGlobalUsage(int64 usage) { |
171 usage_ = usage; | 181 usage_ = usage; |
172 } | 182 } |
173 | 183 |
174 void DidGetHostUsage(const std::string&, int64 usage) { | 184 void DidGetHostUsage(const std::string&, int64 usage) { |
175 usage_ = usage; | 185 usage_ = usage; |
176 } | 186 } |
177 | 187 |
188 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, | |
189 int64 usage, int64 quota, int64 available_space) { | |
190 quota_status_ = status; | |
191 usage_ = usage; | |
192 quota_ = quota; | |
193 available_space_ = available_space; | |
194 } | |
195 | |
178 void DidDelete(QuotaStatusCode status) { | 196 void DidDelete(QuotaStatusCode status) { |
179 quota_status_ = status; | 197 quota_status_ = status; |
180 } | 198 } |
181 | 199 |
182 void set_additional_callback_count(int c) { additional_callback_count_ = c; } | 200 void set_additional_callback_count(int c) { additional_callback_count_ = c; } |
183 int additional_callback_count() const { return additional_callback_count_; } | 201 int additional_callback_count() const { return additional_callback_count_; } |
184 void DidGetUsageAndQuotaAdditional( | 202 void DidGetUsageAndQuotaAdditional( |
185 QuotaStatusCode status, int64 usage, int64 quota) { | 203 QuotaStatusCode status, int64 usage, int64 quota) { |
186 ++additional_callback_count_; | 204 ++additional_callback_count_; |
187 } | 205 } |
188 | 206 |
189 QuotaManager* quota_manager() const { return quota_manager_.get(); } | 207 QuotaManager* quota_manager() const { return quota_manager_.get(); } |
190 void set_quota_manager(QuotaManager* quota_manager) { | 208 void set_quota_manager(QuotaManager* quota_manager) { |
191 quota_manager_ = quota_manager; | 209 quota_manager_ = quota_manager; |
192 } | 210 } |
193 | 211 |
194 QuotaStatusCode status() const { return quota_status_; } | 212 QuotaStatusCode status() const { return quota_status_; } |
195 int64 usage() const { return usage_; } | 213 int64 usage() const { return usage_; } |
196 int64 quota() const { return quota_; } | 214 int64 quota() const { return quota_; } |
215 int64 available_space() const { return available_space_; } | |
197 FilePath profile_path() const { return data_dir_.path(); } | 216 FilePath profile_path() const { return data_dir_.path(); } |
198 | 217 |
199 private: | 218 private: |
200 ScopedTempDir data_dir_; | 219 ScopedTempDir data_dir_; |
201 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; | 220 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; |
202 | 221 |
203 scoped_refptr<QuotaManager> quota_manager_; | 222 scoped_refptr<QuotaManager> quota_manager_; |
204 | 223 |
205 QuotaStatusCode quota_status_; | 224 QuotaStatusCode quota_status_; |
206 std::string host_; | 225 std::string host_; |
207 int64 usage_; | 226 int64 usage_; |
208 int64 quota_; | 227 int64 quota_; |
228 int64 available_space_; | |
209 | 229 |
210 int additional_callback_count_; | 230 int additional_callback_count_; |
211 | 231 |
212 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); | 232 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); |
213 }; | 233 }; |
214 | 234 |
215 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { | 235 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { |
216 static const MockOriginData kData[] = { | 236 static const MockOriginData kData[] = { |
217 { "http://foo.com/", kStorageTypeTemporary, 10 }, | 237 { "http://foo.com/", kStorageTypeTemporary, 10 }, |
218 { "http://foo.com/", kStorageTypePersistent, 80 }, | 238 { "http://foo.com/", kStorageTypePersistent, 80 }, |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 } | 749 } |
730 | 750 |
731 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { | 751 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { |
732 GetAvailableSpace(); | 752 GetAvailableSpace(); |
733 MessageLoop::current()->RunAllPending(); | 753 MessageLoop::current()->RunAllPending(); |
734 EXPECT_EQ(kQuotaStatusOk, status()); | 754 EXPECT_EQ(kQuotaStatusOk, status()); |
735 EXPECT_LE(0, quota()); | 755 EXPECT_LE(0, quota()); |
736 int64 direct_called = base::SysInfo::AmountOfFreeDiskSpace(profile_path()); | 756 int64 direct_called = base::SysInfo::AmountOfFreeDiskSpace(profile_path()); |
737 EXPECT_EQ(direct_called, quota()); | 757 EXPECT_EQ(direct_called, quota()); |
738 } | 758 } |
759 | |
760 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { | |
761 static const MockOriginData kData[] = { | |
762 { "http://foo.com/", kStorageTypeTemporary, 1 }, | |
763 { "http://foo.com:1/", kStorageTypeTemporary, 20 }, | |
764 { "http://foo.com/", kStorageTypePersistent, 300 }, | |
765 { "http://bar.com/", kStorageTypeTemporary, 4000 }, | |
766 }; | |
767 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData)); | |
768 RegisterClient(client); | |
769 | |
770 SetTemporaryGlobalQuota(10000000); | |
771 MessageLoop::current()->RunAllPending(); | |
772 | |
773 GetUsageAndQuotaForEviction(); | |
774 MessageLoop::current()->RunAllPending(); | |
775 EXPECT_EQ(kQuotaStatusOk, status()); | |
776 EXPECT_EQ(4021, usage()); | |
777 EXPECT_EQ(10000000, quota()); | |
778 | |
779 // TODO(dmikurube): It might be flaky? (Also in GetAvailableSpaceTest.) | |
kinuko
2011/05/18 10:02:45
Oh that is true. Sorry could you change this test
Dai Mikurube (NOT FULLTIME)
2011/05/18 11:35:25
Done for GetUsageAndQuotaForEviction with EXPECT_L
| |
780 int64 direct_called = base::SysInfo::AmountOfFreeDiskSpace(profile_path()); | |
781 EXPECT_EQ(direct_called, available_space()); | |
782 } | |
783 | |
739 } // namespace quota | 784 } // namespace quota |
OLD | NEW |