OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 26 matching lines...) Expand all Loading... |
37 using storage::kQuotaStatusOk; | 37 using storage::kQuotaStatusOk; |
38 using storage::kQuotaStatusUnknown; | 38 using storage::kQuotaStatusUnknown; |
39 using storage::kStorageTypePersistent; | 39 using storage::kStorageTypePersistent; |
40 using storage::kStorageTypeSyncable; | 40 using storage::kStorageTypeSyncable; |
41 using storage::kStorageTypeTemporary; | 41 using storage::kStorageTypeTemporary; |
42 using storage::kStorageTypeUnknown; | 42 using storage::kStorageTypeUnknown; |
43 using storage::QuotaClient; | 43 using storage::QuotaClient; |
44 using storage::QuotaManager; | 44 using storage::QuotaManager; |
45 using storage::QuotaStatusCode; | 45 using storage::QuotaStatusCode; |
46 using storage::StorageType; | 46 using storage::StorageType; |
| 47 using storage::UsageAndQuota; |
47 using storage::UsageInfo; | 48 using storage::UsageInfo; |
48 using storage::UsageInfoEntries; | 49 using storage::UsageInfoEntries; |
49 | 50 |
50 namespace content { | 51 namespace content { |
51 | 52 |
52 namespace { | 53 namespace { |
53 | 54 |
54 // For shorter names. | 55 // For shorter names. |
55 const StorageType kTemp = kStorageTypeTemporary; | 56 const StorageType kTemp = kStorageTypeTemporary; |
56 const StorageType kPerm = kStorageTypePersistent; | 57 const StorageType kPerm = kStorageTypePersistent; |
57 const StorageType kSync = kStorageTypeSyncable; | 58 const StorageType kSync = kStorageTypeSyncable; |
58 | 59 |
59 const int kAllClients = QuotaClient::kAllClientsMask; | 60 const int kAllClients = QuotaClient::kAllClientsMask; |
60 | 61 |
61 // Values in bytes. | |
62 const int64_t kAvailableSpaceForApp = 13377331U; | 62 const int64_t kAvailableSpaceForApp = 13377331U; |
63 const int64_t kMustRemainAvailableForSystem = kAvailableSpaceForApp / 2; | 63 |
64 const int64_t kDefaultPoolSize = 1000; | 64 const int64_t kMinimumPreserveForSystem = |
65 const int64_t kDefaultPerHostQuota = 200; | 65 QuotaManager::kMinimumPreserveForSystem; |
| 66 const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion; |
66 | 67 |
67 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); | 68 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); |
68 | 69 |
69 // Returns a deterministic value for the amount of available disk space. | 70 // Returns a deterministic value for the amount of available disk space. |
70 int64_t GetAvailableDiskSpaceForTest() { | 71 int64_t GetAvailableDiskSpaceForTest() { |
71 return kAvailableSpaceForApp + kMustRemainAvailableForSystem; | 72 return kAvailableSpaceForApp + kMinimumPreserveForSystem; |
72 } | 73 } |
73 | 74 |
74 std::pair<int64_t, int64_t> GetVolumeInfoForTests( | 75 bool GetVolumeInfoForTests(const base::FilePath&, |
75 const base::FilePath& unused) { | 76 uint64_t* available, uint64_t* total) { |
76 int64_t available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); | 77 *available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); |
77 int64_t total = available * 2; | 78 *total = *available * 2; |
78 return std::make_pair(total, available); | 79 return true; |
79 } | 80 } |
80 | 81 |
| 82 class TestEvictionPolicy : public storage::QuotaEvictionPolicy { |
| 83 public: |
| 84 TestEvictionPolicy() {} |
| 85 ~TestEvictionPolicy() override {} |
| 86 |
| 87 // Overridden from storage::QuotaEvictionPolicy: |
| 88 void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& |
| 89 special_storage_policy, |
| 90 const std::set<GURL>& exceptions, |
| 91 const std::map<GURL, int64_t>& usage_map, |
| 92 int64_t global_quota, |
| 93 const storage::GetOriginCallback& callback) override { |
| 94 callback.Run(kTestEvictionOrigin); |
| 95 } |
| 96 }; |
| 97 |
81 } // namespace | 98 } // namespace |
82 | 99 |
83 class QuotaManagerTest : public testing::Test { | 100 class QuotaManagerTest : public testing::Test { |
84 protected: | 101 protected: |
85 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; | 102 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; |
86 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; | 103 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; |
87 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; | 104 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; |
88 | 105 |
89 public: | 106 public: |
90 QuotaManagerTest() | 107 QuotaManagerTest() |
(...skipping 11 matching lines...) Expand all Loading... |
102 // Make sure the quota manager cleans up correctly. | 119 // Make sure the quota manager cleans up correctly. |
103 quota_manager_ = NULL; | 120 quota_manager_ = NULL; |
104 base::RunLoop().RunUntilIdle(); | 121 base::RunLoop().RunUntilIdle(); |
105 } | 122 } |
106 | 123 |
107 protected: | 124 protected: |
108 void ResetQuotaManager(bool is_incognito) { | 125 void ResetQuotaManager(bool is_incognito) { |
109 quota_manager_ = new QuotaManager(is_incognito, data_dir_.GetPath(), | 126 quota_manager_ = new QuotaManager(is_incognito, data_dir_.GetPath(), |
110 base::ThreadTaskRunnerHandle::Get().get(), | 127 base::ThreadTaskRunnerHandle::Get().get(), |
111 base::ThreadTaskRunnerHandle::Get().get(), | 128 base::ThreadTaskRunnerHandle::Get().get(), |
112 mock_special_storage_policy_.get(), | 129 mock_special_storage_policy_.get()); |
113 storage::GetQuotaSettingsFunc()); | |
114 SetQuotaSettings(kDefaultPoolSize, kDefaultPerHostQuota, | |
115 is_incognito ? INT64_C(0) : kMustRemainAvailableForSystem); | |
116 | |
117 // Don't (automatically) start the eviction for testing. | 130 // Don't (automatically) start the eviction for testing. |
118 quota_manager_->eviction_disabled_ = true; | 131 quota_manager_->eviction_disabled_ = true; |
119 // Don't query the hard disk for remaining capacity. | 132 // Don't query the hard disk for remaining capacity. |
120 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests; | 133 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests; |
121 additional_callback_count_ = 0; | 134 additional_callback_count_ = 0; |
122 } | 135 } |
123 | 136 |
124 MockStorageClient* CreateClient( | 137 MockStorageClient* CreateClient( |
125 const MockOriginData* mock_data, | 138 const MockOriginData* mock_data, |
126 size_t mock_data_size, | 139 size_t mock_data_size, |
(...skipping 26 matching lines...) Expand all Loading... |
153 void GetUsageAndQuotaForStorageClient(const GURL& origin, | 166 void GetUsageAndQuotaForStorageClient(const GURL& origin, |
154 StorageType type) { | 167 StorageType type) { |
155 quota_status_ = kQuotaStatusUnknown; | 168 quota_status_ = kQuotaStatusUnknown; |
156 usage_ = -1; | 169 usage_ = -1; |
157 quota_ = -1; | 170 quota_ = -1; |
158 quota_manager_->GetUsageAndQuota( | 171 quota_manager_->GetUsageAndQuota( |
159 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, | 172 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, |
160 weak_factory_.GetWeakPtr())); | 173 weak_factory_.GetWeakPtr())); |
161 } | 174 } |
162 | 175 |
163 void SetQuotaSettings(int64_t pool_size, | 176 void GetTemporaryGlobalQuota() { |
164 int64_t per_host_quota, | 177 quota_status_ = kQuotaStatusUnknown; |
165 int64_t must_remain_available) { | 178 quota_ = -1; |
166 storage::QuotaSettings settings; | 179 quota_manager_->GetTemporaryGlobalQuota( |
167 settings.pool_size = pool_size; | 180 base::Bind(&QuotaManagerTest::DidGetQuota, |
168 settings.per_host_quota = per_host_quota; | 181 weak_factory_.GetWeakPtr())); |
169 settings.must_remain_available = must_remain_available; | 182 } |
170 settings.refresh_interval = base::TimeDelta::Max(); | 183 |
171 quota_manager_->SetQuotaSettings(settings); | 184 void SetTemporaryGlobalQuota(int64_t new_quota) { |
| 185 quota_status_ = kQuotaStatusUnknown; |
| 186 quota_ = -1; |
| 187 quota_manager_->SetTemporaryGlobalOverrideQuota( |
| 188 new_quota, |
| 189 base::Bind(&QuotaManagerTest::DidGetQuota, |
| 190 weak_factory_.GetWeakPtr())); |
172 } | 191 } |
173 | 192 |
174 void GetPersistentHostQuota(const std::string& host) { | 193 void GetPersistentHostQuota(const std::string& host) { |
175 quota_status_ = kQuotaStatusUnknown; | 194 quota_status_ = kQuotaStatusUnknown; |
176 quota_ = -1; | 195 quota_ = -1; |
177 quota_manager_->GetPersistentHostQuota( | 196 quota_manager_->GetPersistentHostQuota( |
178 host, | 197 host, |
179 base::Bind(&QuotaManagerTest::DidGetHostQuota, | 198 base::Bind(&QuotaManagerTest::DidGetHostQuota, |
180 weak_factory_.GetWeakPtr())); | 199 weak_factory_.GetWeakPtr())); |
181 } | 200 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 void DeleteHostData(const std::string& host, | 265 void DeleteHostData(const std::string& host, |
247 StorageType type, | 266 StorageType type, |
248 int quota_client_mask) { | 267 int quota_client_mask) { |
249 quota_status_ = kQuotaStatusUnknown; | 268 quota_status_ = kQuotaStatusUnknown; |
250 quota_manager_->DeleteHostData( | 269 quota_manager_->DeleteHostData( |
251 host, type, quota_client_mask, | 270 host, type, quota_client_mask, |
252 base::Bind(&QuotaManagerTest::StatusCallback, | 271 base::Bind(&QuotaManagerTest::StatusCallback, |
253 weak_factory_.GetWeakPtr())); | 272 weak_factory_.GetWeakPtr())); |
254 } | 273 } |
255 | 274 |
256 void GetStorageCapacity() { | 275 void GetAvailableSpace() { |
| 276 quota_status_ = kQuotaStatusUnknown; |
257 available_space_ = -1; | 277 available_space_ = -1; |
258 total_space_ = -1; | 278 quota_manager_->GetAvailableSpace( |
259 quota_manager_->GetStorageCapacity(base::Bind( | 279 base::Bind(&QuotaManagerTest::DidGetAvailableSpace, |
260 &QuotaManagerTest::DidGetStorageCapacity, weak_factory_.GetWeakPtr())); | |
261 } | |
262 | |
263 void GetEvictionRoundInfo() { | |
264 quota_status_ = kQuotaStatusUnknown; | |
265 settings_ = storage::QuotaSettings(); | |
266 available_space_ = -1; | |
267 total_space_ = -1; | |
268 usage_ = -1; | |
269 quota_manager_->GetEvictionRoundInfo( | |
270 base::Bind(&QuotaManagerTest::DidGetEvictionRoundInfo, | |
271 weak_factory_.GetWeakPtr())); | 280 weak_factory_.GetWeakPtr())); |
272 } | 281 } |
273 | 282 |
| 283 void GetUsageAndQuotaForEviction() { |
| 284 quota_status_ = kQuotaStatusUnknown; |
| 285 usage_ = -1; |
| 286 unlimited_usage_ = -1; |
| 287 quota_ = -1; |
| 288 available_space_ = -1; |
| 289 quota_manager_->GetUsageAndQuotaForEviction( |
| 290 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction, |
| 291 weak_factory_.GetWeakPtr())); |
| 292 } |
| 293 |
274 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { | 294 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { |
275 ASSERT_TRUE(origins != NULL); | 295 ASSERT_TRUE(origins != NULL); |
276 origins->clear(); | 296 origins->clear(); |
277 quota_manager_->GetCachedOrigins(type, origins); | 297 quota_manager_->GetCachedOrigins(type, origins); |
278 } | 298 } |
279 | 299 |
| 300 bool GetVolumeInfo(const base::FilePath& path, |
| 301 uint64_t* available_space, |
| 302 uint64_t* total_size) { |
| 303 return QuotaManager::GetVolumeInfo(path, available_space, total_size); |
| 304 } |
| 305 |
280 void NotifyStorageAccessed(QuotaClient* client, | 306 void NotifyStorageAccessed(QuotaClient* client, |
281 const GURL& origin, | 307 const GURL& origin, |
282 StorageType type) { | 308 StorageType type) { |
283 DCHECK(client); | 309 DCHECK(client); |
284 quota_manager_->NotifyStorageAccessedInternal( | 310 quota_manager_->NotifyStorageAccessedInternal( |
285 client->id(), origin, type, IncrementMockTime()); | 311 client->id(), origin, type, IncrementMockTime()); |
286 } | 312 } |
287 | 313 |
288 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { | 314 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { |
289 quota_manager_->DeleteOriginFromDatabase(origin, type, false); | 315 quota_manager_->DeleteOriginFromDatabase(origin, type, false); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 quota_status_ = status; | 366 quota_status_ = status; |
341 usage_ = usage; | 367 usage_ = usage; |
342 quota_ = quota; | 368 quota_ = quota; |
343 } | 369 } |
344 | 370 |
345 void DidGetQuota(QuotaStatusCode status, int64_t quota) { | 371 void DidGetQuota(QuotaStatusCode status, int64_t quota) { |
346 quota_status_ = status; | 372 quota_status_ = status; |
347 quota_ = quota; | 373 quota_ = quota; |
348 } | 374 } |
349 | 375 |
350 void DidGetStorageCapacity(int64_t total_space, int64_t available_space) { | 376 void DidGetAvailableSpace(QuotaStatusCode status, int64_t available_space) { |
351 total_space_ = total_space; | 377 quota_status_ = status; |
352 available_space_ = available_space; | 378 available_space_ = available_space; |
353 } | 379 } |
354 | 380 |
355 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) { | 381 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) { |
356 quota_status_ = status; | 382 quota_status_ = status; |
357 quota_ = quota; | 383 quota_ = quota; |
358 } | 384 } |
359 | 385 |
360 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) { | 386 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) { |
361 usage_ = usage; | 387 usage_ = usage; |
362 unlimited_usage_ = unlimited_usage; | 388 unlimited_usage_ = unlimited_usage; |
363 } | 389 } |
364 | 390 |
365 void DidGetHostUsage(int64_t usage) { usage_ = usage; } | 391 void DidGetHostUsage(int64_t usage) { usage_ = usage; } |
366 | 392 |
367 void StatusCallback(QuotaStatusCode status) { | 393 void StatusCallback(QuotaStatusCode status) { |
368 ++status_callback_count_; | 394 ++status_callback_count_; |
369 quota_status_ = status; | 395 quota_status_ = status; |
370 } | 396 } |
371 | 397 |
372 void DidGetEvictionRoundInfo(QuotaStatusCode status, | 398 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, |
373 const storage::QuotaSettings& settings, | 399 const UsageAndQuota& usage_and_quota) { |
374 int64_t available_space, | |
375 int64_t total_space, | |
376 int64_t global_usage, | |
377 bool global_usage_is_complete) { | |
378 quota_status_ = status; | 400 quota_status_ = status; |
379 settings_ = settings; | 401 limited_usage_ = usage_and_quota.global_limited_usage; |
380 available_space_ = available_space; | 402 quota_ = usage_and_quota.quota; |
381 total_space_ = total_space; | 403 available_space_ = usage_and_quota.available_disk_space; |
382 usage_ = global_usage; | |
383 } | 404 } |
384 | 405 |
385 void DidGetEvictionOrigin(const GURL& origin) { | 406 void DidGetEvictionOrigin(const GURL& origin) { |
386 eviction_origin_ = origin; | 407 eviction_origin_ = origin; |
387 } | 408 } |
388 | 409 |
389 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { | 410 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { |
390 modified_origins_ = origins; | 411 modified_origins_ = origins; |
391 modified_origins_type_ = type; | 412 modified_origins_type_ = type; |
392 } | 413 } |
(...skipping 24 matching lines...) Expand all Loading... |
417 MockSpecialStoragePolicy* mock_special_storage_policy() const { | 438 MockSpecialStoragePolicy* mock_special_storage_policy() const { |
418 return mock_special_storage_policy_.get(); | 439 return mock_special_storage_policy_.get(); |
419 } | 440 } |
420 | 441 |
421 QuotaStatusCode status() const { return quota_status_; } | 442 QuotaStatusCode status() const { return quota_status_; } |
422 const UsageInfoEntries& usage_info() const { return usage_info_; } | 443 const UsageInfoEntries& usage_info() const { return usage_info_; } |
423 int64_t usage() const { return usage_; } | 444 int64_t usage() const { return usage_; } |
424 int64_t limited_usage() const { return limited_usage_; } | 445 int64_t limited_usage() const { return limited_usage_; } |
425 int64_t unlimited_usage() const { return unlimited_usage_; } | 446 int64_t unlimited_usage() const { return unlimited_usage_; } |
426 int64_t quota() const { return quota_; } | 447 int64_t quota() const { return quota_; } |
427 int64_t total_space() const { return total_space_; } | |
428 int64_t available_space() const { return available_space_; } | 448 int64_t available_space() const { return available_space_; } |
429 const GURL& eviction_origin() const { return eviction_origin_; } | 449 const GURL& eviction_origin() const { return eviction_origin_; } |
430 const std::set<GURL>& modified_origins() const { return modified_origins_; } | 450 const std::set<GURL>& modified_origins() const { return modified_origins_; } |
431 StorageType modified_origins_type() const { return modified_origins_type_; } | 451 StorageType modified_origins_type() const { return modified_origins_type_; } |
432 const QuotaTableEntries& quota_entries() const { return quota_entries_; } | 452 const QuotaTableEntries& quota_entries() const { return quota_entries_; } |
433 const OriginInfoTableEntries& origin_info_entries() const { | 453 const OriginInfoTableEntries& origin_info_entries() const { |
434 return origin_info_entries_; | 454 return origin_info_entries_; |
435 } | 455 } |
436 const storage::QuotaSettings& settings() const { return settings_; } | |
437 base::FilePath profile_path() const { return data_dir_.GetPath(); } | 456 base::FilePath profile_path() const { return data_dir_.GetPath(); } |
438 int status_callback_count() const { return status_callback_count_; } | 457 int status_callback_count() const { return status_callback_count_; } |
439 void reset_status_callback_count() { status_callback_count_ = 0; } | 458 void reset_status_callback_count() { status_callback_count_ = 0; } |
440 | 459 |
441 private: | 460 private: |
442 base::Time IncrementMockTime() { | 461 base::Time IncrementMockTime() { |
443 ++mock_time_counter_; | 462 ++mock_time_counter_; |
444 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); | 463 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); |
445 } | 464 } |
446 | 465 |
447 base::MessageLoop message_loop_; | 466 base::MessageLoop message_loop_; |
448 base::ScopedTempDir data_dir_; | 467 base::ScopedTempDir data_dir_; |
449 | 468 |
450 scoped_refptr<QuotaManager> quota_manager_; | 469 scoped_refptr<QuotaManager> quota_manager_; |
451 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; | 470 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; |
452 | 471 |
453 QuotaStatusCode quota_status_; | 472 QuotaStatusCode quota_status_; |
454 UsageInfoEntries usage_info_; | 473 UsageInfoEntries usage_info_; |
455 int64_t usage_; | 474 int64_t usage_; |
456 int64_t limited_usage_; | 475 int64_t limited_usage_; |
457 int64_t unlimited_usage_; | 476 int64_t unlimited_usage_; |
458 int64_t quota_; | 477 int64_t quota_; |
459 int64_t total_space_; | |
460 int64_t available_space_; | 478 int64_t available_space_; |
461 GURL eviction_origin_; | 479 GURL eviction_origin_; |
462 std::set<GURL> modified_origins_; | 480 std::set<GURL> modified_origins_; |
463 StorageType modified_origins_type_; | 481 StorageType modified_origins_type_; |
464 QuotaTableEntries quota_entries_; | 482 QuotaTableEntries quota_entries_; |
465 OriginInfoTableEntries origin_info_entries_; | 483 OriginInfoTableEntries origin_info_entries_; |
466 storage::QuotaSettings settings_; | |
467 int status_callback_count_; | 484 int status_callback_count_; |
468 | 485 |
469 int additional_callback_count_; | 486 int additional_callback_count_; |
470 | 487 |
471 int mock_time_counter_; | 488 int mock_time_counter_; |
472 | 489 |
473 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; | 490 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; |
474 | 491 |
475 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); | 492 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); |
476 }; | 493 }; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 { "http://foo.com:8080/", kTemp, 20 }, | 626 { "http://foo.com:8080/", kTemp, 20 }, |
610 { "http://bar.com/", kTemp, 5 }, | 627 { "http://bar.com/", kTemp, 5 }, |
611 { "https://bar.com/", kTemp, 7 }, | 628 { "https://bar.com/", kTemp, 7 }, |
612 { "http://baz.com/", kTemp, 30 }, | 629 { "http://baz.com/", kTemp, 30 }, |
613 { "http://foo.com/", kPerm, 40 }, | 630 { "http://foo.com/", kPerm, 40 }, |
614 }; | 631 }; |
615 RegisterClient(CreateClient(kData, arraysize(kData), | 632 RegisterClient(CreateClient(kData, arraysize(kData), |
616 QuotaClient::kFileSystem)); | 633 QuotaClient::kFileSystem)); |
617 | 634 |
618 // This time explicitly sets a temporary global quota. | 635 // This time explicitly sets a temporary global quota. |
619 const int kPoolSize = 100; | 636 SetTemporaryGlobalQuota(100); |
620 const int kPerHostQuota = 20; | 637 base::RunLoop().RunUntilIdle(); |
621 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | 638 EXPECT_EQ(kQuotaStatusOk, status()); |
| 639 EXPECT_EQ(100, quota()); |
622 | 640 |
623 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 641 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
624 base::RunLoop().RunUntilIdle(); | 642 base::RunLoop().RunUntilIdle(); |
625 EXPECT_EQ(kQuotaStatusOk, status()); | 643 EXPECT_EQ(kQuotaStatusOk, status()); |
626 EXPECT_EQ(10 + 20, usage()); | 644 EXPECT_EQ(10 + 20, usage()); |
627 | 645 |
| 646 const int kPerHostQuota = 100 / kPerHostTemporaryPortion; |
| 647 |
628 // The host's quota should be its full portion of the global quota | 648 // The host's quota should be its full portion of the global quota |
629 // since there's plenty of diskspace. | 649 // since global usage is under the global quota. |
630 EXPECT_EQ(kPerHostQuota, quota()); | 650 EXPECT_EQ(kPerHostQuota, quota()); |
631 | 651 |
632 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); | 652 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); |
633 base::RunLoop().RunUntilIdle(); | 653 base::RunLoop().RunUntilIdle(); |
634 EXPECT_EQ(kQuotaStatusOk, status()); | 654 EXPECT_EQ(kQuotaStatusOk, status()); |
635 EXPECT_EQ(5 + 7, usage()); | 655 EXPECT_EQ(5 + 7, usage()); |
636 EXPECT_EQ(kPerHostQuota, quota()); | 656 EXPECT_EQ(kPerHostQuota, quota()); |
637 } | 657 } |
638 | 658 |
639 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { | 659 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { |
640 static const MockOriginData kData1[] = { | 660 static const MockOriginData kData1[] = { |
641 { "http://foo.com/", kTemp, 1 }, | 661 { "http://foo.com/", kTemp, 1 }, |
642 { "http://bar.com/", kTemp, 2 }, | 662 { "http://bar.com/", kTemp, 2 }, |
643 { "http://bar.com/", kPerm, 4 }, | 663 { "http://bar.com/", kPerm, 4 }, |
644 { "http://unlimited/", kPerm, 8 }, | 664 { "http://unlimited/", kPerm, 8 }, |
| 665 { "http://installed/", kPerm, 16 }, |
645 }; | 666 }; |
646 static const MockOriginData kData2[] = { | 667 static const MockOriginData kData2[] = { |
647 { "https://foo.com/", kTemp, 128 }, | 668 { "https://foo.com/", kTemp, 128 }, |
648 { "http://example.com/", kPerm, 256 }, | 669 { "http://example.com/", kPerm, 256 }, |
649 { "http://unlimited/", kTemp, 512 }, | 670 { "http://unlimited/", kTemp, 512 }, |
| 671 { "http://installed/", kTemp, 1024 }, |
650 }; | 672 }; |
651 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 673 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
| 674 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
652 RegisterClient(CreateClient(kData1, arraysize(kData1), | 675 RegisterClient(CreateClient(kData1, arraysize(kData1), |
653 QuotaClient::kFileSystem)); | 676 QuotaClient::kFileSystem)); |
654 RegisterClient(CreateClient(kData2, arraysize(kData2), | 677 RegisterClient(CreateClient(kData2, arraysize(kData2), |
655 QuotaClient::kDatabase)); | 678 QuotaClient::kDatabase)); |
656 | 679 |
657 const int64_t kPoolSize = GetAvailableDiskSpaceForTest(); | 680 const int64_t kTempQuotaBase = |
658 const int64_t kPerHostQuota = kPoolSize / 5; | 681 GetAvailableDiskSpaceForTest() / kPerHostTemporaryPortion; |
659 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
660 | 682 |
661 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 683 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
662 base::RunLoop().RunUntilIdle(); | 684 base::RunLoop().RunUntilIdle(); |
663 EXPECT_EQ(kQuotaStatusOk, status()); | 685 EXPECT_EQ(kQuotaStatusOk, status()); |
664 EXPECT_EQ(1 + 128, usage()); | 686 EXPECT_EQ(1 + 128, usage()); |
665 EXPECT_EQ(kPerHostQuota, quota()); | |
666 | 687 |
667 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm); | 688 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm); |
668 base::RunLoop().RunUntilIdle(); | 689 base::RunLoop().RunUntilIdle(); |
669 EXPECT_EQ(kQuotaStatusOk, status()); | 690 EXPECT_EQ(kQuotaStatusOk, status()); |
670 EXPECT_EQ(4, usage()); | 691 EXPECT_EQ(4, usage()); |
671 EXPECT_EQ(0, quota()); | |
672 | 692 |
673 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 693 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
674 base::RunLoop().RunUntilIdle(); | 694 base::RunLoop().RunUntilIdle(); |
675 EXPECT_EQ(kQuotaStatusOk, status()); | 695 EXPECT_EQ(kQuotaStatusOk, status()); |
676 EXPECT_EQ(512, usage()); | 696 EXPECT_EQ(512, usage()); |
677 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | 697 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota()); |
678 | 698 |
679 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); | 699 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); |
680 base::RunLoop().RunUntilIdle(); | 700 base::RunLoop().RunUntilIdle(); |
681 EXPECT_EQ(kQuotaStatusOk, status()); | 701 EXPECT_EQ(kQuotaStatusOk, status()); |
682 EXPECT_EQ(8, usage()); | 702 EXPECT_EQ(8, usage()); |
683 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | 703 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); |
684 | 704 |
| 705 GetAvailableSpace(); |
| 706 base::RunLoop().RunUntilIdle(); |
| 707 EXPECT_EQ(kQuotaStatusOk, status()); |
| 708 EXPECT_LE(0, available_space()); |
| 709 |
| 710 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kTemp); |
| 711 base::RunLoop().RunUntilIdle(); |
| 712 EXPECT_EQ(kQuotaStatusOk, status()); |
| 713 EXPECT_EQ(1024, usage()); |
| 714 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota()); |
| 715 |
| 716 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); |
| 717 base::RunLoop().RunUntilIdle(); |
| 718 EXPECT_EQ(kQuotaStatusOk, status()); |
| 719 EXPECT_EQ(16, usage()); |
| 720 EXPECT_EQ(usage(), quota()); // Over-budget case. |
| 721 |
685 GetGlobalUsage(kTemp); | 722 GetGlobalUsage(kTemp); |
686 base::RunLoop().RunUntilIdle(); | 723 base::RunLoop().RunUntilIdle(); |
687 EXPECT_EQ(kQuotaStatusOk, status()); | 724 EXPECT_EQ(kQuotaStatusOk, status()); |
688 EXPECT_EQ(1 + 2 + 128 + 512, usage()); | 725 EXPECT_EQ(1 + 2 + 128 + 512 + 1024, usage()); |
689 EXPECT_EQ(512, unlimited_usage()); | 726 EXPECT_EQ(512, unlimited_usage()); |
690 | 727 |
691 GetGlobalUsage(kPerm); | 728 GetGlobalUsage(kPerm); |
692 base::RunLoop().RunUntilIdle(); | 729 base::RunLoop().RunUntilIdle(); |
693 EXPECT_EQ(kQuotaStatusOk, status()); | 730 EXPECT_EQ(kQuotaStatusOk, status()); |
694 EXPECT_EQ(4 + 8 + 256, usage()); | 731 EXPECT_EQ(4 + 8 + 16 + 256, usage()); |
695 EXPECT_EQ(8, unlimited_usage()); | 732 EXPECT_EQ(8, unlimited_usage()); |
696 } | 733 } |
697 | 734 |
698 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { | 735 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { |
699 const MockOriginData data[] = { | 736 const MockOriginData data[] = { |
700 { "http://foo.com/", type, 10 }, | 737 { "http://foo.com/", type, 10 }, |
701 { "http://foo.com:1/", type, 20 }, | 738 { "http://foo.com:1/", type, 20 }, |
702 }; | 739 }; |
703 MockStorageClient* client = CreateClient(data, arraysize(data), | 740 MockStorageClient* client = CreateClient(data, arraysize(data), |
704 QuotaClient::kFileSystem); | 741 QuotaClient::kFileSystem); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 | 774 |
738 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { | 775 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { |
739 static const MockOriginData kData[] = { | 776 static const MockOriginData kData[] = { |
740 { "http://foo.com/", kTemp, 10 }, | 777 { "http://foo.com/", kTemp, 10 }, |
741 { "http://foo.com:8080/", kTemp, 20 }, | 778 { "http://foo.com:8080/", kTemp, 20 }, |
742 { "http://bar.com/", kTemp, 13 }, | 779 { "http://bar.com/", kTemp, 13 }, |
743 { "http://foo.com/", kPerm, 40 }, | 780 { "http://foo.com/", kPerm, 40 }, |
744 }; | 781 }; |
745 RegisterClient(CreateClient(kData, arraysize(kData), | 782 RegisterClient(CreateClient(kData, arraysize(kData), |
746 QuotaClient::kFileSystem)); | 783 QuotaClient::kFileSystem)); |
| 784 SetTemporaryGlobalQuota(100); |
| 785 base::RunLoop().RunUntilIdle(); |
747 | 786 |
748 const int kPoolSize = 100; | 787 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; |
749 const int kPerHostQuota = 20; | |
750 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
751 | 788 |
752 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 789 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
753 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 790 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
754 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 791 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
755 base::RunLoop().RunUntilIdle(); | 792 base::RunLoop().RunUntilIdle(); |
756 EXPECT_EQ(kQuotaStatusOk, status()); | 793 EXPECT_EQ(kQuotaStatusOk, status()); |
757 EXPECT_EQ(10 + 20, usage()); | 794 EXPECT_EQ(10 + 20, usage()); |
758 EXPECT_EQ(kPerHostQuota, quota()); | 795 EXPECT_EQ(kPerHostQuota, quota()); |
759 | 796 |
760 set_additional_callback_count(0); | 797 set_additional_callback_count(0); |
(...skipping 10 matching lines...) Expand all Loading... |
771 | 808 |
772 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { | 809 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { |
773 static const MockOriginData kData[] = { | 810 static const MockOriginData kData[] = { |
774 { "http://foo.com/", kTemp, 10 }, | 811 { "http://foo.com/", kTemp, 10 }, |
775 { "http://foo.com:8080/", kTemp, 20 }, | 812 { "http://foo.com:8080/", kTemp, 20 }, |
776 { "http://bar.com/", kTemp, 13 }, | 813 { "http://bar.com/", kTemp, 13 }, |
777 { "http://foo.com/", kPerm, 40 }, | 814 { "http://foo.com/", kPerm, 40 }, |
778 }; | 815 }; |
779 RegisterClient(CreateClient(kData, arraysize(kData), | 816 RegisterClient(CreateClient(kData, arraysize(kData), |
780 QuotaClient::kFileSystem)); | 817 QuotaClient::kFileSystem)); |
781 const int kPoolSize = 100; | 818 SetTemporaryGlobalQuota(100); |
782 const int kPerHostQuota = 20; | 819 base::RunLoop().RunUntilIdle(); |
783 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
784 | 820 |
785 set_additional_callback_count(0); | 821 set_additional_callback_count(0); |
786 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 822 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
787 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 823 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
788 kTemp); | 824 kTemp); |
789 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | 825 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), |
790 kTemp); | 826 kTemp); |
791 | 827 |
792 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | 828 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); |
793 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); | 829 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); |
794 | 830 |
795 // Nuke before waiting for callbacks. | 831 // Nuke before waiting for callbacks. |
796 set_quota_manager(NULL); | 832 set_quota_manager(NULL); |
797 base::RunLoop().RunUntilIdle(); | 833 base::RunLoop().RunUntilIdle(); |
798 EXPECT_EQ(kQuotaErrorAbort, status()); | 834 EXPECT_EQ(kQuotaErrorAbort, status()); |
799 } | 835 } |
800 | 836 |
801 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { | 837 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { |
802 static const MockOriginData kData[] = { | 838 static const MockOriginData kData[] = { |
803 { "http://usage1/", kTemp, 1 }, | 839 { "http://usage1/", kTemp, 1 }, |
804 { "http://usage10/", kTemp, 10 }, | 840 { "http://usage10/", kTemp, 10 }, |
805 { "http://usage200/", kTemp, 200 }, | 841 { "http://usage200/", kTemp, 200 }, |
806 }; | 842 }; |
807 RegisterClient(CreateClient(kData, arraysize(kData), | 843 RegisterClient(CreateClient(kData, arraysize(kData), |
808 QuotaClient::kFileSystem)); | 844 QuotaClient::kFileSystem)); |
809 const int kPoolSize = 100; | 845 SetTemporaryGlobalQuota(100); |
810 const int kPerHostQuota = 20; | 846 base::RunLoop().RunUntilIdle(); |
811 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
812 | 847 |
813 // Provided diskspace is not tight, global usage does not affect the | 848 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; |
814 // quota calculations for an individual origin, so despite global usage | |
815 // in excess of our poolsize, we still get the nominal quota value. | |
816 GetStorageCapacity(); | |
817 base::RunLoop().RunUntilIdle(); | |
818 EXPECT_LE(kMustRemainAvailableForSystem, available_space()); | |
819 | 849 |
820 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); | 850 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); |
821 base::RunLoop().RunUntilIdle(); | 851 base::RunLoop().RunUntilIdle(); |
822 EXPECT_EQ(kQuotaStatusOk, status()); | 852 EXPECT_EQ(kQuotaStatusOk, status()); |
823 EXPECT_EQ(1, usage()); | 853 EXPECT_EQ(1, usage()); |
824 EXPECT_EQ(kPerHostQuota, quota()); | 854 EXPECT_EQ(1, quota()); // should be clamped to our current usage |
825 | 855 |
826 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 856 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
827 base::RunLoop().RunUntilIdle(); | 857 base::RunLoop().RunUntilIdle(); |
828 EXPECT_EQ(kQuotaStatusOk, status()); | 858 EXPECT_EQ(kQuotaStatusOk, status()); |
829 EXPECT_EQ(10, usage()); | 859 EXPECT_EQ(10, usage()); |
830 EXPECT_EQ(kPerHostQuota, quota()); | 860 EXPECT_EQ(10, quota()); |
831 | 861 |
832 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); | 862 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); |
833 base::RunLoop().RunUntilIdle(); | 863 base::RunLoop().RunUntilIdle(); |
834 EXPECT_EQ(kQuotaStatusOk, status()); | 864 EXPECT_EQ(kQuotaStatusOk, status()); |
835 EXPECT_EQ(200, usage()); | 865 EXPECT_EQ(200, usage()); |
836 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota | 866 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota |
837 } | 867 } |
838 | 868 |
839 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { | 869 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { |
840 static const MockOriginData kData[] = { | 870 static const MockOriginData kData[] = { |
841 { "http://usage10/", kTemp, 10 }, | 871 { "http://usage10/", kTemp, 10 }, |
842 { "http://usage50/", kTemp, 50 }, | 872 { "http://usage50/", kTemp, 50 }, |
843 { "http://unlimited/", kTemp, 4000 }, | 873 { "http://unlimited/", kTemp, 4000 }, |
844 }; | 874 }; |
845 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 875 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
846 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 876 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
847 QuotaClient::kFileSystem); | 877 QuotaClient::kFileSystem); |
848 RegisterClient(client); | 878 RegisterClient(client); |
849 | 879 |
850 // Test when not overbugdet. | 880 // Test when not overbugdet. |
851 const int kPerHostQuotaFor1000 = 200; | 881 SetTemporaryGlobalQuota(1000); |
852 SetQuotaSettings(1000, kPerHostQuotaFor1000, kMustRemainAvailableForSystem); | 882 base::RunLoop().RunUntilIdle(); |
853 | 883 |
854 GetGlobalUsage(kTemp); | 884 GetGlobalUsage(kTemp); |
855 base::RunLoop().RunUntilIdle(); | 885 base::RunLoop().RunUntilIdle(); |
856 EXPECT_EQ(10 + 50 + 4000, usage()); | 886 EXPECT_EQ(10 + 50 + 4000, usage()); |
857 EXPECT_EQ(4000, unlimited_usage()); | 887 EXPECT_EQ(4000, unlimited_usage()); |
858 | 888 |
| 889 const int kPerHostQuotaFor1000 = |
| 890 1000 / QuotaManager::kPerHostTemporaryPortion; |
| 891 |
859 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 892 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
860 base::RunLoop().RunUntilIdle(); | 893 base::RunLoop().RunUntilIdle(); |
861 EXPECT_EQ(kQuotaStatusOk, status()); | 894 EXPECT_EQ(kQuotaStatusOk, status()); |
862 EXPECT_EQ(10, usage()); | 895 EXPECT_EQ(10, usage()); |
863 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 896 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
864 | 897 |
865 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 898 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
866 base::RunLoop().RunUntilIdle(); | 899 base::RunLoop().RunUntilIdle(); |
867 EXPECT_EQ(kQuotaStatusOk, status()); | 900 EXPECT_EQ(kQuotaStatusOk, status()); |
868 EXPECT_EQ(50, usage()); | 901 EXPECT_EQ(50, usage()); |
869 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 902 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
870 | 903 |
871 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 904 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
872 base::RunLoop().RunUntilIdle(); | 905 base::RunLoop().RunUntilIdle(); |
873 EXPECT_EQ(kQuotaStatusOk, status()); | 906 EXPECT_EQ(kQuotaStatusOk, status()); |
874 EXPECT_EQ(4000, usage()); | 907 EXPECT_EQ(4000, usage()); |
875 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | 908 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); |
876 | 909 |
877 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); | 910 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); |
878 base::RunLoop().RunUntilIdle(); | 911 base::RunLoop().RunUntilIdle(); |
879 EXPECT_EQ(kQuotaStatusOk, status()); | 912 EXPECT_EQ(kQuotaStatusOk, status()); |
880 EXPECT_EQ(0, usage()); | 913 EXPECT_EQ(0, usage()); |
881 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 914 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
882 | 915 |
883 // Test when overbugdet. | 916 // Test when overbugdet. |
884 const int kPerHostQuotaFor100 = 20; | 917 SetTemporaryGlobalQuota(100); |
885 SetQuotaSettings(100, kPerHostQuotaFor100, kMustRemainAvailableForSystem); | 918 base::RunLoop().RunUntilIdle(); |
| 919 |
| 920 const int kPerHostQuotaFor100 = |
| 921 100 / QuotaManager::kPerHostTemporaryPortion; |
886 | 922 |
887 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 923 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
888 base::RunLoop().RunUntilIdle(); | 924 base::RunLoop().RunUntilIdle(); |
889 EXPECT_EQ(kQuotaStatusOk, status()); | 925 EXPECT_EQ(kQuotaStatusOk, status()); |
890 EXPECT_EQ(10, usage()); | 926 EXPECT_EQ(10, usage()); |
891 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 927 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
892 | 928 |
893 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 929 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
894 base::RunLoop().RunUntilIdle(); | 930 base::RunLoop().RunUntilIdle(); |
895 EXPECT_EQ(kQuotaStatusOk, status()); | 931 EXPECT_EQ(kQuotaStatusOk, status()); |
(...skipping 18 matching lines...) Expand all Loading... |
914 | 950 |
915 GetGlobalUsage(kTemp); | 951 GetGlobalUsage(kTemp); |
916 base::RunLoop().RunUntilIdle(); | 952 base::RunLoop().RunUntilIdle(); |
917 EXPECT_EQ(10 + 50 + 4000, usage()); | 953 EXPECT_EQ(10 + 50 + 4000, usage()); |
918 EXPECT_EQ(0, unlimited_usage()); | 954 EXPECT_EQ(0, unlimited_usage()); |
919 | 955 |
920 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 956 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
921 base::RunLoop().RunUntilIdle(); | 957 base::RunLoop().RunUntilIdle(); |
922 EXPECT_EQ(kQuotaStatusOk, status()); | 958 EXPECT_EQ(kQuotaStatusOk, status()); |
923 EXPECT_EQ(10, usage()); | 959 EXPECT_EQ(10, usage()); |
924 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 960 EXPECT_EQ(10, quota()); // should be clamped to our current usage |
925 | 961 |
926 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 962 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
927 base::RunLoop().RunUntilIdle(); | 963 base::RunLoop().RunUntilIdle(); |
928 EXPECT_EQ(kQuotaStatusOk, status()); | 964 EXPECT_EQ(kQuotaStatusOk, status()); |
929 EXPECT_EQ(50, usage()); | 965 EXPECT_EQ(50, usage()); |
930 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 966 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
931 | 967 |
932 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 968 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
933 base::RunLoop().RunUntilIdle(); | 969 base::RunLoop().RunUntilIdle(); |
934 EXPECT_EQ(kQuotaStatusOk, status()); | 970 EXPECT_EQ(kQuotaStatusOk, status()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 EXPECT_EQ(0, usage()); | 1036 EXPECT_EQ(0, usage()); |
1001 EXPECT_EQ(0, quota()); | 1037 EXPECT_EQ(0, quota()); |
1002 | 1038 |
1003 SetPersistentHostQuota("foo.com", 100); | 1039 SetPersistentHostQuota("foo.com", 100); |
1004 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 1040 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
1005 base::RunLoop().RunUntilIdle(); | 1041 base::RunLoop().RunUntilIdle(); |
1006 EXPECT_EQ(kQuotaStatusOk, status()); | 1042 EXPECT_EQ(kQuotaStatusOk, status()); |
1007 EXPECT_EQ(0, usage()); | 1043 EXPECT_EQ(0, usage()); |
1008 EXPECT_EQ(100, quota()); | 1044 EXPECT_EQ(100, quota()); |
1009 | 1045 |
1010 // The actual space avaialble is given to 'unlimited' origins as their quota. | 1046 // For installed app GetUsageAndQuotaForWebApps returns the capped quota. |
| 1047 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
| 1048 SetPersistentHostQuota("installed", kAvailableSpaceForApp + 100); |
| 1049 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); |
| 1050 base::RunLoop().RunUntilIdle(); |
| 1051 EXPECT_EQ(kAvailableSpaceForApp, quota()); |
| 1052 |
| 1053 // Ditto for unlimited apps. |
1011 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 1054 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
1012 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); | 1055 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); |
1013 base::RunLoop().RunUntilIdle(); | 1056 base::RunLoop().RunUntilIdle(); |
1014 EXPECT_EQ(kAvailableSpaceForApp, quota()); | 1057 EXPECT_EQ(kAvailableSpaceForApp, quota()); |
1015 | 1058 |
1016 // GetUsageAndQuotaForStorageClient should just return 0 usage and | 1059 // GetUsageAndQuotaForStorageClient should just return 0 usage and |
1017 // kNoLimit quota. | 1060 // kNoLimit quota. |
1018 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kPerm); | 1061 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kPerm); |
1019 base::RunLoop().RunUntilIdle(); | 1062 base::RunLoop().RunUntilIdle(); |
1020 EXPECT_EQ(0, usage()); | 1063 EXPECT_EQ(0, usage()); |
1021 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 1064 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
1022 } | 1065 } |
1023 | 1066 |
1024 TEST_F(QuotaManagerTest, GetSyncableQuota) { | 1067 TEST_F(QuotaManagerTest, GetSyncableQuota) { |
1025 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | 1068 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); |
1026 | 1069 |
1027 // Pre-condition check: available disk space (for testing) is less than | 1070 // Pre-condition check: available disk space (for testing) is less than |
1028 // the default quota for syncable storage. | 1071 // the default quota for syncable storage. |
1029 EXPECT_LE(kAvailableSpaceForApp, | 1072 EXPECT_LE(kAvailableSpaceForApp, |
1030 QuotaManager::kSyncableStorageDefaultHostQuota); | 1073 QuotaManager::kSyncableStorageDefaultHostQuota); |
1031 | 1074 |
1032 // For unlimited origins the quota manager should return | 1075 // For installed apps the quota manager should return |
1033 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). | 1076 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). |
1034 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 1077 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
1035 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kSync); | 1078 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kSync); |
1036 base::RunLoop().RunUntilIdle(); | 1079 base::RunLoop().RunUntilIdle(); |
1037 EXPECT_EQ(kQuotaStatusOk, status()); | 1080 EXPECT_EQ(kQuotaStatusOk, status()); |
1038 EXPECT_EQ(0, usage()); | 1081 EXPECT_EQ(0, usage()); |
1039 EXPECT_EQ(kAvailableSpaceForApp, quota()); | 1082 EXPECT_EQ(kAvailableSpaceForApp, quota()); |
| 1083 |
| 1084 // If it's not installed (which shouldn't happen in real case) it |
| 1085 // should just return the default host quota for syncable. |
| 1086 GetUsageAndQuotaForWebApps(GURL("http://foo/"), kSync); |
| 1087 base::RunLoop().RunUntilIdle(); |
| 1088 EXPECT_EQ(kQuotaStatusOk, status()); |
| 1089 EXPECT_EQ(0, usage()); |
| 1090 EXPECT_EQ(QuotaManager::kSyncableStorageDefaultHostQuota, quota()); |
1040 } | 1091 } |
1041 | 1092 |
1042 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { | 1093 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { |
1043 static const MockOriginData kData[] = { | 1094 static const MockOriginData kData[] = { |
1044 { "http://foo.com/", kPerm, 10 }, | 1095 { "http://foo.com/", kPerm, 10 }, |
1045 { "http://foo.com:8080/", kPerm, 20 }, | 1096 { "http://foo.com:8080/", kPerm, 20 }, |
1046 { "https://foo.com/", kPerm, 13 }, | 1097 { "https://foo.com/", kPerm, 13 }, |
1047 { "https://foo.com:8081/", kPerm, 19 }, | 1098 { "https://foo.com:8081/", kPerm, 19 }, |
1048 { "http://bar.com/", kPerm, 5 }, | 1099 { "http://bar.com/", kPerm, 5 }, |
1049 { "https://bar.com/", kPerm, 7 }, | 1100 { "https://bar.com/", kPerm, 7 }, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 | 1287 |
1237 GetHostUsage("foo.com", kTemp); | 1288 GetHostUsage("foo.com", kTemp); |
1238 base::RunLoop().RunUntilIdle(); | 1289 base::RunLoop().RunUntilIdle(); |
1239 EXPECT_EQ(predelete_host_tmp - 1, usage()); | 1290 EXPECT_EQ(predelete_host_tmp - 1, usage()); |
1240 | 1291 |
1241 GetHostUsage("foo.com", kPerm); | 1292 GetHostUsage("foo.com", kPerm); |
1242 base::RunLoop().RunUntilIdle(); | 1293 base::RunLoop().RunUntilIdle(); |
1243 EXPECT_EQ(predelete_host_pers, usage()); | 1294 EXPECT_EQ(predelete_host_pers, usage()); |
1244 } | 1295 } |
1245 | 1296 |
1246 TEST_F(QuotaManagerTest, GetStorageCapacity) { | 1297 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { |
1247 GetStorageCapacity(); | 1298 GetAvailableSpace(); |
1248 base::RunLoop().RunUntilIdle(); | 1299 base::RunLoop().RunUntilIdle(); |
1249 EXPECT_LE(0, total_space()); | 1300 EXPECT_EQ(kQuotaStatusOk, status()); |
1250 EXPECT_LE(0, available_space()); | 1301 EXPECT_LE(0, available_space()); |
1251 } | 1302 } |
1252 | 1303 |
| 1304 TEST_F(QuotaManagerTest, SetTemporaryStorageEvictionPolicy) { |
| 1305 quota_manager()->SetTemporaryStorageEvictionPolicy( |
| 1306 base::WrapUnique(new TestEvictionPolicy)); |
| 1307 |
| 1308 GetEvictionOrigin(kTemp); |
| 1309 base::RunLoop().RunUntilIdle(); |
| 1310 EXPECT_EQ(kTestEvictionOrigin, eviction_origin()); |
| 1311 } |
| 1312 |
1253 TEST_F(QuotaManagerTest, EvictOriginData) { | 1313 TEST_F(QuotaManagerTest, EvictOriginData) { |
1254 static const MockOriginData kData1[] = { | 1314 static const MockOriginData kData1[] = { |
1255 { "http://foo.com/", kTemp, 1 }, | 1315 { "http://foo.com/", kTemp, 1 }, |
1256 { "http://foo.com:1/", kTemp, 20 }, | 1316 { "http://foo.com:1/", kTemp, 20 }, |
1257 { "http://foo.com/", kPerm, 300 }, | 1317 { "http://foo.com/", kPerm, 300 }, |
1258 { "http://bar.com/", kTemp, 4000 }, | 1318 { "http://bar.com/", kTemp, 4000 }, |
1259 }; | 1319 }; |
1260 static const MockOriginData kData2[] = { | 1320 static const MockOriginData kData2[] = { |
1261 { "http://foo.com/", kTemp, 50000 }, | 1321 { "http://foo.com/", kTemp, 50000 }, |
1262 { "http://foo.com:1/", kTemp, 6000 }, | 1322 { "http://foo.com:1/", kTemp, 6000 }, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 | 1521 |
1462 GetHostUsage("foo.com", kTemp); | 1522 GetHostUsage("foo.com", kTemp); |
1463 base::RunLoop().RunUntilIdle(); | 1523 base::RunLoop().RunUntilIdle(); |
1464 EXPECT_EQ(predelete_host_tmp, usage()); | 1524 EXPECT_EQ(predelete_host_tmp, usage()); |
1465 | 1525 |
1466 GetHostUsage("foo.com", kPerm); | 1526 GetHostUsage("foo.com", kPerm); |
1467 base::RunLoop().RunUntilIdle(); | 1527 base::RunLoop().RunUntilIdle(); |
1468 EXPECT_EQ(predelete_host_pers, usage()); | 1528 EXPECT_EQ(predelete_host_pers, usage()); |
1469 } | 1529 } |
1470 | 1530 |
1471 TEST_F(QuotaManagerTest, GetEvictionRoundInfo) { | 1531 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { |
1472 static const MockOriginData kData[] = { | 1532 static const MockOriginData kData[] = { |
1473 { "http://foo.com/", kTemp, 1 }, | 1533 { "http://foo.com/", kTemp, 1 }, |
1474 { "http://foo.com:1/", kTemp, 20 }, | 1534 { "http://foo.com:1/", kTemp, 20 }, |
1475 { "http://foo.com/", kPerm, 300 }, | 1535 { "http://foo.com/", kPerm, 300 }, |
1476 { "http://unlimited/", kTemp, 4000 }, | 1536 { "http://unlimited/", kTemp, 4000 }, |
1477 }; | 1537 }; |
1478 | 1538 |
1479 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 1539 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
1480 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1540 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1481 QuotaClient::kFileSystem); | 1541 QuotaClient::kFileSystem); |
1482 RegisterClient(client); | 1542 RegisterClient(client); |
1483 | 1543 |
1484 const int kPoolSize = 10000000; | 1544 SetTemporaryGlobalQuota(10000000); |
1485 const int kPerHostQuota = kPoolSize / 5; | 1545 base::RunLoop().RunUntilIdle(); |
1486 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
1487 | 1546 |
1488 GetEvictionRoundInfo(); | 1547 GetUsageAndQuotaForEviction(); |
1489 base::RunLoop().RunUntilIdle(); | 1548 base::RunLoop().RunUntilIdle(); |
1490 EXPECT_EQ(kQuotaStatusOk, status()); | 1549 EXPECT_EQ(kQuotaStatusOk, status()); |
1491 EXPECT_EQ(21, usage()); | 1550 EXPECT_EQ(21, limited_usage()); |
1492 EXPECT_EQ(kPoolSize, settings().pool_size); | 1551 EXPECT_EQ(10000000, quota()); |
1493 EXPECT_LE(0, available_space()); | 1552 EXPECT_LE(0, available_space()); |
1494 } | 1553 } |
1495 | 1554 |
1496 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { | 1555 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { |
1497 static const MockOriginData kData[] = { | 1556 static const MockOriginData kData[] = { |
1498 { "http://foo.com/", kTemp, 1 }, | 1557 { "http://foo.com/", kTemp, 1 }, |
1499 }; | 1558 }; |
1500 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1559 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1501 QuotaClient::kFileSystem); | 1560 QuotaClient::kFileSystem); |
1502 RegisterClient(client); | 1561 RegisterClient(client); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1794 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1736 QuotaClient::kFileSystem); | 1795 QuotaClient::kFileSystem); |
1737 RegisterClient(client); | 1796 RegisterClient(client); |
1738 | 1797 |
1739 // TODO(kinuko): Be careful when we add cache pruner. | 1798 // TODO(kinuko): Be careful when we add cache pruner. |
1740 | 1799 |
1741 std::set<GURL> origins; | 1800 std::set<GURL> origins; |
1742 GetCachedOrigins(kTemp, &origins); | 1801 GetCachedOrigins(kTemp, &origins); |
1743 EXPECT_TRUE(origins.empty()); | 1802 EXPECT_TRUE(origins.empty()); |
1744 | 1803 |
| 1804 // No matter how we make queries the quota manager tries to cache all |
| 1805 // the origins at startup. |
1745 GetHostUsage("a.com", kTemp); | 1806 GetHostUsage("a.com", kTemp); |
1746 base::RunLoop().RunUntilIdle(); | 1807 base::RunLoop().RunUntilIdle(); |
1747 GetCachedOrigins(kTemp, &origins); | 1808 GetCachedOrigins(kTemp, &origins); |
1748 EXPECT_EQ(2U, origins.size()); | 1809 EXPECT_EQ(3U, origins.size()); |
1749 | 1810 |
1750 GetHostUsage("b.com", kTemp); | 1811 GetHostUsage("b.com", kTemp); |
1751 base::RunLoop().RunUntilIdle(); | 1812 base::RunLoop().RunUntilIdle(); |
1752 GetCachedOrigins(kTemp, &origins); | 1813 GetCachedOrigins(kTemp, &origins); |
1753 EXPECT_EQ(2U, origins.size()); | |
1754 | |
1755 GetHostUsage("c.com", kTemp); | |
1756 base::RunLoop().RunUntilIdle(); | |
1757 GetCachedOrigins(kTemp, &origins); | |
1758 EXPECT_EQ(3U, origins.size()); | 1814 EXPECT_EQ(3U, origins.size()); |
1759 | 1815 |
1760 GetCachedOrigins(kPerm, &origins); | 1816 GetCachedOrigins(kPerm, &origins); |
1761 EXPECT_TRUE(origins.empty()); | 1817 EXPECT_TRUE(origins.empty()); |
1762 | 1818 |
1763 GetGlobalUsage(kTemp); | 1819 GetGlobalUsage(kTemp); |
1764 base::RunLoop().RunUntilIdle(); | 1820 base::RunLoop().RunUntilIdle(); |
1765 GetCachedOrigins(kTemp, &origins); | 1821 GetCachedOrigins(kTemp, &origins); |
1766 EXPECT_EQ(3U, origins.size()); | 1822 EXPECT_EQ(3U, origins.size()); |
1767 | 1823 |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) { | 2260 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) { |
2205 ResetQuotaManager(true); | 2261 ResetQuotaManager(true); |
2206 | 2262 |
2207 static const MockOriginData kData[] = { | 2263 static const MockOriginData kData[] = { |
2208 { "http://foo.com/", kTemp, 10 }, | 2264 { "http://foo.com/", kTemp, 10 }, |
2209 { "http://foo.com/", kPerm, 80 }, | 2265 { "http://foo.com/", kPerm, 80 }, |
2210 }; | 2266 }; |
2211 RegisterClient(CreateClient(kData, arraysize(kData), | 2267 RegisterClient(CreateClient(kData, arraysize(kData), |
2212 QuotaClient::kFileSystem)); | 2268 QuotaClient::kFileSystem)); |
2213 | 2269 |
2214 // Query global usage to warmup the usage tracker caching. | |
2215 GetGlobalUsage(kTemp); | |
2216 GetGlobalUsage(kPerm); | |
2217 base::RunLoop().RunUntilIdle(); | |
2218 | |
2219 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 2270 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
2220 base::RunLoop().RunUntilIdle(); | 2271 base::RunLoop().RunUntilIdle(); |
2221 EXPECT_EQ(kQuotaStatusOk, status()); | 2272 EXPECT_EQ(kQuotaStatusOk, status()); |
2222 EXPECT_EQ(80, usage()); | 2273 EXPECT_EQ(80, usage()); |
2223 EXPECT_EQ(0, quota()); | 2274 EXPECT_EQ(0, quota()); |
2224 | 2275 |
2225 const int kPoolSize = 1000; | 2276 SetTemporaryGlobalQuota(100); |
2226 const int kPerHostQuota = kPoolSize / 5; | |
2227 SetQuotaSettings(kPoolSize, kPerHostQuota, INT64_C(0)); | |
2228 | |
2229 GetStorageCapacity(); | |
2230 base::RunLoop().RunUntilIdle(); | |
2231 EXPECT_EQ(kPoolSize, total_space()); | |
2232 EXPECT_EQ(kPoolSize - 80 - 10, available_space()); | |
2233 | |
2234 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2277 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
2235 base::RunLoop().RunUntilIdle(); | 2278 base::RunLoop().RunUntilIdle(); |
2236 EXPECT_EQ(kQuotaStatusOk, status()); | 2279 EXPECT_EQ(kQuotaStatusOk, status()); |
2237 EXPECT_EQ(10, usage()); | 2280 EXPECT_EQ(10, usage()); |
2238 EXPECT_LE(kPerHostQuota, quota()); | 2281 EXPECT_LE(std::min(static_cast<int64_t>(100 / kPerHostTemporaryPortion), |
| 2282 QuotaManager::kIncognitoDefaultQuotaLimit), |
| 2283 quota()); |
2239 | 2284 |
2240 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); | 2285 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); |
2241 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 2286 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
2242 base::RunLoop().RunUntilIdle(); | 2287 base::RunLoop().RunUntilIdle(); |
2243 EXPECT_EQ(kQuotaStatusOk, status()); | 2288 EXPECT_EQ(kQuotaStatusOk, status()); |
2244 EXPECT_EQ(80, usage()); | 2289 EXPECT_EQ(80, usage()); |
2245 EXPECT_EQ(available_space() + usage(), quota()); | 2290 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
2246 | 2291 |
2247 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2292 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
2248 base::RunLoop().RunUntilIdle(); | 2293 base::RunLoop().RunUntilIdle(); |
2249 EXPECT_EQ(kQuotaStatusOk, status()); | 2294 EXPECT_EQ(kQuotaStatusOk, status()); |
2250 EXPECT_EQ(10, usage()); | 2295 EXPECT_EQ(10, usage()); |
2251 EXPECT_EQ(available_space() + usage(), quota()); | 2296 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2297 } |
| 2298 |
| 2299 TEST_F(QuotaManagerTest, GetVolumeInfo) { |
| 2300 // We aren't actually testing that it's correct, just that it's sane. |
| 2301 base::FilePath tmp_dir; |
| 2302 ASSERT_TRUE(base::GetTempDir(&tmp_dir)); |
| 2303 uint64_t available_space = 0; |
| 2304 uint64_t total_size = 0; |
| 2305 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size)); |
| 2306 EXPECT_GT(available_space, 0u) << tmp_dir.value(); |
| 2307 EXPECT_GT(total_size, 0u) << tmp_dir.value(); |
2252 } | 2308 } |
2253 | 2309 |
2254 } // namespace content | 2310 } // namespace content |
OLD | NEW |