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