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