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