| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 #include <stdint.h> | |
| 7 | |
| 8 #include <algorithm> | |
| 9 #include <memory> | |
| 10 #include <set> | |
| 11 #include <sstream> | |
| 12 #include <tuple> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/bind.h" | |
| 16 #include "base/files/file_util.h" | |
| 17 #include "base/files/scoped_temp_dir.h" | |
| 18 #include "base/macros.h" | |
| 19 #include "base/memory/ptr_util.h" | |
| 20 #include "base/memory/weak_ptr.h" | |
| 21 #include "base/run_loop.h" | |
| 22 #include "base/stl_util.h" | |
| 23 #include "base/sys_info.h" | |
| 24 #include "base/test/histogram_tester.h" | |
| 25 #include "base/test/scoped_task_environment.h" | |
| 26 #include "base/threading/thread_task_runner_handle.h" | |
| 27 #include "base/time/time.h" | |
| 28 #include "content/public/test/mock_storage_client.h" | |
| 29 #include "storage/browser/quota/quota_database.h" | |
| 30 #include "storage/browser/quota/quota_manager.h" | |
| 31 #include "storage/browser/quota/quota_manager_proxy.h" | |
| 32 #include "storage/browser/test/mock_special_storage_policy.h" | |
| 33 #include "testing/gtest/include/gtest/gtest.h" | |
| 34 #include "url/gurl.h" | |
| 35 | |
| 36 using storage::kQuotaErrorAbort; | |
| 37 using storage::kQuotaErrorInvalidModification; | |
| 38 using storage::kQuotaErrorNotSupported; | |
| 39 using storage::kQuotaStatusOk; | |
| 40 using storage::kQuotaStatusUnknown; | |
| 41 using storage::kStorageTypePersistent; | |
| 42 using storage::kStorageTypeSyncable; | |
| 43 using storage::kStorageTypeTemporary; | |
| 44 using storage::kStorageTypeUnknown; | |
| 45 using storage::QuotaClient; | |
| 46 using storage::QuotaManager; | |
| 47 using storage::QuotaStatusCode; | |
| 48 using storage::StorageType; | |
| 49 using storage::UsageInfo; | |
| 50 using storage::UsageInfoEntries; | |
| 51 | |
| 52 namespace content { | |
| 53 | |
| 54 namespace { | |
| 55 | |
| 56 // For shorter names. | |
| 57 const StorageType kTemp = kStorageTypeTemporary; | |
| 58 const StorageType kPerm = kStorageTypePersistent; | |
| 59 const StorageType kSync = kStorageTypeSyncable; | |
| 60 | |
| 61 const int kAllClients = QuotaClient::kAllClientsMask; | |
| 62 | |
| 63 // Values in bytes. | |
| 64 const int64_t kAvailableSpaceForApp = 13377331U; | |
| 65 const int64_t kMustRemainAvailableForSystem = kAvailableSpaceForApp / 2; | |
| 66 const int64_t kDefaultPoolSize = 1000; | |
| 67 const int64_t kDefaultPerHostQuota = 200; | |
| 68 | |
| 69 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); | |
| 70 | |
| 71 // Returns a deterministic value for the amount of available disk space. | |
| 72 int64_t GetAvailableDiskSpaceForTest() { | |
| 73 return kAvailableSpaceForApp + kMustRemainAvailableForSystem; | |
| 74 } | |
| 75 | |
| 76 std::tuple<int64_t, int64_t> GetVolumeInfoForTests( | |
| 77 const base::FilePath& unused) { | |
| 78 int64_t available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); | |
| 79 int64_t total = available * 2; | |
| 80 return std::make_tuple(total, available); | |
| 81 } | |
| 82 | |
| 83 } // namespace | |
| 84 | |
| 85 class QuotaManagerTest : public testing::Test { | |
| 86 protected: | |
| 87 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; | |
| 88 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; | |
| 89 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; | |
| 90 | |
| 91 public: | |
| 92 QuotaManagerTest() | |
| 93 : mock_time_counter_(0), | |
| 94 weak_factory_(this) { | |
| 95 } | |
| 96 | |
| 97 void SetUp() override { | |
| 98 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | |
| 99 mock_special_storage_policy_ = new MockSpecialStoragePolicy; | |
| 100 ResetQuotaManager(false /* is_incognito */); | |
| 101 } | |
| 102 | |
| 103 void TearDown() override { | |
| 104 // Make sure the quota manager cleans up correctly. | |
| 105 quota_manager_ = NULL; | |
| 106 base::RunLoop().RunUntilIdle(); | |
| 107 } | |
| 108 | |
| 109 protected: | |
| 110 void ResetQuotaManager(bool is_incognito) { | |
| 111 quota_manager_ = new QuotaManager(is_incognito, data_dir_.GetPath(), | |
| 112 base::ThreadTaskRunnerHandle::Get().get(), | |
| 113 base::ThreadTaskRunnerHandle::Get().get(), | |
| 114 mock_special_storage_policy_.get(), | |
| 115 storage::GetQuotaSettingsFunc()); | |
| 116 SetQuotaSettings(kDefaultPoolSize, kDefaultPerHostQuota, | |
| 117 is_incognito ? INT64_C(0) : kMustRemainAvailableForSystem); | |
| 118 | |
| 119 // Don't (automatically) start the eviction for testing. | |
| 120 quota_manager_->eviction_disabled_ = true; | |
| 121 // Don't query the hard disk for remaining capacity. | |
| 122 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests; | |
| 123 additional_callback_count_ = 0; | |
| 124 } | |
| 125 | |
| 126 MockStorageClient* CreateClient( | |
| 127 const MockOriginData* mock_data, | |
| 128 size_t mock_data_size, | |
| 129 QuotaClient::ID id) { | |
| 130 return new MockStorageClient(quota_manager_->proxy(), | |
| 131 mock_data, id, mock_data_size); | |
| 132 } | |
| 133 | |
| 134 void RegisterClient(MockStorageClient* client) { | |
| 135 quota_manager_->proxy()->RegisterClient(client); | |
| 136 } | |
| 137 | |
| 138 void GetUsageInfo() { | |
| 139 usage_info_.clear(); | |
| 140 quota_manager_->GetUsageInfo( | |
| 141 base::Bind(&QuotaManagerTest::DidGetUsageInfo, | |
| 142 weak_factory_.GetWeakPtr())); | |
| 143 } | |
| 144 | |
| 145 void GetUsageAndQuotaForWebApps(const GURL& origin, | |
| 146 StorageType type) { | |
| 147 quota_status_ = kQuotaStatusUnknown; | |
| 148 usage_ = -1; | |
| 149 quota_ = -1; | |
| 150 quota_manager_->GetUsageAndQuotaForWebApps( | |
| 151 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, | |
| 152 weak_factory_.GetWeakPtr())); | |
| 153 } | |
| 154 | |
| 155 void GetUsageAndQuotaForStorageClient(const GURL& origin, | |
| 156 StorageType type) { | |
| 157 quota_status_ = kQuotaStatusUnknown; | |
| 158 usage_ = -1; | |
| 159 quota_ = -1; | |
| 160 quota_manager_->GetUsageAndQuota( | |
| 161 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, | |
| 162 weak_factory_.GetWeakPtr())); | |
| 163 } | |
| 164 | |
| 165 void SetQuotaSettings(int64_t pool_size, | |
| 166 int64_t per_host_quota, | |
| 167 int64_t must_remain_available) { | |
| 168 storage::QuotaSettings settings; | |
| 169 settings.pool_size = pool_size; | |
| 170 settings.per_host_quota = per_host_quota; | |
| 171 settings.session_only_per_host_quota = | |
| 172 (per_host_quota > 0) ? (per_host_quota - 1) : 0; | |
| 173 settings.must_remain_available = must_remain_available; | |
| 174 settings.refresh_interval = base::TimeDelta::Max(); | |
| 175 quota_manager_->SetQuotaSettings(settings); | |
| 176 } | |
| 177 | |
| 178 void GetPersistentHostQuota(const std::string& host) { | |
| 179 quota_status_ = kQuotaStatusUnknown; | |
| 180 quota_ = -1; | |
| 181 quota_manager_->GetPersistentHostQuota( | |
| 182 host, | |
| 183 base::Bind(&QuotaManagerTest::DidGetHostQuota, | |
| 184 weak_factory_.GetWeakPtr())); | |
| 185 } | |
| 186 | |
| 187 void SetPersistentHostQuota(const std::string& host, int64_t new_quota) { | |
| 188 quota_status_ = kQuotaStatusUnknown; | |
| 189 quota_ = -1; | |
| 190 quota_manager_->SetPersistentHostQuota( | |
| 191 host, new_quota, | |
| 192 base::Bind(&QuotaManagerTest::DidGetHostQuota, | |
| 193 weak_factory_.GetWeakPtr())); | |
| 194 } | |
| 195 | |
| 196 void GetGlobalUsage(StorageType type) { | |
| 197 usage_ = -1; | |
| 198 unlimited_usage_ = -1; | |
| 199 quota_manager_->GetGlobalUsage( | |
| 200 type, | |
| 201 base::Bind(&QuotaManagerTest::DidGetGlobalUsage, | |
| 202 weak_factory_.GetWeakPtr())); | |
| 203 } | |
| 204 | |
| 205 void GetHostUsage(const std::string& host, StorageType type) { | |
| 206 usage_ = -1; | |
| 207 quota_manager_->GetHostUsage( | |
| 208 host, type, | |
| 209 base::Bind(&QuotaManagerTest::DidGetHostUsage, | |
| 210 weak_factory_.GetWeakPtr())); | |
| 211 } | |
| 212 | |
| 213 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { | |
| 214 quota_manager_->GetUsageAndQuota( | |
| 215 origin, type, | |
| 216 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional, | |
| 217 weak_factory_.GetWeakPtr())); | |
| 218 } | |
| 219 | |
| 220 void DeleteClientOriginData(QuotaClient* client, | |
| 221 const GURL& origin, | |
| 222 StorageType type) { | |
| 223 DCHECK(client); | |
| 224 quota_status_ = kQuotaStatusUnknown; | |
| 225 client->DeleteOriginData( | |
| 226 origin, type, | |
| 227 base::Bind(&QuotaManagerTest::StatusCallback, | |
| 228 weak_factory_.GetWeakPtr())); | |
| 229 } | |
| 230 | |
| 231 void EvictOriginData(const GURL& origin, | |
| 232 StorageType type) { | |
| 233 quota_status_ = kQuotaStatusUnknown; | |
| 234 quota_manager_->EvictOriginData( | |
| 235 origin, type, | |
| 236 base::Bind(&QuotaManagerTest::StatusCallback, | |
| 237 weak_factory_.GetWeakPtr())); | |
| 238 } | |
| 239 | |
| 240 void DeleteOriginData(const GURL& origin, | |
| 241 StorageType type, | |
| 242 int quota_client_mask) { | |
| 243 quota_status_ = kQuotaStatusUnknown; | |
| 244 quota_manager_->DeleteOriginData( | |
| 245 origin, type, quota_client_mask, | |
| 246 base::Bind(&QuotaManagerTest::StatusCallback, | |
| 247 weak_factory_.GetWeakPtr())); | |
| 248 } | |
| 249 | |
| 250 void DeleteHostData(const std::string& host, | |
| 251 StorageType type, | |
| 252 int quota_client_mask) { | |
| 253 quota_status_ = kQuotaStatusUnknown; | |
| 254 quota_manager_->DeleteHostData( | |
| 255 host, type, quota_client_mask, | |
| 256 base::Bind(&QuotaManagerTest::StatusCallback, | |
| 257 weak_factory_.GetWeakPtr())); | |
| 258 } | |
| 259 | |
| 260 void GetStorageCapacity() { | |
| 261 available_space_ = -1; | |
| 262 total_space_ = -1; | |
| 263 quota_manager_->GetStorageCapacity(base::Bind( | |
| 264 &QuotaManagerTest::DidGetStorageCapacity, weak_factory_.GetWeakPtr())); | |
| 265 } | |
| 266 | |
| 267 void GetEvictionRoundInfo() { | |
| 268 quota_status_ = kQuotaStatusUnknown; | |
| 269 settings_ = storage::QuotaSettings(); | |
| 270 available_space_ = -1; | |
| 271 total_space_ = -1; | |
| 272 usage_ = -1; | |
| 273 quota_manager_->GetEvictionRoundInfo( | |
| 274 base::Bind(&QuotaManagerTest::DidGetEvictionRoundInfo, | |
| 275 weak_factory_.GetWeakPtr())); | |
| 276 } | |
| 277 | |
| 278 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { | |
| 279 ASSERT_TRUE(origins != NULL); | |
| 280 origins->clear(); | |
| 281 quota_manager_->GetCachedOrigins(type, origins); | |
| 282 } | |
| 283 | |
| 284 void NotifyStorageAccessed(QuotaClient* client, | |
| 285 const GURL& origin, | |
| 286 StorageType type) { | |
| 287 DCHECK(client); | |
| 288 quota_manager_->NotifyStorageAccessedInternal( | |
| 289 client->id(), origin, type, IncrementMockTime()); | |
| 290 } | |
| 291 | |
| 292 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { | |
| 293 quota_manager_->DeleteOriginFromDatabase(origin, type, false); | |
| 294 } | |
| 295 | |
| 296 void GetEvictionOrigin(StorageType type) { | |
| 297 eviction_origin_ = GURL(); | |
| 298 // The quota manager's default eviction policy is to use an LRU eviction | |
| 299 // policy. | |
| 300 quota_manager_->GetEvictionOrigin( | |
| 301 type, std::set<GURL>(), 0, | |
| 302 base::Bind(&QuotaManagerTest::DidGetEvictionOrigin, | |
| 303 weak_factory_.GetWeakPtr())); | |
| 304 } | |
| 305 | |
| 306 void NotifyOriginInUse(const GURL& origin) { | |
| 307 quota_manager_->NotifyOriginInUse(origin); | |
| 308 } | |
| 309 | |
| 310 void NotifyOriginNoLongerInUse(const GURL& origin) { | |
| 311 quota_manager_->NotifyOriginNoLongerInUse(origin); | |
| 312 } | |
| 313 | |
| 314 void GetOriginsModifiedSince(StorageType type, base::Time modified_since) { | |
| 315 modified_origins_.clear(); | |
| 316 modified_origins_type_ = kStorageTypeUnknown; | |
| 317 quota_manager_->GetOriginsModifiedSince( | |
| 318 type, modified_since, | |
| 319 base::Bind(&QuotaManagerTest::DidGetModifiedOrigins, | |
| 320 weak_factory_.GetWeakPtr())); | |
| 321 } | |
| 322 | |
| 323 void DumpQuotaTable() { | |
| 324 quota_entries_.clear(); | |
| 325 quota_manager_->DumpQuotaTable( | |
| 326 base::Bind(&QuotaManagerTest::DidDumpQuotaTable, | |
| 327 weak_factory_.GetWeakPtr())); | |
| 328 } | |
| 329 | |
| 330 void DumpOriginInfoTable() { | |
| 331 origin_info_entries_.clear(); | |
| 332 quota_manager_->DumpOriginInfoTable( | |
| 333 base::Bind(&QuotaManagerTest::DidDumpOriginInfoTable, | |
| 334 weak_factory_.GetWeakPtr())); | |
| 335 } | |
| 336 | |
| 337 void DidGetUsageInfo(const UsageInfoEntries& entries) { | |
| 338 usage_info_.insert(usage_info_.begin(), entries.begin(), entries.end()); | |
| 339 } | |
| 340 | |
| 341 void DidGetUsageAndQuota(QuotaStatusCode status, | |
| 342 int64_t usage, | |
| 343 int64_t quota) { | |
| 344 quota_status_ = status; | |
| 345 usage_ = usage; | |
| 346 quota_ = quota; | |
| 347 } | |
| 348 | |
| 349 void DidGetQuota(QuotaStatusCode status, int64_t quota) { | |
| 350 quota_status_ = status; | |
| 351 quota_ = quota; | |
| 352 } | |
| 353 | |
| 354 void DidGetStorageCapacity(int64_t total_space, int64_t available_space) { | |
| 355 total_space_ = total_space; | |
| 356 available_space_ = available_space; | |
| 357 } | |
| 358 | |
| 359 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) { | |
| 360 quota_status_ = status; | |
| 361 quota_ = quota; | |
| 362 } | |
| 363 | |
| 364 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) { | |
| 365 usage_ = usage; | |
| 366 unlimited_usage_ = unlimited_usage; | |
| 367 } | |
| 368 | |
| 369 void DidGetHostUsage(int64_t usage) { usage_ = usage; } | |
| 370 | |
| 371 void StatusCallback(QuotaStatusCode status) { | |
| 372 ++status_callback_count_; | |
| 373 quota_status_ = status; | |
| 374 } | |
| 375 | |
| 376 void DidGetEvictionRoundInfo(QuotaStatusCode status, | |
| 377 const storage::QuotaSettings& settings, | |
| 378 int64_t available_space, | |
| 379 int64_t total_space, | |
| 380 int64_t global_usage, | |
| 381 bool global_usage_is_complete) { | |
| 382 quota_status_ = status; | |
| 383 settings_ = settings; | |
| 384 available_space_ = available_space; | |
| 385 total_space_ = total_space; | |
| 386 usage_ = global_usage; | |
| 387 } | |
| 388 | |
| 389 void DidGetEvictionOrigin(const GURL& origin) { | |
| 390 eviction_origin_ = origin; | |
| 391 } | |
| 392 | |
| 393 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { | |
| 394 modified_origins_ = origins; | |
| 395 modified_origins_type_ = type; | |
| 396 } | |
| 397 | |
| 398 void DidDumpQuotaTable(const QuotaTableEntries& entries) { | |
| 399 quota_entries_ = entries; | |
| 400 } | |
| 401 | |
| 402 void DidDumpOriginInfoTable(const OriginInfoTableEntries& entries) { | |
| 403 origin_info_entries_ = entries; | |
| 404 } | |
| 405 | |
| 406 void GetUsage_WithModifyTestBody(const StorageType type); | |
| 407 | |
| 408 void set_additional_callback_count(int c) { additional_callback_count_ = c; } | |
| 409 int additional_callback_count() const { return additional_callback_count_; } | |
| 410 void DidGetUsageAndQuotaAdditional(QuotaStatusCode status, | |
| 411 int64_t usage, | |
| 412 int64_t quota) { | |
| 413 ++additional_callback_count_; | |
| 414 } | |
| 415 | |
| 416 QuotaManager* quota_manager() const { return quota_manager_.get(); } | |
| 417 void set_quota_manager(QuotaManager* quota_manager) { | |
| 418 quota_manager_ = quota_manager; | |
| 419 } | |
| 420 | |
| 421 MockSpecialStoragePolicy* mock_special_storage_policy() const { | |
| 422 return mock_special_storage_policy_.get(); | |
| 423 } | |
| 424 | |
| 425 QuotaStatusCode status() const { return quota_status_; } | |
| 426 const UsageInfoEntries& usage_info() const { return usage_info_; } | |
| 427 int64_t usage() const { return usage_; } | |
| 428 int64_t limited_usage() const { return limited_usage_; } | |
| 429 int64_t unlimited_usage() const { return unlimited_usage_; } | |
| 430 int64_t quota() const { return quota_; } | |
| 431 int64_t total_space() const { return total_space_; } | |
| 432 int64_t available_space() const { return available_space_; } | |
| 433 const GURL& eviction_origin() const { return eviction_origin_; } | |
| 434 const std::set<GURL>& modified_origins() const { return modified_origins_; } | |
| 435 StorageType modified_origins_type() const { return modified_origins_type_; } | |
| 436 const QuotaTableEntries& quota_entries() const { return quota_entries_; } | |
| 437 const OriginInfoTableEntries& origin_info_entries() const { | |
| 438 return origin_info_entries_; | |
| 439 } | |
| 440 const storage::QuotaSettings& settings() const { return settings_; } | |
| 441 base::FilePath profile_path() const { return data_dir_.GetPath(); } | |
| 442 int status_callback_count() const { return status_callback_count_; } | |
| 443 void reset_status_callback_count() { status_callback_count_ = 0; } | |
| 444 | |
| 445 private: | |
| 446 base::Time IncrementMockTime() { | |
| 447 ++mock_time_counter_; | |
| 448 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); | |
| 449 } | |
| 450 | |
| 451 base::test::ScopedTaskEnvironment scoped_task_environment_; | |
| 452 base::ScopedTempDir data_dir_; | |
| 453 | |
| 454 scoped_refptr<QuotaManager> quota_manager_; | |
| 455 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; | |
| 456 | |
| 457 QuotaStatusCode quota_status_; | |
| 458 UsageInfoEntries usage_info_; | |
| 459 int64_t usage_; | |
| 460 int64_t limited_usage_; | |
| 461 int64_t unlimited_usage_; | |
| 462 int64_t quota_; | |
| 463 int64_t total_space_; | |
| 464 int64_t available_space_; | |
| 465 GURL eviction_origin_; | |
| 466 std::set<GURL> modified_origins_; | |
| 467 StorageType modified_origins_type_; | |
| 468 QuotaTableEntries quota_entries_; | |
| 469 OriginInfoTableEntries origin_info_entries_; | |
| 470 storage::QuotaSettings settings_; | |
| 471 int status_callback_count_; | |
| 472 | |
| 473 int additional_callback_count_; | |
| 474 | |
| 475 int mock_time_counter_; | |
| 476 | |
| 477 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; | |
| 478 | |
| 479 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); | |
| 480 }; | |
| 481 | |
| 482 TEST_F(QuotaManagerTest, GetUsageInfo) { | |
| 483 static const MockOriginData kData1[] = { | |
| 484 { "http://foo.com/", kTemp, 10 }, | |
| 485 { "http://foo.com:8080/", kTemp, 15 }, | |
| 486 { "http://bar.com/", kTemp, 20 }, | |
| 487 { "http://bar.com/", kPerm, 50 }, | |
| 488 }; | |
| 489 static const MockOriginData kData2[] = { | |
| 490 { "https://foo.com/", kTemp, 30 }, | |
| 491 { "https://foo.com:8081/", kTemp, 35 }, | |
| 492 { "http://bar.com/", kPerm, 40 }, | |
| 493 { "http://example.com/", kPerm, 40 }, | |
| 494 }; | |
| 495 RegisterClient(CreateClient(kData1, arraysize(kData1), | |
| 496 QuotaClient::kFileSystem)); | |
| 497 RegisterClient(CreateClient(kData2, arraysize(kData2), | |
| 498 QuotaClient::kDatabase)); | |
| 499 | |
| 500 GetUsageInfo(); | |
| 501 base::RunLoop().RunUntilIdle(); | |
| 502 | |
| 503 EXPECT_EQ(4U, usage_info().size()); | |
| 504 for (size_t i = 0; i < usage_info().size(); ++i) { | |
| 505 const UsageInfo& info = usage_info()[i]; | |
| 506 if (info.host == "foo.com" && info.type == kTemp) { | |
| 507 EXPECT_EQ(10 + 15 + 30 + 35, info.usage); | |
| 508 } else if (info.host == "bar.com" && info.type == kTemp) { | |
| 509 EXPECT_EQ(20, info.usage); | |
| 510 } else if (info.host == "bar.com" && info.type == kPerm) { | |
| 511 EXPECT_EQ(50 + 40, info.usage); | |
| 512 } else if (info.host == "example.com" && info.type == kPerm) { | |
| 513 EXPECT_EQ(40, info.usage); | |
| 514 } else { | |
| 515 ADD_FAILURE() | |
| 516 << "Unexpected host, type: " << info.host << ", " << info.type; | |
| 517 } | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { | |
| 522 static const MockOriginData kData[] = { | |
| 523 { "http://foo.com/", kTemp, 10 }, | |
| 524 { "http://foo.com/", kPerm, 80 }, | |
| 525 }; | |
| 526 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 527 QuotaClient::kFileSystem)); | |
| 528 | |
| 529 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 530 base::RunLoop().RunUntilIdle(); | |
| 531 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 532 EXPECT_EQ(80, usage()); | |
| 533 EXPECT_EQ(0, quota()); | |
| 534 | |
| 535 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 536 base::RunLoop().RunUntilIdle(); | |
| 537 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 538 EXPECT_EQ(10, usage()); | |
| 539 EXPECT_LE(0, quota()); | |
| 540 int64_t quota_returned_for_foo = quota(); | |
| 541 | |
| 542 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); | |
| 543 base::RunLoop().RunUntilIdle(); | |
| 544 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 545 EXPECT_EQ(0, usage()); | |
| 546 EXPECT_EQ(quota_returned_for_foo, quota()); | |
| 547 } | |
| 548 | |
| 549 TEST_F(QuotaManagerTest, GetUsage_NoClient) { | |
| 550 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 551 base::RunLoop().RunUntilIdle(); | |
| 552 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 553 EXPECT_EQ(0, usage()); | |
| 554 | |
| 555 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 556 base::RunLoop().RunUntilIdle(); | |
| 557 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 558 EXPECT_EQ(0, usage()); | |
| 559 | |
| 560 GetHostUsage("foo.com", kTemp); | |
| 561 base::RunLoop().RunUntilIdle(); | |
| 562 EXPECT_EQ(0, usage()); | |
| 563 | |
| 564 GetHostUsage("foo.com", kPerm); | |
| 565 base::RunLoop().RunUntilIdle(); | |
| 566 EXPECT_EQ(0, usage()); | |
| 567 | |
| 568 GetGlobalUsage(kTemp); | |
| 569 base::RunLoop().RunUntilIdle(); | |
| 570 EXPECT_EQ(0, usage()); | |
| 571 EXPECT_EQ(0, unlimited_usage()); | |
| 572 | |
| 573 GetGlobalUsage(kPerm); | |
| 574 base::RunLoop().RunUntilIdle(); | |
| 575 EXPECT_EQ(0, usage()); | |
| 576 EXPECT_EQ(0, unlimited_usage()); | |
| 577 } | |
| 578 | |
| 579 TEST_F(QuotaManagerTest, GetUsage_EmptyClient) { | |
| 580 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | |
| 581 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 582 base::RunLoop().RunUntilIdle(); | |
| 583 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 584 EXPECT_EQ(0, usage()); | |
| 585 | |
| 586 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 587 base::RunLoop().RunUntilIdle(); | |
| 588 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 589 EXPECT_EQ(0, usage()); | |
| 590 | |
| 591 GetHostUsage("foo.com", kTemp); | |
| 592 base::RunLoop().RunUntilIdle(); | |
| 593 EXPECT_EQ(0, usage()); | |
| 594 | |
| 595 GetHostUsage("foo.com", kPerm); | |
| 596 base::RunLoop().RunUntilIdle(); | |
| 597 EXPECT_EQ(0, usage()); | |
| 598 | |
| 599 GetGlobalUsage(kTemp); | |
| 600 base::RunLoop().RunUntilIdle(); | |
| 601 EXPECT_EQ(0, usage()); | |
| 602 EXPECT_EQ(0, unlimited_usage()); | |
| 603 | |
| 604 GetGlobalUsage(kPerm); | |
| 605 base::RunLoop().RunUntilIdle(); | |
| 606 EXPECT_EQ(0, usage()); | |
| 607 EXPECT_EQ(0, unlimited_usage()); | |
| 608 } | |
| 609 | |
| 610 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) { | |
| 611 static const MockOriginData kData[] = { | |
| 612 { "http://foo.com/", kTemp, 10 }, | |
| 613 { "http://foo.com:8080/", kTemp, 20 }, | |
| 614 { "http://bar.com/", kTemp, 5 }, | |
| 615 { "https://bar.com/", kTemp, 7 }, | |
| 616 { "http://baz.com/", kTemp, 30 }, | |
| 617 { "http://foo.com/", kPerm, 40 }, | |
| 618 }; | |
| 619 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 620 QuotaClient::kFileSystem)); | |
| 621 | |
| 622 // This time explicitly sets a temporary global quota. | |
| 623 const int kPoolSize = 100; | |
| 624 const int kPerHostQuota = 20; | |
| 625 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
| 626 | |
| 627 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 628 base::RunLoop().RunUntilIdle(); | |
| 629 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 630 EXPECT_EQ(10 + 20, usage()); | |
| 631 | |
| 632 // The host's quota should be its full portion of the global quota | |
| 633 // since there's plenty of diskspace. | |
| 634 EXPECT_EQ(kPerHostQuota, quota()); | |
| 635 | |
| 636 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); | |
| 637 base::RunLoop().RunUntilIdle(); | |
| 638 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 639 EXPECT_EQ(5 + 7, usage()); | |
| 640 EXPECT_EQ(kPerHostQuota, quota()); | |
| 641 } | |
| 642 | |
| 643 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { | |
| 644 static const MockOriginData kData1[] = { | |
| 645 { "http://foo.com/", kTemp, 1 }, | |
| 646 { "http://bar.com/", kTemp, 2 }, | |
| 647 { "http://bar.com/", kPerm, 4 }, | |
| 648 { "http://unlimited/", kPerm, 8 }, | |
| 649 }; | |
| 650 static const MockOriginData kData2[] = { | |
| 651 { "https://foo.com/", kTemp, 128 }, | |
| 652 { "http://example.com/", kPerm, 256 }, | |
| 653 { "http://unlimited/", kTemp, 512 }, | |
| 654 }; | |
| 655 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | |
| 656 RegisterClient(CreateClient(kData1, arraysize(kData1), | |
| 657 QuotaClient::kFileSystem)); | |
| 658 RegisterClient(CreateClient(kData2, arraysize(kData2), | |
| 659 QuotaClient::kDatabase)); | |
| 660 | |
| 661 const int64_t kPoolSize = GetAvailableDiskSpaceForTest(); | |
| 662 const int64_t kPerHostQuota = kPoolSize / 5; | |
| 663 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
| 664 | |
| 665 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 666 base::RunLoop().RunUntilIdle(); | |
| 667 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 668 EXPECT_EQ(1 + 128, usage()); | |
| 669 EXPECT_EQ(kPerHostQuota, quota()); | |
| 670 | |
| 671 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm); | |
| 672 base::RunLoop().RunUntilIdle(); | |
| 673 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 674 EXPECT_EQ(4, usage()); | |
| 675 EXPECT_EQ(0, quota()); | |
| 676 | |
| 677 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | |
| 678 base::RunLoop().RunUntilIdle(); | |
| 679 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 680 EXPECT_EQ(512, usage()); | |
| 681 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | |
| 682 | |
| 683 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); | |
| 684 base::RunLoop().RunUntilIdle(); | |
| 685 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 686 EXPECT_EQ(8, usage()); | |
| 687 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | |
| 688 | |
| 689 GetGlobalUsage(kTemp); | |
| 690 base::RunLoop().RunUntilIdle(); | |
| 691 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 692 EXPECT_EQ(1 + 2 + 128 + 512, usage()); | |
| 693 EXPECT_EQ(512, unlimited_usage()); | |
| 694 | |
| 695 GetGlobalUsage(kPerm); | |
| 696 base::RunLoop().RunUntilIdle(); | |
| 697 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 698 EXPECT_EQ(4 + 8 + 256, usage()); | |
| 699 EXPECT_EQ(8, unlimited_usage()); | |
| 700 } | |
| 701 | |
| 702 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { | |
| 703 const MockOriginData data[] = { | |
| 704 { "http://foo.com/", type, 10 }, | |
| 705 { "http://foo.com:1/", type, 20 }, | |
| 706 }; | |
| 707 MockStorageClient* client = CreateClient(data, arraysize(data), | |
| 708 QuotaClient::kFileSystem); | |
| 709 RegisterClient(client); | |
| 710 | |
| 711 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), type); | |
| 712 base::RunLoop().RunUntilIdle(); | |
| 713 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 714 EXPECT_EQ(10 + 20, usage()); | |
| 715 | |
| 716 client->ModifyOriginAndNotify(GURL("http://foo.com/"), type, 30); | |
| 717 client->ModifyOriginAndNotify(GURL("http://foo.com:1/"), type, -5); | |
| 718 client->AddOriginAndNotify(GURL("https://foo.com/"), type, 1); | |
| 719 | |
| 720 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), type); | |
| 721 base::RunLoop().RunUntilIdle(); | |
| 722 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 723 EXPECT_EQ(10 + 20 + 30 - 5 + 1, usage()); | |
| 724 int foo_usage = usage(); | |
| 725 | |
| 726 client->AddOriginAndNotify(GURL("http://bar.com/"), type, 40); | |
| 727 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), type); | |
| 728 base::RunLoop().RunUntilIdle(); | |
| 729 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 730 EXPECT_EQ(40, usage()); | |
| 731 | |
| 732 GetGlobalUsage(type); | |
| 733 base::RunLoop().RunUntilIdle(); | |
| 734 EXPECT_EQ(foo_usage + 40, usage()); | |
| 735 EXPECT_EQ(0, unlimited_usage()); | |
| 736 } | |
| 737 | |
| 738 TEST_F(QuotaManagerTest, GetTemporaryUsage_WithModify) { | |
| 739 GetUsage_WithModifyTestBody(kTemp); | |
| 740 } | |
| 741 | |
| 742 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { | |
| 743 static const MockOriginData kData[] = { | |
| 744 { "http://foo.com/", kTemp, 10 }, | |
| 745 { "http://foo.com:8080/", kTemp, 20 }, | |
| 746 { "http://bar.com/", kTemp, 13 }, | |
| 747 { "http://foo.com/", kPerm, 40 }, | |
| 748 }; | |
| 749 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 750 QuotaClient::kFileSystem)); | |
| 751 | |
| 752 const int kPoolSize = 100; | |
| 753 const int kPerHostQuota = 20; | |
| 754 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
| 755 | |
| 756 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 757 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 758 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 759 base::RunLoop().RunUntilIdle(); | |
| 760 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 761 EXPECT_EQ(10 + 20, usage()); | |
| 762 EXPECT_EQ(kPerHostQuota, quota()); | |
| 763 | |
| 764 set_additional_callback_count(0); | |
| 765 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | |
| 766 kTemp); | |
| 767 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 768 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kTemp); | |
| 769 base::RunLoop().RunUntilIdle(); | |
| 770 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 771 EXPECT_EQ(10 + 20, usage()); | |
| 772 EXPECT_EQ(kPerHostQuota, quota()); | |
| 773 EXPECT_EQ(2, additional_callback_count()); | |
| 774 } | |
| 775 | |
| 776 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { | |
| 777 static const MockOriginData kData[] = { | |
| 778 { "http://foo.com/", kTemp, 10 }, | |
| 779 { "http://foo.com:8080/", kTemp, 20 }, | |
| 780 { "http://bar.com/", kTemp, 13 }, | |
| 781 { "http://foo.com/", kPerm, 40 }, | |
| 782 }; | |
| 783 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 784 QuotaClient::kFileSystem)); | |
| 785 const int kPoolSize = 100; | |
| 786 const int kPerHostQuota = 20; | |
| 787 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
| 788 | |
| 789 set_additional_callback_count(0); | |
| 790 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 791 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | |
| 792 kTemp); | |
| 793 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | |
| 794 kTemp); | |
| 795 | |
| 796 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | |
| 797 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); | |
| 798 | |
| 799 // Nuke before waiting for callbacks. | |
| 800 set_quota_manager(NULL); | |
| 801 base::RunLoop().RunUntilIdle(); | |
| 802 EXPECT_EQ(kQuotaErrorAbort, status()); | |
| 803 } | |
| 804 | |
| 805 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { | |
| 806 static const MockOriginData kData[] = { | |
| 807 { "http://usage1/", kTemp, 1 }, | |
| 808 { "http://usage10/", kTemp, 10 }, | |
| 809 { "http://usage200/", kTemp, 200 }, | |
| 810 }; | |
| 811 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 812 QuotaClient::kFileSystem)); | |
| 813 const int kPoolSize = 100; | |
| 814 const int kPerHostQuota = 20; | |
| 815 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
| 816 | |
| 817 // Provided diskspace is not tight, global usage does not affect the | |
| 818 // quota calculations for an individual origin, so despite global usage | |
| 819 // in excess of our poolsize, we still get the nominal quota value. | |
| 820 GetStorageCapacity(); | |
| 821 base::RunLoop().RunUntilIdle(); | |
| 822 EXPECT_LE(kMustRemainAvailableForSystem, available_space()); | |
| 823 | |
| 824 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); | |
| 825 base::RunLoop().RunUntilIdle(); | |
| 826 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 827 EXPECT_EQ(1, usage()); | |
| 828 EXPECT_EQ(kPerHostQuota, quota()); | |
| 829 | |
| 830 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | |
| 831 base::RunLoop().RunUntilIdle(); | |
| 832 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 833 EXPECT_EQ(10, usage()); | |
| 834 EXPECT_EQ(kPerHostQuota, quota()); | |
| 835 | |
| 836 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); | |
| 837 base::RunLoop().RunUntilIdle(); | |
| 838 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 839 EXPECT_EQ(200, usage()); | |
| 840 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota | |
| 841 } | |
| 842 | |
| 843 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { | |
| 844 static const MockOriginData kData[] = { | |
| 845 { "http://usage10/", kTemp, 10 }, | |
| 846 { "http://usage50/", kTemp, 50 }, | |
| 847 { "http://unlimited/", kTemp, 4000 }, | |
| 848 }; | |
| 849 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | |
| 850 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 851 QuotaClient::kFileSystem); | |
| 852 RegisterClient(client); | |
| 853 | |
| 854 // Test when not overbugdet. | |
| 855 const int kPerHostQuotaFor1000 = 200; | |
| 856 SetQuotaSettings(1000, kPerHostQuotaFor1000, kMustRemainAvailableForSystem); | |
| 857 | |
| 858 GetGlobalUsage(kTemp); | |
| 859 base::RunLoop().RunUntilIdle(); | |
| 860 EXPECT_EQ(10 + 50 + 4000, usage()); | |
| 861 EXPECT_EQ(4000, unlimited_usage()); | |
| 862 | |
| 863 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | |
| 864 base::RunLoop().RunUntilIdle(); | |
| 865 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 866 EXPECT_EQ(10, usage()); | |
| 867 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | |
| 868 | |
| 869 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | |
| 870 base::RunLoop().RunUntilIdle(); | |
| 871 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 872 EXPECT_EQ(50, usage()); | |
| 873 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | |
| 874 | |
| 875 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | |
| 876 base::RunLoop().RunUntilIdle(); | |
| 877 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 878 EXPECT_EQ(4000, usage()); | |
| 879 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | |
| 880 | |
| 881 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); | |
| 882 base::RunLoop().RunUntilIdle(); | |
| 883 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 884 EXPECT_EQ(0, usage()); | |
| 885 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | |
| 886 | |
| 887 // Test when overbugdet. | |
| 888 const int kPerHostQuotaFor100 = 20; | |
| 889 SetQuotaSettings(100, kPerHostQuotaFor100, kMustRemainAvailableForSystem); | |
| 890 | |
| 891 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | |
| 892 base::RunLoop().RunUntilIdle(); | |
| 893 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 894 EXPECT_EQ(10, usage()); | |
| 895 EXPECT_EQ(kPerHostQuotaFor100, quota()); | |
| 896 | |
| 897 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | |
| 898 base::RunLoop().RunUntilIdle(); | |
| 899 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 900 EXPECT_EQ(50, usage()); | |
| 901 EXPECT_EQ(kPerHostQuotaFor100, quota()); | |
| 902 | |
| 903 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | |
| 904 base::RunLoop().RunUntilIdle(); | |
| 905 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 906 EXPECT_EQ(4000, usage()); | |
| 907 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); | |
| 908 | |
| 909 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); | |
| 910 base::RunLoop().RunUntilIdle(); | |
| 911 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 912 EXPECT_EQ(0, usage()); | |
| 913 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | |
| 914 | |
| 915 // Revoke the unlimited rights and make sure the change is noticed. | |
| 916 mock_special_storage_policy()->Reset(); | |
| 917 mock_special_storage_policy()->NotifyCleared(); | |
| 918 | |
| 919 GetGlobalUsage(kTemp); | |
| 920 base::RunLoop().RunUntilIdle(); | |
| 921 EXPECT_EQ(10 + 50 + 4000, usage()); | |
| 922 EXPECT_EQ(0, unlimited_usage()); | |
| 923 | |
| 924 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | |
| 925 base::RunLoop().RunUntilIdle(); | |
| 926 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 927 EXPECT_EQ(10, usage()); | |
| 928 EXPECT_EQ(kPerHostQuotaFor100, quota()); | |
| 929 | |
| 930 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | |
| 931 base::RunLoop().RunUntilIdle(); | |
| 932 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 933 EXPECT_EQ(50, usage()); | |
| 934 EXPECT_EQ(kPerHostQuotaFor100, quota()); | |
| 935 | |
| 936 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | |
| 937 base::RunLoop().RunUntilIdle(); | |
| 938 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 939 EXPECT_EQ(4000, usage()); | |
| 940 EXPECT_EQ(kPerHostQuotaFor100, quota()); | |
| 941 | |
| 942 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); | |
| 943 base::RunLoop().RunUntilIdle(); | |
| 944 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 945 EXPECT_EQ(4000, usage()); | |
| 946 EXPECT_EQ(kPerHostQuotaFor100, quota()); | |
| 947 } | |
| 948 | |
| 949 TEST_F(QuotaManagerTest, OriginInUse) { | |
| 950 const GURL kFooOrigin("http://foo.com/"); | |
| 951 const GURL kBarOrigin("http://bar.com/"); | |
| 952 | |
| 953 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); | |
| 954 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 1 | |
| 955 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin)); | |
| 956 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 2 | |
| 957 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin)); | |
| 958 quota_manager()->NotifyOriginNoLongerInUse(kFooOrigin); // count of 1 | |
| 959 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin)); | |
| 960 | |
| 961 EXPECT_FALSE(quota_manager()->IsOriginInUse(kBarOrigin)); | |
| 962 quota_manager()->NotifyOriginInUse(kBarOrigin); | |
| 963 EXPECT_TRUE(quota_manager()->IsOriginInUse(kBarOrigin)); | |
| 964 quota_manager()->NotifyOriginNoLongerInUse(kBarOrigin); | |
| 965 EXPECT_FALSE(quota_manager()->IsOriginInUse(kBarOrigin)); | |
| 966 | |
| 967 quota_manager()->NotifyOriginNoLongerInUse(kFooOrigin); | |
| 968 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); | |
| 969 } | |
| 970 | |
| 971 TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) { | |
| 972 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | |
| 973 | |
| 974 GetPersistentHostQuota("foo.com"); | |
| 975 base::RunLoop().RunUntilIdle(); | |
| 976 EXPECT_EQ(0, quota()); | |
| 977 | |
| 978 SetPersistentHostQuota("foo.com", 100); | |
| 979 base::RunLoop().RunUntilIdle(); | |
| 980 EXPECT_EQ(100, quota()); | |
| 981 | |
| 982 GetPersistentHostQuota("foo.com"); | |
| 983 SetPersistentHostQuota("foo.com", 200); | |
| 984 GetPersistentHostQuota("foo.com"); | |
| 985 SetPersistentHostQuota("foo.com", QuotaManager::kPerHostPersistentQuotaLimit); | |
| 986 GetPersistentHostQuota("foo.com"); | |
| 987 base::RunLoop().RunUntilIdle(); | |
| 988 EXPECT_EQ(QuotaManager::kPerHostPersistentQuotaLimit, quota()); | |
| 989 | |
| 990 // Persistent quota should be capped at the per-host quota limit. | |
| 991 SetPersistentHostQuota("foo.com", | |
| 992 QuotaManager::kPerHostPersistentQuotaLimit + 100); | |
| 993 GetPersistentHostQuota("foo.com"); | |
| 994 base::RunLoop().RunUntilIdle(); | |
| 995 EXPECT_EQ(QuotaManager::kPerHostPersistentQuotaLimit, quota()); | |
| 996 } | |
| 997 | |
| 998 TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) { | |
| 999 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | |
| 1000 | |
| 1001 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1002 base::RunLoop().RunUntilIdle(); | |
| 1003 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1004 EXPECT_EQ(0, usage()); | |
| 1005 EXPECT_EQ(0, quota()); | |
| 1006 | |
| 1007 SetPersistentHostQuota("foo.com", 100); | |
| 1008 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1009 base::RunLoop().RunUntilIdle(); | |
| 1010 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1011 EXPECT_EQ(0, usage()); | |
| 1012 EXPECT_EQ(100, quota()); | |
| 1013 | |
| 1014 // The actual space avaialble is given to 'unlimited' origins as their quota. | |
| 1015 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | |
| 1016 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); | |
| 1017 base::RunLoop().RunUntilIdle(); | |
| 1018 EXPECT_EQ(kAvailableSpaceForApp, quota()); | |
| 1019 | |
| 1020 // GetUsageAndQuotaForStorageClient should just return 0 usage and | |
| 1021 // kNoLimit quota. | |
| 1022 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kPerm); | |
| 1023 base::RunLoop().RunUntilIdle(); | |
| 1024 EXPECT_EQ(0, usage()); | |
| 1025 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | |
| 1026 } | |
| 1027 | |
| 1028 TEST_F(QuotaManagerTest, GetSyncableQuota) { | |
| 1029 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | |
| 1030 | |
| 1031 // Pre-condition check: available disk space (for testing) is less than | |
| 1032 // the default quota for syncable storage. | |
| 1033 EXPECT_LE(kAvailableSpaceForApp, | |
| 1034 QuotaManager::kSyncableStorageDefaultHostQuota); | |
| 1035 | |
| 1036 // For unlimited origins the quota manager should return | |
| 1037 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). | |
| 1038 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | |
| 1039 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kSync); | |
| 1040 base::RunLoop().RunUntilIdle(); | |
| 1041 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1042 EXPECT_EQ(0, usage()); | |
| 1043 EXPECT_EQ(kAvailableSpaceForApp, quota()); | |
| 1044 } | |
| 1045 | |
| 1046 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { | |
| 1047 static const MockOriginData kData[] = { | |
| 1048 { "http://foo.com/", kPerm, 10 }, | |
| 1049 { "http://foo.com:8080/", kPerm, 20 }, | |
| 1050 { "https://foo.com/", kPerm, 13 }, | |
| 1051 { "https://foo.com:8081/", kPerm, 19 }, | |
| 1052 { "http://bar.com/", kPerm, 5 }, | |
| 1053 { "https://bar.com/", kPerm, 7 }, | |
| 1054 { "http://baz.com/", kPerm, 30 }, | |
| 1055 { "http://foo.com/", kTemp, 40 }, | |
| 1056 }; | |
| 1057 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 1058 QuotaClient::kFileSystem)); | |
| 1059 | |
| 1060 SetPersistentHostQuota("foo.com", 100); | |
| 1061 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1062 base::RunLoop().RunUntilIdle(); | |
| 1063 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1064 EXPECT_EQ(10 + 20 + 13 + 19, usage()); | |
| 1065 EXPECT_EQ(100, quota()); | |
| 1066 } | |
| 1067 | |
| 1068 TEST_F(QuotaManagerTest, GetPersistentUsage_WithModify) { | |
| 1069 GetUsage_WithModifyTestBody(kPerm); | |
| 1070 } | |
| 1071 | |
| 1072 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) { | |
| 1073 static const MockOriginData kData[] = { | |
| 1074 { "http://foo.com/", kPerm, 10 }, | |
| 1075 { "http://foo.com:8080/", kPerm, 20 }, | |
| 1076 { "http://bar.com/", kPerm, 13 }, | |
| 1077 { "http://foo.com/", kTemp, 40 }, | |
| 1078 }; | |
| 1079 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 1080 QuotaClient::kFileSystem)); | |
| 1081 SetPersistentHostQuota("foo.com", 100); | |
| 1082 | |
| 1083 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1084 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1085 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1086 base::RunLoop().RunUntilIdle(); | |
| 1087 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1088 EXPECT_EQ(10 + 20, usage()); | |
| 1089 EXPECT_EQ(100, quota()); | |
| 1090 | |
| 1091 set_additional_callback_count(0); | |
| 1092 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | |
| 1093 kPerm); | |
| 1094 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1095 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); | |
| 1096 base::RunLoop().RunUntilIdle(); | |
| 1097 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1098 EXPECT_EQ(10 + 20, usage()); | |
| 1099 EXPECT_EQ(2, additional_callback_count()); | |
| 1100 } | |
| 1101 | |
| 1102 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) { | |
| 1103 static const MockOriginData kData[] = { | |
| 1104 { "http://foo.com/", kPerm, 10 }, | |
| 1105 { "http://foo.com:8080/", kPerm, 20 }, | |
| 1106 { "http://bar.com/", kPerm, 13 }, | |
| 1107 { "http://foo.com/", kTemp, 40 }, | |
| 1108 }; | |
| 1109 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 1110 QuotaClient::kFileSystem)); | |
| 1111 SetPersistentHostQuota("foo.com", 100); | |
| 1112 | |
| 1113 set_additional_callback_count(0); | |
| 1114 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 1115 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), kPerm); | |
| 1116 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); | |
| 1117 | |
| 1118 // Nuke before waiting for callbacks. | |
| 1119 set_quota_manager(NULL); | |
| 1120 base::RunLoop().RunUntilIdle(); | |
| 1121 EXPECT_EQ(kQuotaErrorAbort, status()); | |
| 1122 } | |
| 1123 | |
| 1124 TEST_F(QuotaManagerTest, GetUsage_Simple) { | |
| 1125 static const MockOriginData kData[] = { | |
| 1126 { "http://foo.com/", kPerm, 1 }, | |
| 1127 { "http://foo.com:1/", kPerm, 20 }, | |
| 1128 { "http://bar.com/", kTemp, 300 }, | |
| 1129 { "https://buz.com/", kTemp, 4000 }, | |
| 1130 { "http://buz.com/", kTemp, 50000 }, | |
| 1131 { "http://bar.com:1/", kPerm, 600000 }, | |
| 1132 { "http://foo.com/", kTemp, 7000000 }, | |
| 1133 }; | |
| 1134 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 1135 QuotaClient::kFileSystem)); | |
| 1136 | |
| 1137 GetGlobalUsage(kPerm); | |
| 1138 base::RunLoop().RunUntilIdle(); | |
| 1139 EXPECT_EQ(usage(), 1 + 20 + 600000); | |
| 1140 EXPECT_EQ(0, unlimited_usage()); | |
| 1141 | |
| 1142 GetGlobalUsage(kTemp); | |
| 1143 base::RunLoop().RunUntilIdle(); | |
| 1144 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000); | |
| 1145 EXPECT_EQ(0, unlimited_usage()); | |
| 1146 | |
| 1147 GetHostUsage("foo.com", kPerm); | |
| 1148 base::RunLoop().RunUntilIdle(); | |
| 1149 EXPECT_EQ(usage(), 1 + 20); | |
| 1150 | |
| 1151 GetHostUsage("buz.com", kTemp); | |
| 1152 base::RunLoop().RunUntilIdle(); | |
| 1153 EXPECT_EQ(usage(), 4000 + 50000); | |
| 1154 } | |
| 1155 | |
| 1156 TEST_F(QuotaManagerTest, GetUsage_WithModification) { | |
| 1157 static const MockOriginData kData[] = { | |
| 1158 { "http://foo.com/", kPerm, 1 }, | |
| 1159 { "http://foo.com:1/", kPerm, 20 }, | |
| 1160 { "http://bar.com/", kTemp, 300 }, | |
| 1161 { "https://buz.com/", kTemp, 4000 }, | |
| 1162 { "http://buz.com/", kTemp, 50000 }, | |
| 1163 { "http://bar.com:1/", kPerm, 600000 }, | |
| 1164 { "http://foo.com/", kTemp, 7000000 }, | |
| 1165 }; | |
| 1166 | |
| 1167 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1168 QuotaClient::kFileSystem); | |
| 1169 RegisterClient(client); | |
| 1170 | |
| 1171 GetGlobalUsage(kPerm); | |
| 1172 base::RunLoop().RunUntilIdle(); | |
| 1173 EXPECT_EQ(usage(), 1 + 20 + 600000); | |
| 1174 EXPECT_EQ(0, unlimited_usage()); | |
| 1175 | |
| 1176 client->ModifyOriginAndNotify( | |
| 1177 GURL("http://foo.com/"), kPerm, 80000000); | |
| 1178 | |
| 1179 GetGlobalUsage(kPerm); | |
| 1180 base::RunLoop().RunUntilIdle(); | |
| 1181 EXPECT_EQ(usage(), 1 + 20 + 600000 + 80000000); | |
| 1182 EXPECT_EQ(0, unlimited_usage()); | |
| 1183 | |
| 1184 GetGlobalUsage(kTemp); | |
| 1185 base::RunLoop().RunUntilIdle(); | |
| 1186 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000); | |
| 1187 EXPECT_EQ(0, unlimited_usage()); | |
| 1188 | |
| 1189 client->ModifyOriginAndNotify( | |
| 1190 GURL("http://foo.com/"), kTemp, 1); | |
| 1191 | |
| 1192 GetGlobalUsage(kTemp); | |
| 1193 base::RunLoop().RunUntilIdle(); | |
| 1194 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000 + 1); | |
| 1195 EXPECT_EQ(0, unlimited_usage()); | |
| 1196 | |
| 1197 GetHostUsage("buz.com", kTemp); | |
| 1198 base::RunLoop().RunUntilIdle(); | |
| 1199 EXPECT_EQ(usage(), 4000 + 50000); | |
| 1200 | |
| 1201 client->ModifyOriginAndNotify( | |
| 1202 GURL("http://buz.com/"), kTemp, 900000000); | |
| 1203 | |
| 1204 GetHostUsage("buz.com", kTemp); | |
| 1205 base::RunLoop().RunUntilIdle(); | |
| 1206 EXPECT_EQ(usage(), 4000 + 50000 + 900000000); | |
| 1207 } | |
| 1208 | |
| 1209 TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) { | |
| 1210 static const MockOriginData kData[] = { | |
| 1211 { "http://foo.com/", kTemp, 1 }, | |
| 1212 { "http://foo.com:1/", kTemp, 20 }, | |
| 1213 { "http://foo.com/", kPerm, 300 }, | |
| 1214 { "http://bar.com/", kTemp, 4000 }, | |
| 1215 }; | |
| 1216 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1217 QuotaClient::kFileSystem); | |
| 1218 RegisterClient(client); | |
| 1219 | |
| 1220 GetGlobalUsage(kTemp); | |
| 1221 base::RunLoop().RunUntilIdle(); | |
| 1222 int64_t predelete_global_tmp = usage(); | |
| 1223 | |
| 1224 GetHostUsage("foo.com", kTemp); | |
| 1225 base::RunLoop().RunUntilIdle(); | |
| 1226 int64_t predelete_host_tmp = usage(); | |
| 1227 | |
| 1228 GetHostUsage("foo.com", kPerm); | |
| 1229 base::RunLoop().RunUntilIdle(); | |
| 1230 int64_t predelete_host_pers = usage(); | |
| 1231 | |
| 1232 DeleteClientOriginData(client, GURL("http://foo.com/"), | |
| 1233 kTemp); | |
| 1234 base::RunLoop().RunUntilIdle(); | |
| 1235 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1236 | |
| 1237 GetGlobalUsage(kTemp); | |
| 1238 base::RunLoop().RunUntilIdle(); | |
| 1239 EXPECT_EQ(predelete_global_tmp - 1, usage()); | |
| 1240 | |
| 1241 GetHostUsage("foo.com", kTemp); | |
| 1242 base::RunLoop().RunUntilIdle(); | |
| 1243 EXPECT_EQ(predelete_host_tmp - 1, usage()); | |
| 1244 | |
| 1245 GetHostUsage("foo.com", kPerm); | |
| 1246 base::RunLoop().RunUntilIdle(); | |
| 1247 EXPECT_EQ(predelete_host_pers, usage()); | |
| 1248 } | |
| 1249 | |
| 1250 TEST_F(QuotaManagerTest, GetStorageCapacity) { | |
| 1251 GetStorageCapacity(); | |
| 1252 base::RunLoop().RunUntilIdle(); | |
| 1253 EXPECT_LE(0, total_space()); | |
| 1254 EXPECT_LE(0, available_space()); | |
| 1255 } | |
| 1256 | |
| 1257 TEST_F(QuotaManagerTest, EvictOriginData) { | |
| 1258 static const MockOriginData kData1[] = { | |
| 1259 { "http://foo.com/", kTemp, 1 }, | |
| 1260 { "http://foo.com:1/", kTemp, 20 }, | |
| 1261 { "http://foo.com/", kPerm, 300 }, | |
| 1262 { "http://bar.com/", kTemp, 4000 }, | |
| 1263 }; | |
| 1264 static const MockOriginData kData2[] = { | |
| 1265 { "http://foo.com/", kTemp, 50000 }, | |
| 1266 { "http://foo.com:1/", kTemp, 6000 }, | |
| 1267 { "http://foo.com/", kPerm, 700 }, | |
| 1268 { "https://foo.com/", kTemp, 80 }, | |
| 1269 { "http://bar.com/", kTemp, 9 }, | |
| 1270 }; | |
| 1271 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 1272 QuotaClient::kFileSystem); | |
| 1273 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 1274 QuotaClient::kDatabase); | |
| 1275 RegisterClient(client1); | |
| 1276 RegisterClient(client2); | |
| 1277 | |
| 1278 GetGlobalUsage(kTemp); | |
| 1279 base::RunLoop().RunUntilIdle(); | |
| 1280 int64_t predelete_global_tmp = usage(); | |
| 1281 | |
| 1282 GetHostUsage("foo.com", kTemp); | |
| 1283 base::RunLoop().RunUntilIdle(); | |
| 1284 int64_t predelete_host_tmp = usage(); | |
| 1285 | |
| 1286 GetHostUsage("foo.com", kPerm); | |
| 1287 base::RunLoop().RunUntilIdle(); | |
| 1288 int64_t predelete_host_pers = usage(); | |
| 1289 | |
| 1290 for (size_t i = 0; i < arraysize(kData1); ++i) | |
| 1291 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | |
| 1292 GURL(kData1[i].origin), kData1[i].type); | |
| 1293 for (size_t i = 0; i < arraysize(kData2); ++i) | |
| 1294 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | |
| 1295 GURL(kData2[i].origin), kData2[i].type); | |
| 1296 base::RunLoop().RunUntilIdle(); | |
| 1297 | |
| 1298 EvictOriginData(GURL("http://foo.com/"), kTemp); | |
| 1299 base::RunLoop().RunUntilIdle(); | |
| 1300 | |
| 1301 DumpOriginInfoTable(); | |
| 1302 base::RunLoop().RunUntilIdle(); | |
| 1303 | |
| 1304 typedef OriginInfoTableEntries::const_iterator iterator; | |
| 1305 for (iterator itr(origin_info_entries().begin()), | |
| 1306 end(origin_info_entries().end()); | |
| 1307 itr != end; ++itr) { | |
| 1308 if (itr->type == kTemp) | |
| 1309 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | |
| 1310 } | |
| 1311 | |
| 1312 GetGlobalUsage(kTemp); | |
| 1313 base::RunLoop().RunUntilIdle(); | |
| 1314 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage()); | |
| 1315 | |
| 1316 GetHostUsage("foo.com", kTemp); | |
| 1317 base::RunLoop().RunUntilIdle(); | |
| 1318 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); | |
| 1319 | |
| 1320 GetHostUsage("foo.com", kPerm); | |
| 1321 base::RunLoop().RunUntilIdle(); | |
| 1322 EXPECT_EQ(predelete_host_pers, usage()); | |
| 1323 } | |
| 1324 | |
| 1325 TEST_F(QuotaManagerTest, EvictOriginDataHistogram) { | |
| 1326 const GURL kOrigin = GURL("http://foo.com/"); | |
| 1327 static const MockOriginData kData[] = { | |
| 1328 {"http://foo.com/", kTemp, 1}, | |
| 1329 }; | |
| 1330 | |
| 1331 base::HistogramTester histograms; | |
| 1332 MockStorageClient* client = | |
| 1333 CreateClient(kData, arraysize(kData), QuotaClient::kFileSystem); | |
| 1334 RegisterClient(client); | |
| 1335 | |
| 1336 GetGlobalUsage(kTemp); | |
| 1337 base::RunLoop().RunUntilIdle(); | |
| 1338 | |
| 1339 EvictOriginData(kOrigin, kTemp); | |
| 1340 base::RunLoop().RunUntilIdle(); | |
| 1341 | |
| 1342 // Ensure used count and time since access are recorded. | |
| 1343 histograms.ExpectTotalCount( | |
| 1344 QuotaManager::kEvictedOriginAccessedCountHistogram, 1); | |
| 1345 histograms.ExpectBucketCount( | |
| 1346 QuotaManager::kEvictedOriginAccessedCountHistogram, 0, 1); | |
| 1347 histograms.ExpectTotalCount( | |
| 1348 QuotaManager::kEvictedOriginDaysSinceAccessHistogram, 1); | |
| 1349 | |
| 1350 // First eviction has no 'last' time to compare to. | |
| 1351 histograms.ExpectTotalCount( | |
| 1352 QuotaManager::kDaysBetweenRepeatedOriginEvictionsHistogram, 0); | |
| 1353 | |
| 1354 client->AddOriginAndNotify(kOrigin, kTemp, 100); | |
| 1355 | |
| 1356 // Change the used count of the origin. | |
| 1357 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, GURL(kOrigin), | |
| 1358 kTemp); | |
| 1359 base::RunLoop().RunUntilIdle(); | |
| 1360 | |
| 1361 GetGlobalUsage(kTemp); | |
| 1362 base::RunLoop().RunUntilIdle(); | |
| 1363 | |
| 1364 EvictOriginData(kOrigin, kTemp); | |
| 1365 base::RunLoop().RunUntilIdle(); | |
| 1366 | |
| 1367 // The new used count should be logged. | |
| 1368 histograms.ExpectTotalCount( | |
| 1369 QuotaManager::kEvictedOriginAccessedCountHistogram, 2); | |
| 1370 histograms.ExpectBucketCount( | |
| 1371 QuotaManager::kEvictedOriginAccessedCountHistogram, 1, 1); | |
| 1372 histograms.ExpectTotalCount( | |
| 1373 QuotaManager::kEvictedOriginDaysSinceAccessHistogram, 2); | |
| 1374 | |
| 1375 // Second eviction should log a 'time between repeated eviction' sample. | |
| 1376 histograms.ExpectTotalCount( | |
| 1377 QuotaManager::kDaysBetweenRepeatedOriginEvictionsHistogram, 1); | |
| 1378 | |
| 1379 client->AddOriginAndNotify(kOrigin, kTemp, 100); | |
| 1380 | |
| 1381 GetGlobalUsage(kTemp); | |
| 1382 base::RunLoop().RunUntilIdle(); | |
| 1383 | |
| 1384 DeleteOriginFromDatabase(kOrigin, kTemp); | |
| 1385 | |
| 1386 // Deletion from non-eviction source should not log a histogram sample. | |
| 1387 histograms.ExpectTotalCount( | |
| 1388 QuotaManager::kDaysBetweenRepeatedOriginEvictionsHistogram, 1); | |
| 1389 } | |
| 1390 | |
| 1391 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { | |
| 1392 static const MockOriginData kData[] = { | |
| 1393 { "http://foo.com/", kTemp, 1 }, | |
| 1394 { "http://foo.com:1/", kTemp, 20 }, | |
| 1395 { "http://foo.com/", kPerm, 300 }, | |
| 1396 { "http://bar.com/", kTemp, 4000 }, | |
| 1397 }; | |
| 1398 static const int kNumberOfTemporaryOrigins = 3; | |
| 1399 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1400 QuotaClient::kFileSystem); | |
| 1401 RegisterClient(client); | |
| 1402 | |
| 1403 GetGlobalUsage(kTemp); | |
| 1404 base::RunLoop().RunUntilIdle(); | |
| 1405 int64_t predelete_global_tmp = usage(); | |
| 1406 | |
| 1407 GetHostUsage("foo.com", kTemp); | |
| 1408 base::RunLoop().RunUntilIdle(); | |
| 1409 int64_t predelete_host_tmp = usage(); | |
| 1410 | |
| 1411 GetHostUsage("foo.com", kPerm); | |
| 1412 base::RunLoop().RunUntilIdle(); | |
| 1413 int64_t predelete_host_pers = usage(); | |
| 1414 | |
| 1415 for (size_t i = 0; i < arraysize(kData); ++i) | |
| 1416 NotifyStorageAccessed(client, GURL(kData[i].origin), kData[i].type); | |
| 1417 base::RunLoop().RunUntilIdle(); | |
| 1418 | |
| 1419 client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp); | |
| 1420 | |
| 1421 for (int i = 0; | |
| 1422 i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1; | |
| 1423 ++i) { | |
| 1424 EvictOriginData(GURL("http://foo.com/"), kTemp); | |
| 1425 base::RunLoop().RunUntilIdle(); | |
| 1426 EXPECT_EQ(kQuotaErrorInvalidModification, status()); | |
| 1427 } | |
| 1428 | |
| 1429 DumpOriginInfoTable(); | |
| 1430 base::RunLoop().RunUntilIdle(); | |
| 1431 | |
| 1432 bool found_origin_in_database = false; | |
| 1433 typedef OriginInfoTableEntries::const_iterator iterator; | |
| 1434 for (iterator itr(origin_info_entries().begin()), | |
| 1435 end(origin_info_entries().end()); | |
| 1436 itr != end; ++itr) { | |
| 1437 if (itr->type == kTemp && itr->origin == "http://foo.com/") { | |
| 1438 found_origin_in_database = true; | |
| 1439 break; | |
| 1440 } | |
| 1441 } | |
| 1442 // The origin "http://foo.com/" should be in the database. | |
| 1443 EXPECT_TRUE(found_origin_in_database); | |
| 1444 | |
| 1445 for (size_t i = 0; i < kNumberOfTemporaryOrigins - 1; ++i) { | |
| 1446 GetEvictionOrigin(kTemp); | |
| 1447 base::RunLoop().RunUntilIdle(); | |
| 1448 EXPECT_FALSE(eviction_origin().is_empty()); | |
| 1449 // The origin "http://foo.com/" should not be in the LRU list. | |
| 1450 EXPECT_NE(std::string("http://foo.com/"), eviction_origin().spec()); | |
| 1451 DeleteOriginFromDatabase(eviction_origin(), kTemp); | |
| 1452 base::RunLoop().RunUntilIdle(); | |
| 1453 } | |
| 1454 | |
| 1455 // Now the LRU list must be empty. | |
| 1456 GetEvictionOrigin(kTemp); | |
| 1457 base::RunLoop().RunUntilIdle(); | |
| 1458 EXPECT_TRUE(eviction_origin().is_empty()); | |
| 1459 | |
| 1460 // Deleting origins from the database should not affect the results of the | |
| 1461 // following checks. | |
| 1462 GetGlobalUsage(kTemp); | |
| 1463 base::RunLoop().RunUntilIdle(); | |
| 1464 EXPECT_EQ(predelete_global_tmp, usage()); | |
| 1465 | |
| 1466 GetHostUsage("foo.com", kTemp); | |
| 1467 base::RunLoop().RunUntilIdle(); | |
| 1468 EXPECT_EQ(predelete_host_tmp, usage()); | |
| 1469 | |
| 1470 GetHostUsage("foo.com", kPerm); | |
| 1471 base::RunLoop().RunUntilIdle(); | |
| 1472 EXPECT_EQ(predelete_host_pers, usage()); | |
| 1473 } | |
| 1474 | |
| 1475 TEST_F(QuotaManagerTest, GetEvictionRoundInfo) { | |
| 1476 static const MockOriginData kData[] = { | |
| 1477 { "http://foo.com/", kTemp, 1 }, | |
| 1478 { "http://foo.com:1/", kTemp, 20 }, | |
| 1479 { "http://foo.com/", kPerm, 300 }, | |
| 1480 { "http://unlimited/", kTemp, 4000 }, | |
| 1481 }; | |
| 1482 | |
| 1483 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | |
| 1484 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1485 QuotaClient::kFileSystem); | |
| 1486 RegisterClient(client); | |
| 1487 | |
| 1488 const int kPoolSize = 10000000; | |
| 1489 const int kPerHostQuota = kPoolSize / 5; | |
| 1490 SetQuotaSettings(kPoolSize, kPerHostQuota, kMustRemainAvailableForSystem); | |
| 1491 | |
| 1492 GetEvictionRoundInfo(); | |
| 1493 base::RunLoop().RunUntilIdle(); | |
| 1494 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1495 EXPECT_EQ(21, usage()); | |
| 1496 EXPECT_EQ(kPoolSize, settings().pool_size); | |
| 1497 EXPECT_LE(0, available_space()); | |
| 1498 } | |
| 1499 | |
| 1500 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { | |
| 1501 static const MockOriginData kData[] = { | |
| 1502 { "http://foo.com/", kTemp, 1 }, | |
| 1503 }; | |
| 1504 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1505 QuotaClient::kFileSystem); | |
| 1506 RegisterClient(client); | |
| 1507 | |
| 1508 GetGlobalUsage(kTemp); | |
| 1509 base::RunLoop().RunUntilIdle(); | |
| 1510 const int64_t predelete_global_tmp = usage(); | |
| 1511 | |
| 1512 GetHostUsage("foo.com", kTemp); | |
| 1513 base::RunLoop().RunUntilIdle(); | |
| 1514 int64_t predelete_host_tmp = usage(); | |
| 1515 | |
| 1516 GetHostUsage("foo.com", kPerm); | |
| 1517 base::RunLoop().RunUntilIdle(); | |
| 1518 int64_t predelete_host_pers = usage(); | |
| 1519 | |
| 1520 DeleteHostData(std::string(), kTemp, kAllClients); | |
| 1521 base::RunLoop().RunUntilIdle(); | |
| 1522 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1523 | |
| 1524 GetGlobalUsage(kTemp); | |
| 1525 base::RunLoop().RunUntilIdle(); | |
| 1526 EXPECT_EQ(predelete_global_tmp, usage()); | |
| 1527 | |
| 1528 GetHostUsage("foo.com", kTemp); | |
| 1529 base::RunLoop().RunUntilIdle(); | |
| 1530 EXPECT_EQ(predelete_host_tmp, usage()); | |
| 1531 | |
| 1532 GetHostUsage("foo.com", kPerm); | |
| 1533 base::RunLoop().RunUntilIdle(); | |
| 1534 EXPECT_EQ(predelete_host_pers, usage()); | |
| 1535 | |
| 1536 DeleteHostData("foo.com", kTemp, kAllClients); | |
| 1537 base::RunLoop().RunUntilIdle(); | |
| 1538 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 1539 | |
| 1540 GetGlobalUsage(kTemp); | |
| 1541 base::RunLoop().RunUntilIdle(); | |
| 1542 EXPECT_EQ(predelete_global_tmp - 1, usage()); | |
| 1543 | |
| 1544 GetHostUsage("foo.com", kTemp); | |
| 1545 base::RunLoop().RunUntilIdle(); | |
| 1546 EXPECT_EQ(predelete_host_tmp - 1, usage()); | |
| 1547 | |
| 1548 GetHostUsage("foo.com", kPerm); | |
| 1549 base::RunLoop().RunUntilIdle(); | |
| 1550 EXPECT_EQ(predelete_host_pers, usage()); | |
| 1551 } | |
| 1552 | |
| 1553 TEST_F(QuotaManagerTest, DeleteHostDataMultiple) { | |
| 1554 static const MockOriginData kData1[] = { | |
| 1555 { "http://foo.com/", kTemp, 1 }, | |
| 1556 { "http://foo.com:1/", kTemp, 20 }, | |
| 1557 { "http://foo.com/", kPerm, 300 }, | |
| 1558 { "http://bar.com/", kTemp, 4000 }, | |
| 1559 }; | |
| 1560 static const MockOriginData kData2[] = { | |
| 1561 { "http://foo.com/", kTemp, 50000 }, | |
| 1562 { "http://foo.com:1/", kTemp, 6000 }, | |
| 1563 { "http://foo.com/", kPerm, 700 }, | |
| 1564 { "https://foo.com/", kTemp, 80 }, | |
| 1565 { "http://bar.com/", kTemp, 9 }, | |
| 1566 }; | |
| 1567 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 1568 QuotaClient::kFileSystem); | |
| 1569 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 1570 QuotaClient::kDatabase); | |
| 1571 RegisterClient(client1); | |
| 1572 RegisterClient(client2); | |
| 1573 | |
| 1574 GetGlobalUsage(kTemp); | |
| 1575 base::RunLoop().RunUntilIdle(); | |
| 1576 const int64_t predelete_global_tmp = usage(); | |
| 1577 | |
| 1578 GetHostUsage("foo.com", kTemp); | |
| 1579 base::RunLoop().RunUntilIdle(); | |
| 1580 const int64_t predelete_foo_tmp = usage(); | |
| 1581 | |
| 1582 GetHostUsage("bar.com", kTemp); | |
| 1583 base::RunLoop().RunUntilIdle(); | |
| 1584 const int64_t predelete_bar_tmp = usage(); | |
| 1585 | |
| 1586 GetHostUsage("foo.com", kPerm); | |
| 1587 base::RunLoop().RunUntilIdle(); | |
| 1588 const int64_t predelete_foo_pers = usage(); | |
| 1589 | |
| 1590 GetHostUsage("bar.com", kPerm); | |
| 1591 base::RunLoop().RunUntilIdle(); | |
| 1592 const int64_t predelete_bar_pers = usage(); | |
| 1593 | |
| 1594 reset_status_callback_count(); | |
| 1595 DeleteHostData("foo.com", kTemp, kAllClients); | |
| 1596 DeleteHostData("bar.com", kTemp, kAllClients); | |
| 1597 DeleteHostData("foo.com", kTemp, kAllClients); | |
| 1598 base::RunLoop().RunUntilIdle(); | |
| 1599 | |
| 1600 EXPECT_EQ(3, status_callback_count()); | |
| 1601 | |
| 1602 DumpOriginInfoTable(); | |
| 1603 base::RunLoop().RunUntilIdle(); | |
| 1604 | |
| 1605 typedef OriginInfoTableEntries::const_iterator iterator; | |
| 1606 for (iterator itr(origin_info_entries().begin()), | |
| 1607 end(origin_info_entries().end()); | |
| 1608 itr != end; ++itr) { | |
| 1609 if (itr->type == kTemp) { | |
| 1610 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | |
| 1611 EXPECT_NE(std::string("http://foo.com:1/"), itr->origin.spec()); | |
| 1612 EXPECT_NE(std::string("https://foo.com/"), itr->origin.spec()); | |
| 1613 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); | |
| 1614 } | |
| 1615 } | |
| 1616 | |
| 1617 GetGlobalUsage(kTemp); | |
| 1618 base::RunLoop().RunUntilIdle(); | |
| 1619 EXPECT_EQ(predelete_global_tmp - (1 + 20 + 4000 + 50000 + 6000 + 80 + 9), | |
| 1620 usage()); | |
| 1621 | |
| 1622 GetHostUsage("foo.com", kTemp); | |
| 1623 base::RunLoop().RunUntilIdle(); | |
| 1624 EXPECT_EQ(predelete_foo_tmp - (1 + 20 + 50000 + 6000 + 80), usage()); | |
| 1625 | |
| 1626 GetHostUsage("bar.com", kTemp); | |
| 1627 base::RunLoop().RunUntilIdle(); | |
| 1628 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage()); | |
| 1629 | |
| 1630 GetHostUsage("foo.com", kPerm); | |
| 1631 base::RunLoop().RunUntilIdle(); | |
| 1632 EXPECT_EQ(predelete_foo_pers, usage()); | |
| 1633 | |
| 1634 GetHostUsage("bar.com", kPerm); | |
| 1635 base::RunLoop().RunUntilIdle(); | |
| 1636 EXPECT_EQ(predelete_bar_pers, usage()); | |
| 1637 } | |
| 1638 | |
| 1639 // Single-run DeleteOriginData cases must be well covered by | |
| 1640 // EvictOriginData tests. | |
| 1641 TEST_F(QuotaManagerTest, DeleteOriginDataMultiple) { | |
| 1642 static const MockOriginData kData1[] = { | |
| 1643 { "http://foo.com/", kTemp, 1 }, | |
| 1644 { "http://foo.com:1/", kTemp, 20 }, | |
| 1645 { "http://foo.com/", kPerm, 300 }, | |
| 1646 { "http://bar.com/", kTemp, 4000 }, | |
| 1647 }; | |
| 1648 static const MockOriginData kData2[] = { | |
| 1649 { "http://foo.com/", kTemp, 50000 }, | |
| 1650 { "http://foo.com:1/", kTemp, 6000 }, | |
| 1651 { "http://foo.com/", kPerm, 700 }, | |
| 1652 { "https://foo.com/", kTemp, 80 }, | |
| 1653 { "http://bar.com/", kTemp, 9 }, | |
| 1654 }; | |
| 1655 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 1656 QuotaClient::kFileSystem); | |
| 1657 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 1658 QuotaClient::kDatabase); | |
| 1659 RegisterClient(client1); | |
| 1660 RegisterClient(client2); | |
| 1661 | |
| 1662 GetGlobalUsage(kTemp); | |
| 1663 base::RunLoop().RunUntilIdle(); | |
| 1664 const int64_t predelete_global_tmp = usage(); | |
| 1665 | |
| 1666 GetHostUsage("foo.com", kTemp); | |
| 1667 base::RunLoop().RunUntilIdle(); | |
| 1668 const int64_t predelete_foo_tmp = usage(); | |
| 1669 | |
| 1670 GetHostUsage("bar.com", kTemp); | |
| 1671 base::RunLoop().RunUntilIdle(); | |
| 1672 const int64_t predelete_bar_tmp = usage(); | |
| 1673 | |
| 1674 GetHostUsage("foo.com", kPerm); | |
| 1675 base::RunLoop().RunUntilIdle(); | |
| 1676 const int64_t predelete_foo_pers = usage(); | |
| 1677 | |
| 1678 GetHostUsage("bar.com", kPerm); | |
| 1679 base::RunLoop().RunUntilIdle(); | |
| 1680 const int64_t predelete_bar_pers = usage(); | |
| 1681 | |
| 1682 for (size_t i = 0; i < arraysize(kData1); ++i) | |
| 1683 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | |
| 1684 GURL(kData1[i].origin), kData1[i].type); | |
| 1685 for (size_t i = 0; i < arraysize(kData2); ++i) | |
| 1686 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | |
| 1687 GURL(kData2[i].origin), kData2[i].type); | |
| 1688 base::RunLoop().RunUntilIdle(); | |
| 1689 | |
| 1690 reset_status_callback_count(); | |
| 1691 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | |
| 1692 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); | |
| 1693 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | |
| 1694 base::RunLoop().RunUntilIdle(); | |
| 1695 | |
| 1696 EXPECT_EQ(3, status_callback_count()); | |
| 1697 | |
| 1698 DumpOriginInfoTable(); | |
| 1699 base::RunLoop().RunUntilIdle(); | |
| 1700 | |
| 1701 typedef OriginInfoTableEntries::const_iterator iterator; | |
| 1702 for (iterator itr(origin_info_entries().begin()), | |
| 1703 end(origin_info_entries().end()); | |
| 1704 itr != end; ++itr) { | |
| 1705 if (itr->type == kTemp) { | |
| 1706 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | |
| 1707 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); | |
| 1708 } | |
| 1709 } | |
| 1710 | |
| 1711 GetGlobalUsage(kTemp); | |
| 1712 base::RunLoop().RunUntilIdle(); | |
| 1713 EXPECT_EQ(predelete_global_tmp - (1 + 4000 + 50000 + 9), usage()); | |
| 1714 | |
| 1715 GetHostUsage("foo.com", kTemp); | |
| 1716 base::RunLoop().RunUntilIdle(); | |
| 1717 EXPECT_EQ(predelete_foo_tmp - (1 + 50000), usage()); | |
| 1718 | |
| 1719 GetHostUsage("bar.com", kTemp); | |
| 1720 base::RunLoop().RunUntilIdle(); | |
| 1721 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage()); | |
| 1722 | |
| 1723 GetHostUsage("foo.com", kPerm); | |
| 1724 base::RunLoop().RunUntilIdle(); | |
| 1725 EXPECT_EQ(predelete_foo_pers, usage()); | |
| 1726 | |
| 1727 GetHostUsage("bar.com", kPerm); | |
| 1728 base::RunLoop().RunUntilIdle(); | |
| 1729 EXPECT_EQ(predelete_bar_pers, usage()); | |
| 1730 } | |
| 1731 | |
| 1732 TEST_F(QuotaManagerTest, GetCachedOrigins) { | |
| 1733 static const MockOriginData kData[] = { | |
| 1734 { "http://a.com/", kTemp, 1 }, | |
| 1735 { "http://a.com:1/", kTemp, 20 }, | |
| 1736 { "http://b.com/", kPerm, 300 }, | |
| 1737 { "http://c.com/", kTemp, 4000 }, | |
| 1738 }; | |
| 1739 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1740 QuotaClient::kFileSystem); | |
| 1741 RegisterClient(client); | |
| 1742 | |
| 1743 // TODO(kinuko): Be careful when we add cache pruner. | |
| 1744 | |
| 1745 std::set<GURL> origins; | |
| 1746 GetCachedOrigins(kTemp, &origins); | |
| 1747 EXPECT_TRUE(origins.empty()); | |
| 1748 | |
| 1749 GetHostUsage("a.com", kTemp); | |
| 1750 base::RunLoop().RunUntilIdle(); | |
| 1751 GetCachedOrigins(kTemp, &origins); | |
| 1752 EXPECT_EQ(2U, origins.size()); | |
| 1753 | |
| 1754 GetHostUsage("b.com", kTemp); | |
| 1755 base::RunLoop().RunUntilIdle(); | |
| 1756 GetCachedOrigins(kTemp, &origins); | |
| 1757 EXPECT_EQ(2U, origins.size()); | |
| 1758 | |
| 1759 GetHostUsage("c.com", kTemp); | |
| 1760 base::RunLoop().RunUntilIdle(); | |
| 1761 GetCachedOrigins(kTemp, &origins); | |
| 1762 EXPECT_EQ(3U, origins.size()); | |
| 1763 | |
| 1764 GetCachedOrigins(kPerm, &origins); | |
| 1765 EXPECT_TRUE(origins.empty()); | |
| 1766 | |
| 1767 GetGlobalUsage(kTemp); | |
| 1768 base::RunLoop().RunUntilIdle(); | |
| 1769 GetCachedOrigins(kTemp, &origins); | |
| 1770 EXPECT_EQ(3U, origins.size()); | |
| 1771 | |
| 1772 for (size_t i = 0; i < arraysize(kData); ++i) { | |
| 1773 if (kData[i].type == kTemp) | |
| 1774 EXPECT_TRUE(origins.find(GURL(kData[i].origin)) != origins.end()); | |
| 1775 } | |
| 1776 } | |
| 1777 | |
| 1778 TEST_F(QuotaManagerTest, NotifyAndLRUOrigin) { | |
| 1779 static const MockOriginData kData[] = { | |
| 1780 { "http://a.com/", kTemp, 0 }, | |
| 1781 { "http://a.com:1/", kTemp, 0 }, | |
| 1782 { "https://a.com/", kTemp, 0 }, | |
| 1783 { "http://b.com/", kPerm, 0 }, // persistent | |
| 1784 { "http://c.com/", kTemp, 0 }, | |
| 1785 }; | |
| 1786 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1787 QuotaClient::kFileSystem); | |
| 1788 RegisterClient(client); | |
| 1789 | |
| 1790 GURL origin; | |
| 1791 GetEvictionOrigin(kTemp); | |
| 1792 base::RunLoop().RunUntilIdle(); | |
| 1793 EXPECT_TRUE(eviction_origin().is_empty()); | |
| 1794 | |
| 1795 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); | |
| 1796 GetEvictionOrigin(kTemp); | |
| 1797 base::RunLoop().RunUntilIdle(); | |
| 1798 EXPECT_EQ("http://a.com/", eviction_origin().spec()); | |
| 1799 | |
| 1800 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); | |
| 1801 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); | |
| 1802 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); | |
| 1803 GetEvictionOrigin(kTemp); | |
| 1804 base::RunLoop().RunUntilIdle(); | |
| 1805 EXPECT_EQ("http://a.com/", eviction_origin().spec()); | |
| 1806 | |
| 1807 DeleteOriginFromDatabase(eviction_origin(), kTemp); | |
| 1808 GetEvictionOrigin(kTemp); | |
| 1809 base::RunLoop().RunUntilIdle(); | |
| 1810 EXPECT_EQ("https://a.com/", eviction_origin().spec()); | |
| 1811 | |
| 1812 DeleteOriginFromDatabase(eviction_origin(), kTemp); | |
| 1813 GetEvictionOrigin(kTemp); | |
| 1814 base::RunLoop().RunUntilIdle(); | |
| 1815 EXPECT_EQ("http://c.com/", eviction_origin().spec()); | |
| 1816 } | |
| 1817 | |
| 1818 TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) { | |
| 1819 static const MockOriginData kData[] = { | |
| 1820 { "http://a.com/", kTemp, 0 }, | |
| 1821 { "http://a.com:1/", kTemp, 0 }, | |
| 1822 { "https://a.com/", kTemp, 0 }, | |
| 1823 { "http://b.com/", kPerm, 0 }, // persistent | |
| 1824 { "http://c.com/", kTemp, 0 }, | |
| 1825 }; | |
| 1826 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1827 QuotaClient::kFileSystem); | |
| 1828 RegisterClient(client); | |
| 1829 | |
| 1830 GURL origin; | |
| 1831 GetEvictionOrigin(kTemp); | |
| 1832 base::RunLoop().RunUntilIdle(); | |
| 1833 EXPECT_TRUE(eviction_origin().is_empty()); | |
| 1834 | |
| 1835 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); | |
| 1836 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); | |
| 1837 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); | |
| 1838 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); | |
| 1839 | |
| 1840 GetEvictionOrigin(kTemp); | |
| 1841 base::RunLoop().RunUntilIdle(); | |
| 1842 EXPECT_EQ("http://a.com/", eviction_origin().spec()); | |
| 1843 | |
| 1844 // Notify origin http://a.com is in use. | |
| 1845 NotifyOriginInUse(GURL("http://a.com/")); | |
| 1846 GetEvictionOrigin(kTemp); | |
| 1847 base::RunLoop().RunUntilIdle(); | |
| 1848 EXPECT_EQ("https://a.com/", eviction_origin().spec()); | |
| 1849 | |
| 1850 // Notify origin https://a.com is in use while GetEvictionOrigin is running. | |
| 1851 GetEvictionOrigin(kTemp); | |
| 1852 NotifyOriginInUse(GURL("https://a.com/")); | |
| 1853 base::RunLoop().RunUntilIdle(); | |
| 1854 // Post-filtering must have excluded the returned origin, so we will | |
| 1855 // see empty result here. | |
| 1856 EXPECT_TRUE(eviction_origin().is_empty()); | |
| 1857 | |
| 1858 // Notify access for http://c.com while GetEvictionOrigin is running. | |
| 1859 GetEvictionOrigin(kTemp); | |
| 1860 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); | |
| 1861 base::RunLoop().RunUntilIdle(); | |
| 1862 // Post-filtering must have excluded the returned origin, so we will | |
| 1863 // see empty result here. | |
| 1864 EXPECT_TRUE(eviction_origin().is_empty()); | |
| 1865 | |
| 1866 NotifyOriginNoLongerInUse(GURL("http://a.com/")); | |
| 1867 NotifyOriginNoLongerInUse(GURL("https://a.com/")); | |
| 1868 GetEvictionOrigin(kTemp); | |
| 1869 base::RunLoop().RunUntilIdle(); | |
| 1870 EXPECT_EQ("http://a.com/", eviction_origin().spec()); | |
| 1871 } | |
| 1872 | |
| 1873 TEST_F(QuotaManagerTest, GetOriginsModifiedSince) { | |
| 1874 static const MockOriginData kData[] = { | |
| 1875 { "http://a.com/", kTemp, 0 }, | |
| 1876 { "http://a.com:1/", kTemp, 0 }, | |
| 1877 { "https://a.com/", kTemp, 0 }, | |
| 1878 { "http://b.com/", kPerm, 0 }, // persistent | |
| 1879 { "http://c.com/", kTemp, 0 }, | |
| 1880 }; | |
| 1881 MockStorageClient* client = CreateClient(kData, arraysize(kData), | |
| 1882 QuotaClient::kFileSystem); | |
| 1883 RegisterClient(client); | |
| 1884 | |
| 1885 GetOriginsModifiedSince(kTemp, base::Time()); | |
| 1886 base::RunLoop().RunUntilIdle(); | |
| 1887 EXPECT_TRUE(modified_origins().empty()); | |
| 1888 EXPECT_EQ(modified_origins_type(), kTemp); | |
| 1889 | |
| 1890 base::Time time1 = client->IncrementMockTime(); | |
| 1891 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); | |
| 1892 client->ModifyOriginAndNotify(GURL("http://a.com:1/"), kTemp, 10); | |
| 1893 client->ModifyOriginAndNotify(GURL("http://b.com/"), kPerm, 10); | |
| 1894 base::Time time2 = client->IncrementMockTime(); | |
| 1895 client->ModifyOriginAndNotify(GURL("https://a.com/"), kTemp, 10); | |
| 1896 client->ModifyOriginAndNotify(GURL("http://c.com/"), kTemp, 10); | |
| 1897 base::Time time3 = client->IncrementMockTime(); | |
| 1898 | |
| 1899 GetOriginsModifiedSince(kTemp, time1); | |
| 1900 base::RunLoop().RunUntilIdle(); | |
| 1901 EXPECT_EQ(4U, modified_origins().size()); | |
| 1902 EXPECT_EQ(modified_origins_type(), kTemp); | |
| 1903 for (size_t i = 0; i < arraysize(kData); ++i) { | |
| 1904 if (kData[i].type == kTemp) | |
| 1905 EXPECT_EQ(1U, modified_origins().count(GURL(kData[i].origin))); | |
| 1906 } | |
| 1907 | |
| 1908 GetOriginsModifiedSince(kTemp, time2); | |
| 1909 base::RunLoop().RunUntilIdle(); | |
| 1910 EXPECT_EQ(2U, modified_origins().size()); | |
| 1911 | |
| 1912 GetOriginsModifiedSince(kTemp, time3); | |
| 1913 base::RunLoop().RunUntilIdle(); | |
| 1914 EXPECT_TRUE(modified_origins().empty()); | |
| 1915 EXPECT_EQ(modified_origins_type(), kTemp); | |
| 1916 | |
| 1917 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); | |
| 1918 | |
| 1919 GetOriginsModifiedSince(kTemp, time3); | |
| 1920 base::RunLoop().RunUntilIdle(); | |
| 1921 EXPECT_EQ(1U, modified_origins().size()); | |
| 1922 EXPECT_EQ(1U, modified_origins().count(GURL("http://a.com/"))); | |
| 1923 EXPECT_EQ(modified_origins_type(), kTemp); | |
| 1924 } | |
| 1925 | |
| 1926 TEST_F(QuotaManagerTest, DumpQuotaTable) { | |
| 1927 SetPersistentHostQuota("example1.com", 1); | |
| 1928 SetPersistentHostQuota("example2.com", 20); | |
| 1929 SetPersistentHostQuota("example3.com", 300); | |
| 1930 base::RunLoop().RunUntilIdle(); | |
| 1931 | |
| 1932 DumpQuotaTable(); | |
| 1933 base::RunLoop().RunUntilIdle(); | |
| 1934 | |
| 1935 const QuotaTableEntry kEntries[] = { | |
| 1936 QuotaTableEntry("example1.com", kPerm, 1), | |
| 1937 QuotaTableEntry("example2.com", kPerm, 20), | |
| 1938 QuotaTableEntry("example3.com", kPerm, 300), | |
| 1939 }; | |
| 1940 std::set<QuotaTableEntry> entries(kEntries, kEntries + arraysize(kEntries)); | |
| 1941 | |
| 1942 typedef QuotaTableEntries::const_iterator iterator; | |
| 1943 for (iterator itr(quota_entries().begin()), end(quota_entries().end()); | |
| 1944 itr != end; ++itr) { | |
| 1945 SCOPED_TRACE(testing::Message() | |
| 1946 << "host = " << itr->host << ", " | |
| 1947 << "quota = " << itr->quota); | |
| 1948 EXPECT_EQ(1u, entries.erase(*itr)); | |
| 1949 } | |
| 1950 EXPECT_TRUE(entries.empty()); | |
| 1951 } | |
| 1952 | |
| 1953 TEST_F(QuotaManagerTest, DumpOriginInfoTable) { | |
| 1954 using std::make_pair; | |
| 1955 | |
| 1956 quota_manager()->NotifyStorageAccessed( | |
| 1957 QuotaClient::kUnknown, | |
| 1958 GURL("http://example.com/"), | |
| 1959 kTemp); | |
| 1960 quota_manager()->NotifyStorageAccessed( | |
| 1961 QuotaClient::kUnknown, | |
| 1962 GURL("http://example.com/"), | |
| 1963 kPerm); | |
| 1964 quota_manager()->NotifyStorageAccessed( | |
| 1965 QuotaClient::kUnknown, | |
| 1966 GURL("http://example.com/"), | |
| 1967 kPerm); | |
| 1968 base::RunLoop().RunUntilIdle(); | |
| 1969 | |
| 1970 DumpOriginInfoTable(); | |
| 1971 base::RunLoop().RunUntilIdle(); | |
| 1972 | |
| 1973 typedef std::pair<GURL, StorageType> TypedOrigin; | |
| 1974 typedef std::pair<TypedOrigin, int> Entry; | |
| 1975 const Entry kEntries[] = { | |
| 1976 make_pair(make_pair(GURL("http://example.com/"), kTemp), 1), | |
| 1977 make_pair(make_pair(GURL("http://example.com/"), kPerm), 2), | |
| 1978 }; | |
| 1979 std::set<Entry> entries(kEntries, kEntries + arraysize(kEntries)); | |
| 1980 | |
| 1981 typedef OriginInfoTableEntries::const_iterator iterator; | |
| 1982 for (iterator itr(origin_info_entries().begin()), | |
| 1983 end(origin_info_entries().end()); | |
| 1984 itr != end; ++itr) { | |
| 1985 SCOPED_TRACE(testing::Message() | |
| 1986 << "host = " << itr->origin << ", " | |
| 1987 << "type = " << itr->type << ", " | |
| 1988 << "used_count = " << itr->used_count); | |
| 1989 EXPECT_EQ(1u, entries.erase( | |
| 1990 make_pair(make_pair(itr->origin, itr->type), | |
| 1991 itr->used_count))); | |
| 1992 } | |
| 1993 EXPECT_TRUE(entries.empty()); | |
| 1994 } | |
| 1995 | |
| 1996 TEST_F(QuotaManagerTest, QuotaForEmptyHost) { | |
| 1997 GetPersistentHostQuota(std::string()); | |
| 1998 base::RunLoop().RunUntilIdle(); | |
| 1999 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 2000 EXPECT_EQ(0, quota()); | |
| 2001 | |
| 2002 SetPersistentHostQuota(std::string(), 10); | |
| 2003 base::RunLoop().RunUntilIdle(); | |
| 2004 EXPECT_EQ(kQuotaErrorNotSupported, status()); | |
| 2005 } | |
| 2006 | |
| 2007 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleOrigin) { | |
| 2008 static const MockOriginData kData1[] = { | |
| 2009 { "http://foo.com/", kTemp, 1 }, | |
| 2010 }; | |
| 2011 static const MockOriginData kData2[] = { | |
| 2012 { "http://foo.com/", kTemp, 2 }, | |
| 2013 }; | |
| 2014 static const MockOriginData kData3[] = { | |
| 2015 { "http://foo.com/", kTemp, 4 }, | |
| 2016 }; | |
| 2017 static const MockOriginData kData4[] = { | |
| 2018 { "http://foo.com/", kTemp, 8 }, | |
| 2019 }; | |
| 2020 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 2021 QuotaClient::kFileSystem); | |
| 2022 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 2023 QuotaClient::kAppcache); | |
| 2024 MockStorageClient* client3 = CreateClient(kData3, arraysize(kData3), | |
| 2025 QuotaClient::kDatabase); | |
| 2026 MockStorageClient* client4 = CreateClient(kData4, arraysize(kData4), | |
| 2027 QuotaClient::kIndexedDatabase); | |
| 2028 RegisterClient(client1); | |
| 2029 RegisterClient(client2); | |
| 2030 RegisterClient(client3); | |
| 2031 RegisterClient(client4); | |
| 2032 | |
| 2033 GetHostUsage("foo.com", kTemp); | |
| 2034 base::RunLoop().RunUntilIdle(); | |
| 2035 const int64_t predelete_foo_tmp = usage(); | |
| 2036 | |
| 2037 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kFileSystem); | |
| 2038 base::RunLoop().RunUntilIdle(); | |
| 2039 GetHostUsage("foo.com", kTemp); | |
| 2040 base::RunLoop().RunUntilIdle(); | |
| 2041 EXPECT_EQ(predelete_foo_tmp - 1, usage()); | |
| 2042 | |
| 2043 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kAppcache); | |
| 2044 base::RunLoop().RunUntilIdle(); | |
| 2045 GetHostUsage("foo.com", kTemp); | |
| 2046 base::RunLoop().RunUntilIdle(); | |
| 2047 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | |
| 2048 | |
| 2049 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kDatabase); | |
| 2050 base::RunLoop().RunUntilIdle(); | |
| 2051 GetHostUsage("foo.com", kTemp); | |
| 2052 base::RunLoop().RunUntilIdle(); | |
| 2053 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); | |
| 2054 | |
| 2055 DeleteOriginData(GURL("http://foo.com/"), kTemp, | |
| 2056 QuotaClient::kIndexedDatabase); | |
| 2057 base::RunLoop().RunUntilIdle(); | |
| 2058 GetHostUsage("foo.com", kTemp); | |
| 2059 base::RunLoop().RunUntilIdle(); | |
| 2060 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | |
| 2061 } | |
| 2062 | |
| 2063 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleHost) { | |
| 2064 static const MockOriginData kData1[] = { | |
| 2065 { "http://foo.com:1111/", kTemp, 1 }, | |
| 2066 }; | |
| 2067 static const MockOriginData kData2[] = { | |
| 2068 { "http://foo.com:2222/", kTemp, 2 }, | |
| 2069 }; | |
| 2070 static const MockOriginData kData3[] = { | |
| 2071 { "http://foo.com:3333/", kTemp, 4 }, | |
| 2072 }; | |
| 2073 static const MockOriginData kData4[] = { | |
| 2074 { "http://foo.com:4444/", kTemp, 8 }, | |
| 2075 }; | |
| 2076 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 2077 QuotaClient::kFileSystem); | |
| 2078 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 2079 QuotaClient::kAppcache); | |
| 2080 MockStorageClient* client3 = CreateClient(kData3, arraysize(kData3), | |
| 2081 QuotaClient::kDatabase); | |
| 2082 MockStorageClient* client4 = CreateClient(kData4, arraysize(kData4), | |
| 2083 QuotaClient::kIndexedDatabase); | |
| 2084 RegisterClient(client1); | |
| 2085 RegisterClient(client2); | |
| 2086 RegisterClient(client3); | |
| 2087 RegisterClient(client4); | |
| 2088 | |
| 2089 GetHostUsage("foo.com", kTemp); | |
| 2090 base::RunLoop().RunUntilIdle(); | |
| 2091 const int64_t predelete_foo_tmp = usage(); | |
| 2092 | |
| 2093 DeleteHostData("foo.com", kTemp, QuotaClient::kFileSystem); | |
| 2094 base::RunLoop().RunUntilIdle(); | |
| 2095 GetHostUsage("foo.com", kTemp); | |
| 2096 base::RunLoop().RunUntilIdle(); | |
| 2097 EXPECT_EQ(predelete_foo_tmp - 1, usage()); | |
| 2098 | |
| 2099 DeleteHostData("foo.com", kTemp, QuotaClient::kAppcache); | |
| 2100 base::RunLoop().RunUntilIdle(); | |
| 2101 GetHostUsage("foo.com", kTemp); | |
| 2102 base::RunLoop().RunUntilIdle(); | |
| 2103 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | |
| 2104 | |
| 2105 DeleteHostData("foo.com", kTemp, QuotaClient::kDatabase); | |
| 2106 base::RunLoop().RunUntilIdle(); | |
| 2107 GetHostUsage("foo.com", kTemp); | |
| 2108 base::RunLoop().RunUntilIdle(); | |
| 2109 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); | |
| 2110 | |
| 2111 DeleteHostData("foo.com", kTemp, QuotaClient::kIndexedDatabase); | |
| 2112 base::RunLoop().RunUntilIdle(); | |
| 2113 GetHostUsage("foo.com", kTemp); | |
| 2114 base::RunLoop().RunUntilIdle(); | |
| 2115 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | |
| 2116 } | |
| 2117 | |
| 2118 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleOrigin) { | |
| 2119 static const MockOriginData kData1[] = { | |
| 2120 { "http://foo.com/", kTemp, 1 }, | |
| 2121 }; | |
| 2122 static const MockOriginData kData2[] = { | |
| 2123 { "http://foo.com/", kTemp, 2 }, | |
| 2124 }; | |
| 2125 static const MockOriginData kData3[] = { | |
| 2126 { "http://foo.com/", kTemp, 4 }, | |
| 2127 }; | |
| 2128 static const MockOriginData kData4[] = { | |
| 2129 { "http://foo.com/", kTemp, 8 }, | |
| 2130 }; | |
| 2131 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 2132 QuotaClient::kFileSystem); | |
| 2133 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 2134 QuotaClient::kAppcache); | |
| 2135 MockStorageClient* client3 = CreateClient(kData3, arraysize(kData3), | |
| 2136 QuotaClient::kDatabase); | |
| 2137 MockStorageClient* client4 = CreateClient(kData4, arraysize(kData4), | |
| 2138 QuotaClient::kIndexedDatabase); | |
| 2139 RegisterClient(client1); | |
| 2140 RegisterClient(client2); | |
| 2141 RegisterClient(client3); | |
| 2142 RegisterClient(client4); | |
| 2143 | |
| 2144 GetHostUsage("foo.com", kTemp); | |
| 2145 base::RunLoop().RunUntilIdle(); | |
| 2146 const int64_t predelete_foo_tmp = usage(); | |
| 2147 | |
| 2148 DeleteOriginData(GURL("http://foo.com/"), kTemp, | |
| 2149 QuotaClient::kFileSystem | QuotaClient::kDatabase); | |
| 2150 base::RunLoop().RunUntilIdle(); | |
| 2151 GetHostUsage("foo.com", kTemp); | |
| 2152 base::RunLoop().RunUntilIdle(); | |
| 2153 EXPECT_EQ(predelete_foo_tmp - 4 - 1, usage()); | |
| 2154 | |
| 2155 DeleteOriginData(GURL("http://foo.com/"), kTemp, | |
| 2156 QuotaClient::kAppcache | QuotaClient::kIndexedDatabase); | |
| 2157 base::RunLoop().RunUntilIdle(); | |
| 2158 GetHostUsage("foo.com", kTemp); | |
| 2159 base::RunLoop().RunUntilIdle(); | |
| 2160 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | |
| 2161 } | |
| 2162 | |
| 2163 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleHost) { | |
| 2164 static const MockOriginData kData1[] = { | |
| 2165 { "http://foo.com:1111/", kTemp, 1 }, | |
| 2166 }; | |
| 2167 static const MockOriginData kData2[] = { | |
| 2168 { "http://foo.com:2222/", kTemp, 2 }, | |
| 2169 }; | |
| 2170 static const MockOriginData kData3[] = { | |
| 2171 { "http://foo.com:3333/", kTemp, 4 }, | |
| 2172 }; | |
| 2173 static const MockOriginData kData4[] = { | |
| 2174 { "http://foo.com:4444/", kTemp, 8 }, | |
| 2175 }; | |
| 2176 MockStorageClient* client1 = CreateClient(kData1, arraysize(kData1), | |
| 2177 QuotaClient::kFileSystem); | |
| 2178 MockStorageClient* client2 = CreateClient(kData2, arraysize(kData2), | |
| 2179 QuotaClient::kAppcache); | |
| 2180 MockStorageClient* client3 = CreateClient(kData3, arraysize(kData3), | |
| 2181 QuotaClient::kDatabase); | |
| 2182 MockStorageClient* client4 = CreateClient(kData4, arraysize(kData4), | |
| 2183 QuotaClient::kIndexedDatabase); | |
| 2184 RegisterClient(client1); | |
| 2185 RegisterClient(client2); | |
| 2186 RegisterClient(client3); | |
| 2187 RegisterClient(client4); | |
| 2188 | |
| 2189 GetHostUsage("foo.com", kTemp); | |
| 2190 base::RunLoop().RunUntilIdle(); | |
| 2191 const int64_t predelete_foo_tmp = usage(); | |
| 2192 | |
| 2193 DeleteHostData("foo.com", kTemp, | |
| 2194 QuotaClient::kFileSystem | QuotaClient::kAppcache); | |
| 2195 base::RunLoop().RunUntilIdle(); | |
| 2196 GetHostUsage("foo.com", kTemp); | |
| 2197 base::RunLoop().RunUntilIdle(); | |
| 2198 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | |
| 2199 | |
| 2200 DeleteHostData("foo.com", kTemp, | |
| 2201 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); | |
| 2202 base::RunLoop().RunUntilIdle(); | |
| 2203 GetHostUsage("foo.com", kTemp); | |
| 2204 base::RunLoop().RunUntilIdle(); | |
| 2205 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | |
| 2206 } | |
| 2207 | |
| 2208 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) { | |
| 2209 ResetQuotaManager(true); | |
| 2210 | |
| 2211 static const MockOriginData kData[] = { | |
| 2212 { "http://foo.com/", kTemp, 10 }, | |
| 2213 { "http://foo.com/", kPerm, 80 }, | |
| 2214 }; | |
| 2215 RegisterClient(CreateClient(kData, arraysize(kData), | |
| 2216 QuotaClient::kFileSystem)); | |
| 2217 | |
| 2218 // Query global usage to warmup the usage tracker caching. | |
| 2219 GetGlobalUsage(kTemp); | |
| 2220 GetGlobalUsage(kPerm); | |
| 2221 base::RunLoop().RunUntilIdle(); | |
| 2222 | |
| 2223 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 2224 base::RunLoop().RunUntilIdle(); | |
| 2225 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 2226 EXPECT_EQ(80, usage()); | |
| 2227 EXPECT_EQ(0, quota()); | |
| 2228 | |
| 2229 const int kPoolSize = 1000; | |
| 2230 const int kPerHostQuota = kPoolSize / 5; | |
| 2231 SetQuotaSettings(kPoolSize, kPerHostQuota, INT64_C(0)); | |
| 2232 | |
| 2233 GetStorageCapacity(); | |
| 2234 base::RunLoop().RunUntilIdle(); | |
| 2235 EXPECT_EQ(kPoolSize, total_space()); | |
| 2236 EXPECT_EQ(kPoolSize - 80 - 10, available_space()); | |
| 2237 | |
| 2238 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 2239 base::RunLoop().RunUntilIdle(); | |
| 2240 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 2241 EXPECT_EQ(10, usage()); | |
| 2242 EXPECT_LE(kPerHostQuota, quota()); | |
| 2243 | |
| 2244 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); | |
| 2245 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | |
| 2246 base::RunLoop().RunUntilIdle(); | |
| 2247 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 2248 EXPECT_EQ(80, usage()); | |
| 2249 EXPECT_EQ(available_space() + usage(), quota()); | |
| 2250 | |
| 2251 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | |
| 2252 base::RunLoop().RunUntilIdle(); | |
| 2253 EXPECT_EQ(kQuotaStatusOk, status()); | |
| 2254 EXPECT_EQ(10, usage()); | |
| 2255 EXPECT_EQ(available_space() + usage(), quota()); | |
| 2256 } | |
| 2257 | |
| 2258 TEST_F(QuotaManagerTest, GetUsageAndQuota_SessionOnly) { | |
| 2259 const GURL kEpheremalOrigin("http://ephemeral/"); | |
| 2260 mock_special_storage_policy()->AddSessionOnly(kEpheremalOrigin); | |
| 2261 | |
| 2262 GetUsageAndQuotaForWebApps(kEpheremalOrigin, kTemp); | |
| 2263 base::RunLoop().RunUntilIdle(); | |
| 2264 EXPECT_EQ(quota_manager()->settings().session_only_per_host_quota, quota()); | |
| 2265 | |
| 2266 GetUsageAndQuotaForWebApps(kEpheremalOrigin, kPerm); | |
| 2267 base::RunLoop().RunUntilIdle(); | |
| 2268 EXPECT_EQ(0, quota()); | |
| 2269 } | |
| 2270 | |
| 2271 } // namespace content | |
| OLD | NEW |