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