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; | |
48 using storage::UsageInfo; | 47 using storage::UsageInfo; |
49 using storage::UsageInfoEntries; | 48 using storage::UsageInfoEntries; |
50 | 49 |
51 namespace content { | 50 namespace content { |
52 | 51 |
53 namespace { | 52 namespace { |
54 | 53 |
55 // For shorter names. | 54 // For shorter names. |
56 const StorageType kTemp = kStorageTypeTemporary; | 55 const StorageType kTemp = kStorageTypeTemporary; |
57 const StorageType kPerm = kStorageTypePersistent; | 56 const StorageType kPerm = kStorageTypePersistent; |
58 const StorageType kSync = kStorageTypeSyncable; | 57 const StorageType kSync = kStorageTypeSyncable; |
59 | 58 |
60 const int kAllClients = QuotaClient::kAllClientsMask; | 59 const int kAllClients = QuotaClient::kAllClientsMask; |
61 | 60 |
| 61 // Values in bytes. |
62 const int64_t kAvailableSpaceForApp = 13377331U; | 62 const int64_t kAvailableSpaceForApp = 13377331U; |
63 | 63 const int64_t kMustRemainAvailableForSystem = kAvailableSpaceForApp / 2; |
64 const int64_t kMinimumPreserveForSystem = | 64 const int64_t kDefaultPoolSize = 1000; |
65 QuotaManager::kMinimumPreserveForSystem; | 65 const int64_t kDefaultPerHostQuota = 200; |
66 const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion; | |
67 | 66 |
68 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); | 67 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); |
69 | 68 |
70 // Returns a deterministic value for the amount of available disk space. | 69 // Returns a deterministic value for the amount of available disk space. |
71 int64_t GetAvailableDiskSpaceForTest() { | 70 int64_t GetAvailableDiskSpaceForTest() { |
72 return kAvailableSpaceForApp + kMinimumPreserveForSystem; | 71 return kAvailableSpaceForApp + kMustRemainAvailableForSystem; |
73 } | 72 } |
74 | 73 |
75 bool GetVolumeInfoForTests(const base::FilePath&, | 74 // base::Optional<> todo? |
76 uint64_t* available, uint64_t* total) { | 75 std::pair<int64_t, int64_t> GetVolumeInfoForTests( |
77 *available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); | 76 const base::FilePath& unused) { |
78 *total = *available * 2; | 77 int64_t available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); |
79 return true; | 78 int64_t total = available * 2; |
| 79 return std::make_pair(total, available); |
80 } | 80 } |
81 | 81 |
82 class TestEvictionPolicy : public storage::QuotaEvictionPolicy { | 82 class TestEvictionPolicy : public storage::QuotaEvictionPolicy { |
83 public: | 83 public: |
84 TestEvictionPolicy() {} | 84 TestEvictionPolicy() {} |
85 ~TestEvictionPolicy() override {} | 85 ~TestEvictionPolicy() override {} |
86 | 86 |
87 // Overridden from storage::QuotaEvictionPolicy: | 87 // Overridden from storage::QuotaEvictionPolicy: |
88 void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& | 88 void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& |
89 special_storage_policy, | 89 special_storage_policy, |
(...skipping 29 matching lines...) Expand all Loading... |
119 // Make sure the quota manager cleans up correctly. | 119 // Make sure the quota manager cleans up correctly. |
120 quota_manager_ = NULL; | 120 quota_manager_ = NULL; |
121 base::RunLoop().RunUntilIdle(); | 121 base::RunLoop().RunUntilIdle(); |
122 } | 122 } |
123 | 123 |
124 protected: | 124 protected: |
125 void ResetQuotaManager(bool is_incognito) { | 125 void ResetQuotaManager(bool is_incognito) { |
126 quota_manager_ = new QuotaManager(is_incognito, data_dir_.GetPath(), | 126 quota_manager_ = new QuotaManager(is_incognito, data_dir_.GetPath(), |
127 base::ThreadTaskRunnerHandle::Get().get(), | 127 base::ThreadTaskRunnerHandle::Get().get(), |
128 base::ThreadTaskRunnerHandle::Get().get(), | 128 base::ThreadTaskRunnerHandle::Get().get(), |
129 mock_special_storage_policy_.get()); | 129 mock_special_storage_policy_.get(), |
| 130 storage::GetQuotaSettingsFunc()); |
| 131 SetQuotaSettings(kDefaultPoolSize, kDefaultPerHostQuota, |
| 132 is_incognito ? INT64_C(0) : kMustRemainAvailableForSystem); |
| 133 |
130 // Don't (automatically) start the eviction for testing. | 134 // Don't (automatically) start the eviction for testing. |
131 quota_manager_->eviction_disabled_ = true; | 135 quota_manager_->eviction_disabled_ = true; |
132 // Don't query the hard disk for remaining capacity. | 136 // Don't query the hard disk for remaining capacity. |
133 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests; | 137 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests; |
134 additional_callback_count_ = 0; | 138 additional_callback_count_ = 0; |
135 } | 139 } |
136 | 140 |
137 MockStorageClient* CreateClient( | 141 MockStorageClient* CreateClient( |
138 const MockOriginData* mock_data, | 142 const MockOriginData* mock_data, |
139 size_t mock_data_size, | 143 size_t mock_data_size, |
(...skipping 26 matching lines...) Expand all Loading... |
166 void GetUsageAndQuotaForStorageClient(const GURL& origin, | 170 void GetUsageAndQuotaForStorageClient(const GURL& origin, |
167 StorageType type) { | 171 StorageType type) { |
168 quota_status_ = kQuotaStatusUnknown; | 172 quota_status_ = kQuotaStatusUnknown; |
169 usage_ = -1; | 173 usage_ = -1; |
170 quota_ = -1; | 174 quota_ = -1; |
171 quota_manager_->GetUsageAndQuota( | 175 quota_manager_->GetUsageAndQuota( |
172 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, | 176 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, |
173 weak_factory_.GetWeakPtr())); | 177 weak_factory_.GetWeakPtr())); |
174 } | 178 } |
175 | 179 |
176 void GetTemporaryGlobalQuota() { | 180 void SetQuotaSettings(int64_t pool_size, |
177 quota_status_ = kQuotaStatusUnknown; | 181 int64_t per_host_quota, |
178 quota_ = -1; | 182 int64_t must_remain_available) { |
179 quota_manager_->GetTemporaryGlobalQuota( | 183 storage::QuotaSettings settings; |
180 base::Bind(&QuotaManagerTest::DidGetQuota, | 184 settings.pool_size = pool_size; |
181 weak_factory_.GetWeakPtr())); | 185 settings.per_host_quota = per_host_quota; |
182 } | 186 settings.must_remain_available = must_remain_available; |
183 | 187 settings.refresh_interval = base::TimeDelta::Max(); |
184 void SetTemporaryGlobalQuota(int64_t new_quota) { | 188 quota_manager_->SetQuotaSettings(settings); |
185 quota_status_ = kQuotaStatusUnknown; | |
186 quota_ = -1; | |
187 quota_manager_->SetTemporaryGlobalOverrideQuota( | |
188 new_quota, | |
189 base::Bind(&QuotaManagerTest::DidGetQuota, | |
190 weak_factory_.GetWeakPtr())); | |
191 } | 189 } |
192 | 190 |
193 void GetPersistentHostQuota(const std::string& host) { | 191 void GetPersistentHostQuota(const std::string& host) { |
194 quota_status_ = kQuotaStatusUnknown; | 192 quota_status_ = kQuotaStatusUnknown; |
195 quota_ = -1; | 193 quota_ = -1; |
196 quota_manager_->GetPersistentHostQuota( | 194 quota_manager_->GetPersistentHostQuota( |
197 host, | 195 host, |
198 base::Bind(&QuotaManagerTest::DidGetHostQuota, | 196 base::Bind(&QuotaManagerTest::DidGetHostQuota, |
199 weak_factory_.GetWeakPtr())); | 197 weak_factory_.GetWeakPtr())); |
200 } | 198 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 void DeleteHostData(const std::string& host, | 263 void DeleteHostData(const std::string& host, |
266 StorageType type, | 264 StorageType type, |
267 int quota_client_mask) { | 265 int quota_client_mask) { |
268 quota_status_ = kQuotaStatusUnknown; | 266 quota_status_ = kQuotaStatusUnknown; |
269 quota_manager_->DeleteHostData( | 267 quota_manager_->DeleteHostData( |
270 host, type, quota_client_mask, | 268 host, type, quota_client_mask, |
271 base::Bind(&QuotaManagerTest::StatusCallback, | 269 base::Bind(&QuotaManagerTest::StatusCallback, |
272 weak_factory_.GetWeakPtr())); | 270 weak_factory_.GetWeakPtr())); |
273 } | 271 } |
274 | 272 |
275 void GetAvailableSpace() { | 273 void GetStorageCapacity() { |
| 274 available_space_ = -1; |
| 275 total_space_ = -1; |
| 276 quota_manager_->GetStorageCapacity(base::Bind( |
| 277 &QuotaManagerTest::DidGetStorageCapacity, weak_factory_.GetWeakPtr())); |
| 278 } |
| 279 |
| 280 void GetEvictionRoundInfo() { |
276 quota_status_ = kQuotaStatusUnknown; | 281 quota_status_ = kQuotaStatusUnknown; |
| 282 settings_ = storage::QuotaSettings(); |
277 available_space_ = -1; | 283 available_space_ = -1; |
278 quota_manager_->GetAvailableSpace( | 284 total_space_ = -1; |
279 base::Bind(&QuotaManagerTest::DidGetAvailableSpace, | 285 usage_ = -1; |
| 286 quota_manager_->GetEvictionRoundInfo( |
| 287 base::Bind(&QuotaManagerTest::DidGetEvictionRoundInfo, |
280 weak_factory_.GetWeakPtr())); | 288 weak_factory_.GetWeakPtr())); |
281 } | 289 } |
282 | 290 |
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 | |
294 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { | 291 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { |
295 ASSERT_TRUE(origins != NULL); | 292 ASSERT_TRUE(origins != NULL); |
296 origins->clear(); | 293 origins->clear(); |
297 quota_manager_->GetCachedOrigins(type, origins); | 294 quota_manager_->GetCachedOrigins(type, origins); |
298 } | 295 } |
299 | 296 |
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 | |
306 void NotifyStorageAccessed(QuotaClient* client, | 297 void NotifyStorageAccessed(QuotaClient* client, |
307 const GURL& origin, | 298 const GURL& origin, |
308 StorageType type) { | 299 StorageType type) { |
309 DCHECK(client); | 300 DCHECK(client); |
310 quota_manager_->NotifyStorageAccessedInternal( | 301 quota_manager_->NotifyStorageAccessedInternal( |
311 client->id(), origin, type, IncrementMockTime()); | 302 client->id(), origin, type, IncrementMockTime()); |
312 } | 303 } |
313 | 304 |
314 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { | 305 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { |
315 quota_manager_->DeleteOriginFromDatabase(origin, type, false); | 306 quota_manager_->DeleteOriginFromDatabase(origin, type, false); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 quota_status_ = status; | 357 quota_status_ = status; |
367 usage_ = usage; | 358 usage_ = usage; |
368 quota_ = quota; | 359 quota_ = quota; |
369 } | 360 } |
370 | 361 |
371 void DidGetQuota(QuotaStatusCode status, int64_t quota) { | 362 void DidGetQuota(QuotaStatusCode status, int64_t quota) { |
372 quota_status_ = status; | 363 quota_status_ = status; |
373 quota_ = quota; | 364 quota_ = quota; |
374 } | 365 } |
375 | 366 |
376 void DidGetAvailableSpace(QuotaStatusCode status, int64_t available_space) { | 367 void DidGetStorageCapacity(int64_t total_space, int64_t available_space) { |
377 quota_status_ = status; | 368 total_space_ = total_space; |
378 available_space_ = available_space; | 369 available_space_ = available_space; |
379 } | 370 } |
380 | 371 |
381 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) { | 372 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) { |
382 quota_status_ = status; | 373 quota_status_ = status; |
383 quota_ = quota; | 374 quota_ = quota; |
384 } | 375 } |
385 | 376 |
386 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) { | 377 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) { |
387 usage_ = usage; | 378 usage_ = usage; |
388 unlimited_usage_ = unlimited_usage; | 379 unlimited_usage_ = unlimited_usage; |
389 } | 380 } |
390 | 381 |
391 void DidGetHostUsage(int64_t usage) { usage_ = usage; } | 382 void DidGetHostUsage(int64_t usage) { usage_ = usage; } |
392 | 383 |
393 void StatusCallback(QuotaStatusCode status) { | 384 void StatusCallback(QuotaStatusCode status) { |
394 ++status_callback_count_; | 385 ++status_callback_count_; |
395 quota_status_ = status; | 386 quota_status_ = status; |
396 } | 387 } |
397 | 388 |
398 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, | 389 void DidGetEvictionRoundInfo(QuotaStatusCode status, |
399 const UsageAndQuota& usage_and_quota) { | 390 const storage::QuotaSettings& settings, |
| 391 int64_t available_space, |
| 392 int64_t total_space, |
| 393 int64_t global_usage, |
| 394 bool global_usage_is_complete) { |
400 quota_status_ = status; | 395 quota_status_ = status; |
401 limited_usage_ = usage_and_quota.global_limited_usage; | 396 settings_ = settings; |
402 quota_ = usage_and_quota.quota; | 397 available_space_ = available_space; |
403 available_space_ = usage_and_quota.available_disk_space; | 398 total_space_ = total_space; |
| 399 usage_ = global_usage; |
404 } | 400 } |
405 | 401 |
406 void DidGetEvictionOrigin(const GURL& origin) { | 402 void DidGetEvictionOrigin(const GURL& origin) { |
407 eviction_origin_ = origin; | 403 eviction_origin_ = origin; |
408 } | 404 } |
409 | 405 |
410 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { | 406 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { |
411 modified_origins_ = origins; | 407 modified_origins_ = origins; |
412 modified_origins_type_ = type; | 408 modified_origins_type_ = type; |
413 } | 409 } |
(...skipping 24 matching lines...) Expand all Loading... |
438 MockSpecialStoragePolicy* mock_special_storage_policy() const { | 434 MockSpecialStoragePolicy* mock_special_storage_policy() const { |
439 return mock_special_storage_policy_.get(); | 435 return mock_special_storage_policy_.get(); |
440 } | 436 } |
441 | 437 |
442 QuotaStatusCode status() const { return quota_status_; } | 438 QuotaStatusCode status() const { return quota_status_; } |
443 const UsageInfoEntries& usage_info() const { return usage_info_; } | 439 const UsageInfoEntries& usage_info() const { return usage_info_; } |
444 int64_t usage() const { return usage_; } | 440 int64_t usage() const { return usage_; } |
445 int64_t limited_usage() const { return limited_usage_; } | 441 int64_t limited_usage() const { return limited_usage_; } |
446 int64_t unlimited_usage() const { return unlimited_usage_; } | 442 int64_t unlimited_usage() const { return unlimited_usage_; } |
447 int64_t quota() const { return quota_; } | 443 int64_t quota() const { return quota_; } |
| 444 int64_t total_space() const { return total_space_; } |
448 int64_t available_space() const { return available_space_; } | 445 int64_t available_space() const { return available_space_; } |
449 const GURL& eviction_origin() const { return eviction_origin_; } | 446 const GURL& eviction_origin() const { return eviction_origin_; } |
450 const std::set<GURL>& modified_origins() const { return modified_origins_; } | 447 const std::set<GURL>& modified_origins() const { return modified_origins_; } |
451 StorageType modified_origins_type() const { return modified_origins_type_; } | 448 StorageType modified_origins_type() const { return modified_origins_type_; } |
452 const QuotaTableEntries& quota_entries() const { return quota_entries_; } | 449 const QuotaTableEntries& quota_entries() const { return quota_entries_; } |
453 const OriginInfoTableEntries& origin_info_entries() const { | 450 const OriginInfoTableEntries& origin_info_entries() const { |
454 return origin_info_entries_; | 451 return origin_info_entries_; |
455 } | 452 } |
| 453 const storage::QuotaSettings& settings() const { return settings_; } |
456 base::FilePath profile_path() const { return data_dir_.GetPath(); } | 454 base::FilePath profile_path() const { return data_dir_.GetPath(); } |
457 int status_callback_count() const { return status_callback_count_; } | 455 int status_callback_count() const { return status_callback_count_; } |
458 void reset_status_callback_count() { status_callback_count_ = 0; } | 456 void reset_status_callback_count() { status_callback_count_ = 0; } |
459 | 457 |
460 private: | 458 private: |
461 base::Time IncrementMockTime() { | 459 base::Time IncrementMockTime() { |
462 ++mock_time_counter_; | 460 ++mock_time_counter_; |
463 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); | 461 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); |
464 } | 462 } |
465 | 463 |
466 base::MessageLoop message_loop_; | 464 base::MessageLoop message_loop_; |
467 base::ScopedTempDir data_dir_; | 465 base::ScopedTempDir data_dir_; |
468 | 466 |
469 scoped_refptr<QuotaManager> quota_manager_; | 467 scoped_refptr<QuotaManager> quota_manager_; |
470 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; | 468 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; |
471 | 469 |
472 QuotaStatusCode quota_status_; | 470 QuotaStatusCode quota_status_; |
473 UsageInfoEntries usage_info_; | 471 UsageInfoEntries usage_info_; |
474 int64_t usage_; | 472 int64_t usage_; |
475 int64_t limited_usage_; | 473 int64_t limited_usage_; |
476 int64_t unlimited_usage_; | 474 int64_t unlimited_usage_; |
477 int64_t quota_; | 475 int64_t quota_; |
| 476 int64_t total_space_; |
478 int64_t available_space_; | 477 int64_t available_space_; |
479 GURL eviction_origin_; | 478 GURL eviction_origin_; |
480 std::set<GURL> modified_origins_; | 479 std::set<GURL> modified_origins_; |
481 StorageType modified_origins_type_; | 480 StorageType modified_origins_type_; |
482 QuotaTableEntries quota_entries_; | 481 QuotaTableEntries quota_entries_; |
483 OriginInfoTableEntries origin_info_entries_; | 482 OriginInfoTableEntries origin_info_entries_; |
| 483 storage::QuotaSettings settings_; |
484 int status_callback_count_; | 484 int status_callback_count_; |
485 | 485 |
486 int additional_callback_count_; | 486 int additional_callback_count_; |
487 | 487 |
488 int mock_time_counter_; | 488 int mock_time_counter_; |
489 | 489 |
490 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; | 490 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; |
491 | 491 |
492 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); | 492 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); |
493 }; | 493 }; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 { "http://foo.com:8080/", kTemp, 20 }, | 626 { "http://foo.com:8080/", kTemp, 20 }, |
627 { "http://bar.com/", kTemp, 5 }, | 627 { "http://bar.com/", kTemp, 5 }, |
628 { "https://bar.com/", kTemp, 7 }, | 628 { "https://bar.com/", kTemp, 7 }, |
629 { "http://baz.com/", kTemp, 30 }, | 629 { "http://baz.com/", kTemp, 30 }, |
630 { "http://foo.com/", kPerm, 40 }, | 630 { "http://foo.com/", kPerm, 40 }, |
631 }; | 631 }; |
632 RegisterClient(CreateClient(kData, arraysize(kData), | 632 RegisterClient(CreateClient(kData, arraysize(kData), |
633 QuotaClient::kFileSystem)); | 633 QuotaClient::kFileSystem)); |
634 | 634 |
635 // This time explicitly sets a temporary global quota. | 635 // This time explicitly sets a temporary global quota. |
636 SetTemporaryGlobalQuota(100); | 636 const int kPoolSize = 100; |
637 base::RunLoop().RunUntilIdle(); | 637 const int kPerHostQuota = 20; |
638 EXPECT_EQ(kQuotaStatusOk, status()); | 638 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); |
639 EXPECT_EQ(100, quota()); | |
640 | 639 |
641 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 640 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
642 base::RunLoop().RunUntilIdle(); | 641 base::RunLoop().RunUntilIdle(); |
643 EXPECT_EQ(kQuotaStatusOk, status()); | 642 EXPECT_EQ(kQuotaStatusOk, status()); |
644 EXPECT_EQ(10 + 20, usage()); | 643 EXPECT_EQ(10 + 20, usage()); |
645 | 644 |
646 const int kPerHostQuota = 100 / kPerHostTemporaryPortion; | |
647 | |
648 // The host's quota should be its full portion of the global quota | 645 // The host's quota should be its full portion of the global quota |
649 // since global usage is under the global quota. | 646 // since there's plenty of diskspace. |
650 EXPECT_EQ(kPerHostQuota, quota()); | 647 EXPECT_EQ(kPerHostQuota, quota()); |
651 | 648 |
652 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); | 649 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); |
653 base::RunLoop().RunUntilIdle(); | 650 base::RunLoop().RunUntilIdle(); |
654 EXPECT_EQ(kQuotaStatusOk, status()); | 651 EXPECT_EQ(kQuotaStatusOk, status()); |
655 EXPECT_EQ(5 + 7, usage()); | 652 EXPECT_EQ(5 + 7, usage()); |
656 EXPECT_EQ(kPerHostQuota, quota()); | 653 EXPECT_EQ(kPerHostQuota, quota()); |
657 } | 654 } |
658 | 655 |
659 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { | 656 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { |
(...skipping 10 matching lines...) Expand all Loading... |
670 { "http://unlimited/", kTemp, 512 }, | 667 { "http://unlimited/", kTemp, 512 }, |
671 { "http://installed/", kTemp, 1024 }, | 668 { "http://installed/", kTemp, 1024 }, |
672 }; | 669 }; |
673 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 670 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
674 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); | 671 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
675 RegisterClient(CreateClient(kData1, arraysize(kData1), | 672 RegisterClient(CreateClient(kData1, arraysize(kData1), |
676 QuotaClient::kFileSystem)); | 673 QuotaClient::kFileSystem)); |
677 RegisterClient(CreateClient(kData2, arraysize(kData2), | 674 RegisterClient(CreateClient(kData2, arraysize(kData2), |
678 QuotaClient::kDatabase)); | 675 QuotaClient::kDatabase)); |
679 | 676 |
680 const int64_t kTempQuotaBase = | 677 const int64_t kPoolSize = GetAvailableDiskSpaceForTest(); |
681 GetAvailableDiskSpaceForTest() / kPerHostTemporaryPortion; | 678 const int64_t kPerHostQuota = kPoolSize / 5; |
| 679 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); |
682 | 680 |
683 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 681 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
684 base::RunLoop().RunUntilIdle(); | 682 base::RunLoop().RunUntilIdle(); |
685 EXPECT_EQ(kQuotaStatusOk, status()); | 683 EXPECT_EQ(kQuotaStatusOk, status()); |
686 EXPECT_EQ(1 + 128, usage()); | 684 EXPECT_EQ(1 + 128, usage()); |
| 685 EXPECT_EQ(kPerHostQuota, quota()); |
687 | 686 |
688 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm); | 687 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm); |
689 base::RunLoop().RunUntilIdle(); | 688 base::RunLoop().RunUntilIdle(); |
690 EXPECT_EQ(kQuotaStatusOk, status()); | 689 EXPECT_EQ(kQuotaStatusOk, status()); |
691 EXPECT_EQ(4, usage()); | 690 EXPECT_EQ(4, usage()); |
| 691 EXPECT_EQ(0, quota()); |
692 | 692 |
693 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 693 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
694 base::RunLoop().RunUntilIdle(); | 694 base::RunLoop().RunUntilIdle(); |
695 EXPECT_EQ(kQuotaStatusOk, status()); | 695 EXPECT_EQ(kQuotaStatusOk, status()); |
696 EXPECT_EQ(512, usage()); | 696 EXPECT_EQ(512, usage()); |
697 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota()); | 697 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); |
698 | 698 |
699 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); | 699 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); |
700 base::RunLoop().RunUntilIdle(); | 700 base::RunLoop().RunUntilIdle(); |
701 EXPECT_EQ(kQuotaStatusOk, status()); | 701 EXPECT_EQ(kQuotaStatusOk, status()); |
702 EXPECT_EQ(8, usage()); | 702 EXPECT_EQ(8, usage()); |
703 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | 703 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); |
704 | 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); | 705 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kTemp); |
711 base::RunLoop().RunUntilIdle(); | 706 base::RunLoop().RunUntilIdle(); |
712 EXPECT_EQ(kQuotaStatusOk, status()); | 707 EXPECT_EQ(kQuotaStatusOk, status()); |
713 EXPECT_EQ(1024, usage()); | 708 EXPECT_EQ(1024, usage()); |
714 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota()); | 709 EXPECT_EQ(kPerHostQuota, quota()); // todo TOOOOODOOOOO???? |
715 | 710 |
716 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); | 711 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); |
717 base::RunLoop().RunUntilIdle(); | 712 base::RunLoop().RunUntilIdle(); |
718 EXPECT_EQ(kQuotaStatusOk, status()); | 713 EXPECT_EQ(kQuotaStatusOk, status()); |
719 EXPECT_EQ(16, usage()); | 714 EXPECT_EQ(16, usage()); |
720 EXPECT_EQ(usage(), quota()); // Over-budget case. | 715 EXPECT_EQ(0, quota()); // Over-budget case. todo TOODOOOOO??? |
721 | 716 |
722 GetGlobalUsage(kTemp); | 717 GetGlobalUsage(kTemp); |
723 base::RunLoop().RunUntilIdle(); | 718 base::RunLoop().RunUntilIdle(); |
724 EXPECT_EQ(kQuotaStatusOk, status()); | 719 EXPECT_EQ(kQuotaStatusOk, status()); |
725 EXPECT_EQ(1 + 2 + 128 + 512 + 1024, usage()); | 720 EXPECT_EQ(1 + 2 + 128 + 512 + 1024, usage()); |
726 EXPECT_EQ(512, unlimited_usage()); | 721 EXPECT_EQ(512, unlimited_usage()); |
727 | 722 |
728 GetGlobalUsage(kPerm); | 723 GetGlobalUsage(kPerm); |
729 base::RunLoop().RunUntilIdle(); | 724 base::RunLoop().RunUntilIdle(); |
730 EXPECT_EQ(kQuotaStatusOk, status()); | 725 EXPECT_EQ(kQuotaStatusOk, status()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 | 769 |
775 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { | 770 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { |
776 static const MockOriginData kData[] = { | 771 static const MockOriginData kData[] = { |
777 { "http://foo.com/", kTemp, 10 }, | 772 { "http://foo.com/", kTemp, 10 }, |
778 { "http://foo.com:8080/", kTemp, 20 }, | 773 { "http://foo.com:8080/", kTemp, 20 }, |
779 { "http://bar.com/", kTemp, 13 }, | 774 { "http://bar.com/", kTemp, 13 }, |
780 { "http://foo.com/", kPerm, 40 }, | 775 { "http://foo.com/", kPerm, 40 }, |
781 }; | 776 }; |
782 RegisterClient(CreateClient(kData, arraysize(kData), | 777 RegisterClient(CreateClient(kData, arraysize(kData), |
783 QuotaClient::kFileSystem)); | 778 QuotaClient::kFileSystem)); |
784 SetTemporaryGlobalQuota(100); | |
785 base::RunLoop().RunUntilIdle(); | |
786 | 779 |
787 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; | 780 const int kPoolSize = 100; |
| 781 const int kPerHostQuota = 20; |
| 782 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); |
788 | 783 |
789 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 784 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
790 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 785 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
791 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 786 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
792 base::RunLoop().RunUntilIdle(); | 787 base::RunLoop().RunUntilIdle(); |
793 EXPECT_EQ(kQuotaStatusOk, status()); | 788 EXPECT_EQ(kQuotaStatusOk, status()); |
794 EXPECT_EQ(10 + 20, usage()); | 789 EXPECT_EQ(10 + 20, usage()); |
795 EXPECT_EQ(kPerHostQuota, quota()); | 790 EXPECT_EQ(kPerHostQuota, quota()); |
796 | 791 |
797 set_additional_callback_count(0); | 792 set_additional_callback_count(0); |
(...skipping 10 matching lines...) Expand all Loading... |
808 | 803 |
809 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { | 804 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { |
810 static const MockOriginData kData[] = { | 805 static const MockOriginData kData[] = { |
811 { "http://foo.com/", kTemp, 10 }, | 806 { "http://foo.com/", kTemp, 10 }, |
812 { "http://foo.com:8080/", kTemp, 20 }, | 807 { "http://foo.com:8080/", kTemp, 20 }, |
813 { "http://bar.com/", kTemp, 13 }, | 808 { "http://bar.com/", kTemp, 13 }, |
814 { "http://foo.com/", kPerm, 40 }, | 809 { "http://foo.com/", kPerm, 40 }, |
815 }; | 810 }; |
816 RegisterClient(CreateClient(kData, arraysize(kData), | 811 RegisterClient(CreateClient(kData, arraysize(kData), |
817 QuotaClient::kFileSystem)); | 812 QuotaClient::kFileSystem)); |
818 SetTemporaryGlobalQuota(100); | 813 const int kPoolSize = 100; |
819 base::RunLoop().RunUntilIdle(); | 814 const int kPerHostQuota = 20; |
| 815 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); |
820 | 816 |
821 set_additional_callback_count(0); | 817 set_additional_callback_count(0); |
822 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 818 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
823 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 819 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
824 kTemp); | 820 kTemp); |
825 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | 821 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), |
826 kTemp); | 822 kTemp); |
827 | 823 |
828 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | 824 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); |
829 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); | 825 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); |
830 | 826 |
831 // Nuke before waiting for callbacks. | 827 // Nuke before waiting for callbacks. |
832 set_quota_manager(NULL); | 828 set_quota_manager(NULL); |
833 base::RunLoop().RunUntilIdle(); | 829 base::RunLoop().RunUntilIdle(); |
834 EXPECT_EQ(kQuotaErrorAbort, status()); | 830 EXPECT_EQ(kQuotaErrorAbort, status()); |
835 } | 831 } |
836 | 832 |
837 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { | 833 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { |
838 static const MockOriginData kData[] = { | 834 static const MockOriginData kData[] = { |
839 { "http://usage1/", kTemp, 1 }, | 835 { "http://usage1/", kTemp, 1 }, |
840 { "http://usage10/", kTemp, 10 }, | 836 { "http://usage10/", kTemp, 10 }, |
841 { "http://usage200/", kTemp, 200 }, | 837 { "http://usage200/", kTemp, 200 }, |
842 }; | 838 }; |
843 RegisterClient(CreateClient(kData, arraysize(kData), | 839 RegisterClient(CreateClient(kData, arraysize(kData), |
844 QuotaClient::kFileSystem)); | 840 QuotaClient::kFileSystem)); |
845 SetTemporaryGlobalQuota(100); | 841 const int kPoolSize = 100; |
| 842 const int kPerHostQuota = 20; |
| 843 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); |
| 844 |
| 845 // Provided diskspace is not tight,. global usage does not affect the |
| 846 // quota calculations for an individual origin, so despite global usage |
| 847 // in excess of our poolsize, we still get the nominal quota value. |
| 848 GetStorageCapacity(); |
846 base::RunLoop().RunUntilIdle(); | 849 base::RunLoop().RunUntilIdle(); |
847 | 850 EXPECT_LE(kMustRemainAvailableForSystem, available_space()); |
848 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; | |
849 | 851 |
850 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); | 852 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); |
851 base::RunLoop().RunUntilIdle(); | 853 base::RunLoop().RunUntilIdle(); |
852 EXPECT_EQ(kQuotaStatusOk, status()); | 854 EXPECT_EQ(kQuotaStatusOk, status()); |
853 EXPECT_EQ(1, usage()); | 855 EXPECT_EQ(1, usage()); |
854 EXPECT_EQ(1, quota()); // should be clamped to our current usage | 856 EXPECT_EQ(kPerHostQuota, quota()); |
855 | 857 |
856 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 858 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
857 base::RunLoop().RunUntilIdle(); | 859 base::RunLoop().RunUntilIdle(); |
858 EXPECT_EQ(kQuotaStatusOk, status()); | 860 EXPECT_EQ(kQuotaStatusOk, status()); |
859 EXPECT_EQ(10, usage()); | 861 EXPECT_EQ(10, usage()); |
860 EXPECT_EQ(10, quota()); | 862 EXPECT_EQ(kPerHostQuota, quota()); |
861 | 863 |
862 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); | 864 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); |
863 base::RunLoop().RunUntilIdle(); | 865 base::RunLoop().RunUntilIdle(); |
864 EXPECT_EQ(kQuotaStatusOk, status()); | 866 EXPECT_EQ(kQuotaStatusOk, status()); |
865 EXPECT_EQ(200, usage()); | 867 EXPECT_EQ(200, usage()); |
866 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota | 868 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota |
867 } | 869 } |
868 | 870 |
869 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { | 871 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { |
870 static const MockOriginData kData[] = { | 872 static const MockOriginData kData[] = { |
871 { "http://usage10/", kTemp, 10 }, | 873 { "http://usage10/", kTemp, 10 }, |
872 { "http://usage50/", kTemp, 50 }, | 874 { "http://usage50/", kTemp, 50 }, |
873 { "http://unlimited/", kTemp, 4000 }, | 875 { "http://unlimited/", kTemp, 4000 }, |
874 }; | 876 }; |
875 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 877 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
876 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 878 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
877 QuotaClient::kFileSystem); | 879 QuotaClient::kFileSystem); |
878 RegisterClient(client); | 880 RegisterClient(client); |
879 | 881 |
880 // Test when not overbugdet. | 882 // Test when not overbugdet. |
881 SetTemporaryGlobalQuota(1000); | 883 const int kPerHostQuotaFor1000 = 200; |
882 base::RunLoop().RunUntilIdle(); | 884 SetQuotaSettings(1000, kPerHostQuotaFor1000, kMustRemainAvailableForSystem); |
883 | 885 |
884 GetGlobalUsage(kTemp); | 886 GetGlobalUsage(kTemp); |
885 base::RunLoop().RunUntilIdle(); | 887 base::RunLoop().RunUntilIdle(); |
886 EXPECT_EQ(10 + 50 + 4000, usage()); | 888 EXPECT_EQ(10 + 50 + 4000, usage()); |
887 EXPECT_EQ(4000, unlimited_usage()); | 889 EXPECT_EQ(4000, unlimited_usage()); |
888 | 890 |
889 const int kPerHostQuotaFor1000 = | |
890 1000 / QuotaManager::kPerHostTemporaryPortion; | |
891 | |
892 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 891 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
893 base::RunLoop().RunUntilIdle(); | 892 base::RunLoop().RunUntilIdle(); |
894 EXPECT_EQ(kQuotaStatusOk, status()); | 893 EXPECT_EQ(kQuotaStatusOk, status()); |
895 EXPECT_EQ(10, usage()); | 894 EXPECT_EQ(10, usage()); |
896 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 895 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
897 | 896 |
898 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 897 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
899 base::RunLoop().RunUntilIdle(); | 898 base::RunLoop().RunUntilIdle(); |
900 EXPECT_EQ(kQuotaStatusOk, status()); | 899 EXPECT_EQ(kQuotaStatusOk, status()); |
901 EXPECT_EQ(50, usage()); | 900 EXPECT_EQ(50, usage()); |
902 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 901 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
903 | 902 |
904 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 903 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
905 base::RunLoop().RunUntilIdle(); | 904 base::RunLoop().RunUntilIdle(); |
906 EXPECT_EQ(kQuotaStatusOk, status()); | 905 EXPECT_EQ(kQuotaStatusOk, status()); |
907 EXPECT_EQ(4000, usage()); | 906 EXPECT_EQ(4000, usage()); |
908 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | 907 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); |
909 | 908 |
910 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); | 909 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); |
911 base::RunLoop().RunUntilIdle(); | 910 base::RunLoop().RunUntilIdle(); |
912 EXPECT_EQ(kQuotaStatusOk, status()); | 911 EXPECT_EQ(kQuotaStatusOk, status()); |
913 EXPECT_EQ(0, usage()); | 912 EXPECT_EQ(0, usage()); |
914 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 913 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
915 | 914 |
916 // Test when overbugdet. | 915 // Test when overbugdet. |
917 SetTemporaryGlobalQuota(100); | 916 const int kPerHostQuotaFor100 = 20; |
918 base::RunLoop().RunUntilIdle(); | 917 SetQuotaSettings(100, kPerHostQuotaFor100, kMustRemainAvailableForSystem); |
919 | |
920 const int kPerHostQuotaFor100 = | |
921 100 / QuotaManager::kPerHostTemporaryPortion; | |
922 | 918 |
923 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 919 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
924 base::RunLoop().RunUntilIdle(); | 920 base::RunLoop().RunUntilIdle(); |
925 EXPECT_EQ(kQuotaStatusOk, status()); | 921 EXPECT_EQ(kQuotaStatusOk, status()); |
926 EXPECT_EQ(10, usage()); | 922 EXPECT_EQ(10, usage()); |
927 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 923 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
928 | 924 |
929 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 925 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
930 base::RunLoop().RunUntilIdle(); | 926 base::RunLoop().RunUntilIdle(); |
931 EXPECT_EQ(kQuotaStatusOk, status()); | 927 EXPECT_EQ(kQuotaStatusOk, status()); |
(...skipping 18 matching lines...) Expand all Loading... |
950 | 946 |
951 GetGlobalUsage(kTemp); | 947 GetGlobalUsage(kTemp); |
952 base::RunLoop().RunUntilIdle(); | 948 base::RunLoop().RunUntilIdle(); |
953 EXPECT_EQ(10 + 50 + 4000, usage()); | 949 EXPECT_EQ(10 + 50 + 4000, usage()); |
954 EXPECT_EQ(0, unlimited_usage()); | 950 EXPECT_EQ(0, unlimited_usage()); |
955 | 951 |
956 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 952 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
957 base::RunLoop().RunUntilIdle(); | 953 base::RunLoop().RunUntilIdle(); |
958 EXPECT_EQ(kQuotaStatusOk, status()); | 954 EXPECT_EQ(kQuotaStatusOk, status()); |
959 EXPECT_EQ(10, usage()); | 955 EXPECT_EQ(10, usage()); |
960 EXPECT_EQ(10, quota()); // should be clamped to our current usage | 956 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
961 | 957 |
962 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 958 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
963 base::RunLoop().RunUntilIdle(); | 959 base::RunLoop().RunUntilIdle(); |
964 EXPECT_EQ(kQuotaStatusOk, status()); | 960 EXPECT_EQ(kQuotaStatusOk, status()); |
965 EXPECT_EQ(50, usage()); | 961 EXPECT_EQ(50, usage()); |
966 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 962 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
967 | 963 |
968 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 964 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
969 base::RunLoop().RunUntilIdle(); | 965 base::RunLoop().RunUntilIdle(); |
970 EXPECT_EQ(kQuotaStatusOk, status()); | 966 EXPECT_EQ(kQuotaStatusOk, status()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 QuotaManager::kSyncableStorageDefaultHostQuota); | 1069 QuotaManager::kSyncableStorageDefaultHostQuota); |
1074 | 1070 |
1075 // For installed apps the quota manager should return | 1071 // For installed apps the quota manager should return |
1076 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). | 1072 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). |
1077 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); | 1073 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
1078 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kSync); | 1074 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kSync); |
1079 base::RunLoop().RunUntilIdle(); | 1075 base::RunLoop().RunUntilIdle(); |
1080 EXPECT_EQ(kQuotaStatusOk, status()); | 1076 EXPECT_EQ(kQuotaStatusOk, status()); |
1081 EXPECT_EQ(0, usage()); | 1077 EXPECT_EQ(0, usage()); |
1082 EXPECT_EQ(kAvailableSpaceForApp, quota()); | 1078 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()); | |
1091 } | 1079 } |
1092 | 1080 |
1093 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { | 1081 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { |
1094 static const MockOriginData kData[] = { | 1082 static const MockOriginData kData[] = { |
1095 { "http://foo.com/", kPerm, 10 }, | 1083 { "http://foo.com/", kPerm, 10 }, |
1096 { "http://foo.com:8080/", kPerm, 20 }, | 1084 { "http://foo.com:8080/", kPerm, 20 }, |
1097 { "https://foo.com/", kPerm, 13 }, | 1085 { "https://foo.com/", kPerm, 13 }, |
1098 { "https://foo.com:8081/", kPerm, 19 }, | 1086 { "https://foo.com:8081/", kPerm, 19 }, |
1099 { "http://bar.com/", kPerm, 5 }, | 1087 { "http://bar.com/", kPerm, 5 }, |
1100 { "https://bar.com/", kPerm, 7 }, | 1088 { "https://bar.com/", kPerm, 7 }, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 | 1275 |
1288 GetHostUsage("foo.com", kTemp); | 1276 GetHostUsage("foo.com", kTemp); |
1289 base::RunLoop().RunUntilIdle(); | 1277 base::RunLoop().RunUntilIdle(); |
1290 EXPECT_EQ(predelete_host_tmp - 1, usage()); | 1278 EXPECT_EQ(predelete_host_tmp - 1, usage()); |
1291 | 1279 |
1292 GetHostUsage("foo.com", kPerm); | 1280 GetHostUsage("foo.com", kPerm); |
1293 base::RunLoop().RunUntilIdle(); | 1281 base::RunLoop().RunUntilIdle(); |
1294 EXPECT_EQ(predelete_host_pers, usage()); | 1282 EXPECT_EQ(predelete_host_pers, usage()); |
1295 } | 1283 } |
1296 | 1284 |
1297 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { | 1285 TEST_F(QuotaManagerTest, GetStorageCapacity) { |
1298 GetAvailableSpace(); | 1286 GetStorageCapacity(); |
1299 base::RunLoop().RunUntilIdle(); | 1287 base::RunLoop().RunUntilIdle(); |
1300 EXPECT_EQ(kQuotaStatusOk, status()); | 1288 EXPECT_LE(0, total_space()); |
1301 EXPECT_LE(0, available_space()); | 1289 EXPECT_LE(0, available_space()); |
1302 } | 1290 } |
1303 | 1291 |
1304 TEST_F(QuotaManagerTest, SetTemporaryStorageEvictionPolicy) { | 1292 TEST_F(QuotaManagerTest, SetTemporaryStorageEvictionPolicy) { |
1305 quota_manager()->SetTemporaryStorageEvictionPolicy( | 1293 quota_manager()->SetTemporaryStorageEvictionPolicy( |
1306 base::WrapUnique(new TestEvictionPolicy)); | 1294 base::WrapUnique(new TestEvictionPolicy)); |
1307 | 1295 |
1308 GetEvictionOrigin(kTemp); | 1296 GetEvictionOrigin(kTemp); |
1309 base::RunLoop().RunUntilIdle(); | 1297 base::RunLoop().RunUntilIdle(); |
1310 EXPECT_EQ(kTestEvictionOrigin, eviction_origin()); | 1298 EXPECT_EQ(kTestEvictionOrigin, eviction_origin()); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 | 1510 |
1523 GetHostUsage("foo.com", kTemp); | 1511 GetHostUsage("foo.com", kTemp); |
1524 base::RunLoop().RunUntilIdle(); | 1512 base::RunLoop().RunUntilIdle(); |
1525 EXPECT_EQ(predelete_host_tmp, usage()); | 1513 EXPECT_EQ(predelete_host_tmp, usage()); |
1526 | 1514 |
1527 GetHostUsage("foo.com", kPerm); | 1515 GetHostUsage("foo.com", kPerm); |
1528 base::RunLoop().RunUntilIdle(); | 1516 base::RunLoop().RunUntilIdle(); |
1529 EXPECT_EQ(predelete_host_pers, usage()); | 1517 EXPECT_EQ(predelete_host_pers, usage()); |
1530 } | 1518 } |
1531 | 1519 |
1532 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { | 1520 TEST_F(QuotaManagerTest, GetEvictionRoundInfo) { |
1533 static const MockOriginData kData[] = { | 1521 static const MockOriginData kData[] = { |
1534 { "http://foo.com/", kTemp, 1 }, | 1522 { "http://foo.com/", kTemp, 1 }, |
1535 { "http://foo.com:1/", kTemp, 20 }, | 1523 { "http://foo.com:1/", kTemp, 20 }, |
1536 { "http://foo.com/", kPerm, 300 }, | 1524 { "http://foo.com/", kPerm, 300 }, |
1537 { "http://unlimited/", kTemp, 4000 }, | 1525 { "http://unlimited/", kTemp, 4000 }, |
1538 }; | 1526 }; |
1539 | 1527 |
1540 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 1528 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
1541 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1529 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1542 QuotaClient::kFileSystem); | 1530 QuotaClient::kFileSystem); |
1543 RegisterClient(client); | 1531 RegisterClient(client); |
1544 | 1532 |
1545 SetTemporaryGlobalQuota(10000000); | 1533 const int kPoolSize = 10000000; |
1546 base::RunLoop().RunUntilIdle(); | 1534 const int kPerHostQuota = kPoolSize / 5; |
| 1535 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); |
1547 | 1536 |
1548 GetUsageAndQuotaForEviction(); | 1537 GetEvictionRoundInfo(); |
1549 base::RunLoop().RunUntilIdle(); | 1538 base::RunLoop().RunUntilIdle(); |
1550 EXPECT_EQ(kQuotaStatusOk, status()); | 1539 EXPECT_EQ(kQuotaStatusOk, status()); |
1551 EXPECT_EQ(21, limited_usage()); | 1540 EXPECT_EQ(21, usage()); |
1552 EXPECT_EQ(10000000, quota()); | 1541 EXPECT_EQ(kPoolSize, settings().pool_size); |
1553 EXPECT_LE(0, available_space()); | 1542 EXPECT_LE(0, available_space()); |
1554 } | 1543 } |
1555 | 1544 |
1556 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { | 1545 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { |
1557 static const MockOriginData kData[] = { | 1546 static const MockOriginData kData[] = { |
1558 { "http://foo.com/", kTemp, 1 }, | 1547 { "http://foo.com/", kTemp, 1 }, |
1559 }; | 1548 }; |
1560 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1549 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1561 QuotaClient::kFileSystem); | 1550 QuotaClient::kFileSystem); |
1562 RegisterClient(client); | 1551 RegisterClient(client); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1784 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1796 QuotaClient::kFileSystem); | 1785 QuotaClient::kFileSystem); |
1797 RegisterClient(client); | 1786 RegisterClient(client); |
1798 | 1787 |
1799 // TODO(kinuko): Be careful when we add cache pruner. | 1788 // TODO(kinuko): Be careful when we add cache pruner. |
1800 | 1789 |
1801 std::set<GURL> origins; | 1790 std::set<GURL> origins; |
1802 GetCachedOrigins(kTemp, &origins); | 1791 GetCachedOrigins(kTemp, &origins); |
1803 EXPECT_TRUE(origins.empty()); | 1792 EXPECT_TRUE(origins.empty()); |
1804 | 1793 |
1805 // No matter how we make queries the quota manager tries to cache all | |
1806 // the origins at startup. | |
1807 GetHostUsage("a.com", kTemp); | 1794 GetHostUsage("a.com", kTemp); |
1808 base::RunLoop().RunUntilIdle(); | 1795 base::RunLoop().RunUntilIdle(); |
1809 GetCachedOrigins(kTemp, &origins); | 1796 GetCachedOrigins(kTemp, &origins); |
1810 EXPECT_EQ(3U, origins.size()); | 1797 EXPECT_EQ(2U, origins.size()); |
1811 | 1798 |
1812 GetHostUsage("b.com", kTemp); | 1799 GetHostUsage("b.com", kTemp); |
1813 base::RunLoop().RunUntilIdle(); | 1800 base::RunLoop().RunUntilIdle(); |
1814 GetCachedOrigins(kTemp, &origins); | 1801 GetCachedOrigins(kTemp, &origins); |
| 1802 EXPECT_EQ(2U, origins.size()); |
| 1803 |
| 1804 GetHostUsage("c.com", kTemp); |
| 1805 base::RunLoop().RunUntilIdle(); |
| 1806 GetCachedOrigins(kTemp, &origins); |
1815 EXPECT_EQ(3U, origins.size()); | 1807 EXPECT_EQ(3U, origins.size()); |
1816 | 1808 |
1817 GetCachedOrigins(kPerm, &origins); | 1809 GetCachedOrigins(kPerm, &origins); |
1818 EXPECT_TRUE(origins.empty()); | 1810 EXPECT_TRUE(origins.empty()); |
1819 | 1811 |
1820 GetGlobalUsage(kTemp); | 1812 GetGlobalUsage(kTemp); |
1821 base::RunLoop().RunUntilIdle(); | 1813 base::RunLoop().RunUntilIdle(); |
1822 GetCachedOrigins(kTemp, &origins); | 1814 GetCachedOrigins(kTemp, &origins); |
1823 EXPECT_EQ(3U, origins.size()); | 1815 EXPECT_EQ(3U, origins.size()); |
1824 | 1816 |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2261 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) { | 2253 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) { |
2262 ResetQuotaManager(true); | 2254 ResetQuotaManager(true); |
2263 | 2255 |
2264 static const MockOriginData kData[] = { | 2256 static const MockOriginData kData[] = { |
2265 { "http://foo.com/", kTemp, 10 }, | 2257 { "http://foo.com/", kTemp, 10 }, |
2266 { "http://foo.com/", kPerm, 80 }, | 2258 { "http://foo.com/", kPerm, 80 }, |
2267 }; | 2259 }; |
2268 RegisterClient(CreateClient(kData, arraysize(kData), | 2260 RegisterClient(CreateClient(kData, arraysize(kData), |
2269 QuotaClient::kFileSystem)); | 2261 QuotaClient::kFileSystem)); |
2270 | 2262 |
| 2263 // Query global usage to warmup the usage tracker caching. |
| 2264 GetGlobalUsage(kTemp); |
| 2265 GetGlobalUsage(kPerm); |
| 2266 base::RunLoop().RunUntilIdle(); |
| 2267 |
2271 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 2268 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
2272 base::RunLoop().RunUntilIdle(); | 2269 base::RunLoop().RunUntilIdle(); |
2273 EXPECT_EQ(kQuotaStatusOk, status()); | 2270 EXPECT_EQ(kQuotaStatusOk, status()); |
2274 EXPECT_EQ(80, usage()); | 2271 EXPECT_EQ(80, usage()); |
2275 EXPECT_EQ(0, quota()); | 2272 EXPECT_EQ(0, quota()); |
2276 | 2273 |
2277 SetTemporaryGlobalQuota(100); | 2274 const int kPoolSize = 1000; |
| 2275 const int kPerHostQuota = kPoolSize / 5; |
| 2276 SetQuotaSettings(kPoolSize, kPerHostQuota, INT64_C(0)); |
| 2277 |
| 2278 GetStorageCapacity(); |
| 2279 base::RunLoop().RunUntilIdle(); |
| 2280 EXPECT_EQ(kPoolSize, total_space()); |
| 2281 EXPECT_EQ(kPoolSize - 80 - 10, available_space()); |
| 2282 |
2278 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2283 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
2279 base::RunLoop().RunUntilIdle(); | 2284 base::RunLoop().RunUntilIdle(); |
2280 EXPECT_EQ(kQuotaStatusOk, status()); | 2285 EXPECT_EQ(kQuotaStatusOk, status()); |
2281 EXPECT_EQ(10, usage()); | 2286 EXPECT_EQ(10, usage()); |
2282 EXPECT_LE(std::min(static_cast<int64_t>(100 / kPerHostTemporaryPortion), | 2287 EXPECT_LE(kPerHostQuota, quota()); |
2283 QuotaManager::kIncognitoDefaultQuotaLimit), | |
2284 quota()); | |
2285 | 2288 |
2286 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); | 2289 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); |
2287 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 2290 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
2288 base::RunLoop().RunUntilIdle(); | 2291 base::RunLoop().RunUntilIdle(); |
2289 EXPECT_EQ(kQuotaStatusOk, status()); | 2292 EXPECT_EQ(kQuotaStatusOk, status()); |
2290 EXPECT_EQ(80, usage()); | 2293 EXPECT_EQ(80, usage()); |
2291 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2294 EXPECT_EQ(available_space() + usage(), quota()); |
2292 | 2295 |
2293 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2296 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
2294 base::RunLoop().RunUntilIdle(); | 2297 base::RunLoop().RunUntilIdle(); |
2295 EXPECT_EQ(kQuotaStatusOk, status()); | 2298 EXPECT_EQ(kQuotaStatusOk, status()); |
2296 EXPECT_EQ(10, usage()); | 2299 EXPECT_EQ(10, usage()); |
2297 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2300 EXPECT_EQ(available_space() + usage(), quota()); |
2298 } | |
2299 | |
2300 TEST_F(QuotaManagerTest, GetVolumeInfo) { | |
2301 // We aren't actually testing that it's correct, just that it's sane. | |
2302 base::FilePath tmp_dir; | |
2303 ASSERT_TRUE(base::GetTempDir(&tmp_dir)); | |
2304 uint64_t available_space = 0; | |
2305 uint64_t total_size = 0; | |
2306 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size)); | |
2307 EXPECT_GT(available_space, 0u) << tmp_dir.value(); | |
2308 EXPECT_GT(total_size, 0u) << tmp_dir.value(); | |
2309 } | 2301 } |
2310 | 2302 |
2311 } // namespace content | 2303 } // namespace content |
OLD | NEW |