Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: content/browser/quota/quota_manager_unittest.cc

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 26 matching lines...) Expand all
37 using storage::kQuotaStatusOk; 37 using storage::kQuotaStatusOk;
38 using storage::kQuotaStatusUnknown; 38 using storage::kQuotaStatusUnknown;
39 using storage::kStorageTypePersistent; 39 using storage::kStorageTypePersistent;
40 using storage::kStorageTypeSyncable; 40 using storage::kStorageTypeSyncable;
41 using storage::kStorageTypeTemporary; 41 using storage::kStorageTypeTemporary;
42 using storage::kStorageTypeUnknown; 42 using storage::kStorageTypeUnknown;
43 using storage::QuotaClient; 43 using storage::QuotaClient;
44 using storage::QuotaManager; 44 using storage::QuotaManager;
45 using storage::QuotaStatusCode; 45 using storage::QuotaStatusCode;
46 using storage::StorageType; 46 using storage::StorageType;
47 using storage::UsageAndQuota;
48 using storage::UsageInfo; 47 using storage::UsageInfo;
49 using storage::UsageInfoEntries; 48 using storage::UsageInfoEntries;
50 49
51 namespace content { 50 namespace content {
52 51
53 namespace { 52 namespace {
54 53
55 // For shorter names. 54 // For shorter names.
56 const StorageType kTemp = kStorageTypeTemporary; 55 const StorageType kTemp = kStorageTypeTemporary;
57 const StorageType kPerm = kStorageTypePersistent; 56 const StorageType kPerm = kStorageTypePersistent;
58 const StorageType kSync = kStorageTypeSyncable; 57 const StorageType kSync = kStorageTypeSyncable;
59 58
60 const int kAllClients = QuotaClient::kAllClientsMask; 59 const int kAllClients = QuotaClient::kAllClientsMask;
61 60
62 const int64_t kAvailableSpaceForApp = 13377331U; 61 const int64_t kAvailableSpaceForApp = 13377331U;
63 62 const int64_t kMustRemainAvailableForSystem = kAvailableSpaceForApp / 2;
64 const int64_t kMinimumPreserveForSystem = 63 const int64_t kDefaultPoolSize = 1000;
cmumford 2016/10/25 20:30:54 Could add units to these values (either as a comme
michaeln 2016/10/26 21:47:53 Done.
65 QuotaManager::kMinimumPreserveForSystem; 64 const int64_t kDefaultPerHostQuota = 200;
66 const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion;
67 65
68 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); 66 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result");
69 67
70 // Returns a deterministic value for the amount of available disk space. 68 // Returns a deterministic value for the amount of available disk space.
71 int64_t GetAvailableDiskSpaceForTest() { 69 int64_t GetAvailableDiskSpaceForTest() {
72 return kAvailableSpaceForApp + kMinimumPreserveForSystem; 70 return kAvailableSpaceForApp + kMustRemainAvailableForSystem;
73 } 71 }
74 72
75 bool GetVolumeInfoForTests(const base::FilePath&, 73 // base::Optional<>
76 uint64_t* available, uint64_t* total) { 74 std::pair<int64_t, int64_t> GetVolumeInfoForTests(
cmumford 2016/10/25 20:30:54 Is the base::Optional comment a TODO?
michaeln 2016/10/26 21:47:53 yes :)
77 *available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); 75 const base::FilePath& unused) {
78 *total = *available * 2; 76 int64_t available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest());
79 return true; 77 int64_t total = available * 2;
78 return std::make_pair(total, available);
80 } 79 }
81 80
82 class TestEvictionPolicy : public storage::QuotaEvictionPolicy { 81 class TestEvictionPolicy : public storage::QuotaEvictionPolicy {
83 public: 82 public:
84 TestEvictionPolicy() {} 83 TestEvictionPolicy() {}
85 ~TestEvictionPolicy() override {} 84 ~TestEvictionPolicy() override {}
86 85
87 // Overridden from storage::QuotaEvictionPolicy: 86 // Overridden from storage::QuotaEvictionPolicy:
88 void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& 87 void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>&
89 special_storage_policy, 88 special_storage_policy,
(...skipping 26 matching lines...) Expand all
116 } 115 }
117 116
118 void TearDown() override { 117 void TearDown() override {
119 // Make sure the quota manager cleans up correctly. 118 // Make sure the quota manager cleans up correctly.
120 quota_manager_ = NULL; 119 quota_manager_ = NULL;
121 base::RunLoop().RunUntilIdle(); 120 base::RunLoop().RunUntilIdle();
122 } 121 }
123 122
124 protected: 123 protected:
125 void ResetQuotaManager(bool is_incognito) { 124 void ResetQuotaManager(bool is_incognito) {
126 quota_manager_ = new QuotaManager(is_incognito, data_dir_.GetPath(), 125 quota_manager_ = new QuotaManager(
127 base::ThreadTaskRunnerHandle::Get().get(), 126 is_incognito, data_dir_.GetPath(),
128 base::ThreadTaskRunnerHandle::Get().get(), 127 base::ThreadTaskRunnerHandle::Get().get(),
129 mock_special_storage_policy_.get()); 128 base::ThreadTaskRunnerHandle::Get().get(),
129 mock_special_storage_policy_.get(),
130 storage::GetTemporaryStorageConfigurationFunc());
131 SetStorageConfig(kDefaultPoolSize, kDefaultPerHostQuota,
132 kMustRemainAvailableForSystem);
133
130 // Don't (automatically) start the eviction for testing. 134 // Don't (automatically) start the eviction for testing.
131 quota_manager_->eviction_disabled_ = true; 135 quota_manager_->eviction_disabled_ = true;
132 // Don't query the hard disk for remaining capacity. 136 // Don't query the hard disk for remaining capacity.
133 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests; 137 quota_manager_->get_volume_info_fn_= &GetVolumeInfoForTests;
134 additional_callback_count_ = 0; 138 additional_callback_count_ = 0;
135 } 139 }
136 140
137 MockStorageClient* CreateClient( 141 MockStorageClient* CreateClient(
138 const MockOriginData* mock_data, 142 const MockOriginData* mock_data,
139 size_t mock_data_size, 143 size_t mock_data_size,
(...skipping 26 matching lines...) Expand all
166 void GetUsageAndQuotaForStorageClient(const GURL& origin, 170 void GetUsageAndQuotaForStorageClient(const GURL& origin,
167 StorageType type) { 171 StorageType type) {
168 quota_status_ = kQuotaStatusUnknown; 172 quota_status_ = kQuotaStatusUnknown;
169 usage_ = -1; 173 usage_ = -1;
170 quota_ = -1; 174 quota_ = -1;
171 quota_manager_->GetUsageAndQuota( 175 quota_manager_->GetUsageAndQuota(
172 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, 176 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota,
173 weak_factory_.GetWeakPtr())); 177 weak_factory_.GetWeakPtr()));
174 } 178 }
175 179
176 void GetTemporaryGlobalQuota() { 180 void SetStorageConfig(int64_t pool_size,
177 quota_status_ = kQuotaStatusUnknown; 181 int64_t per_host_quota,
178 quota_ = -1; 182 int64_t must_remain_available) {
179 quota_manager_->GetTemporaryGlobalQuota( 183 storage::TemporaryStorageConfiguration config;
180 base::Bind(&QuotaManagerTest::DidGetQuota, 184 config.pool_size = pool_size;
181 weak_factory_.GetWeakPtr())); 185 config.per_host_quota = per_host_quota;
182 } 186 config.must_remain_available = must_remain_available;
183 187 config.refresh_interval = base::TimeDelta::Max();
184 void SetTemporaryGlobalQuota(int64_t new_quota) { 188 quota_manager_->SetTemporaryStorageConfiguration(config);
185 quota_status_ = kQuotaStatusUnknown;
186 quota_ = -1;
187 quota_manager_->SetTemporaryGlobalOverrideQuota(
188 new_quota,
189 base::Bind(&QuotaManagerTest::DidGetQuota,
190 weak_factory_.GetWeakPtr()));
191 } 189 }
192 190
193 void GetPersistentHostQuota(const std::string& host) { 191 void GetPersistentHostQuota(const std::string& host) {
194 quota_status_ = kQuotaStatusUnknown; 192 quota_status_ = kQuotaStatusUnknown;
195 quota_ = -1; 193 quota_ = -1;
196 quota_manager_->GetPersistentHostQuota( 194 quota_manager_->GetPersistentHostQuota(
197 host, 195 host,
198 base::Bind(&QuotaManagerTest::DidGetHostQuota, 196 base::Bind(&QuotaManagerTest::DidGetHostQuota,
199 weak_factory_.GetWeakPtr())); 197 weak_factory_.GetWeakPtr()));
200 } 198 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void DeleteHostData(const std::string& host, 263 void DeleteHostData(const std::string& host,
266 StorageType type, 264 StorageType type,
267 int quota_client_mask) { 265 int quota_client_mask) {
268 quota_status_ = kQuotaStatusUnknown; 266 quota_status_ = kQuotaStatusUnknown;
269 quota_manager_->DeleteHostData( 267 quota_manager_->DeleteHostData(
270 host, type, quota_client_mask, 268 host, type, quota_client_mask,
271 base::Bind(&QuotaManagerTest::StatusCallback, 269 base::Bind(&QuotaManagerTest::StatusCallback,
272 weak_factory_.GetWeakPtr())); 270 weak_factory_.GetWeakPtr()));
273 } 271 }
274 272
275 void GetAvailableSpace() { 273 void GetDeviceStorageCapacity() {
276 quota_status_ = kQuotaStatusUnknown;
277 available_space_ = -1; 274 available_space_ = -1;
278 quota_manager_->GetAvailableSpace( 275 total_space_ = -1;
279 base::Bind(&QuotaManagerTest::DidGetAvailableSpace, 276 quota_manager_->GetDeviceStorageCapacity(
277 base::Bind(&QuotaManagerTest::DidGetStorageCapacity,
280 weak_factory_.GetWeakPtr())); 278 weak_factory_.GetWeakPtr()));
281 } 279 }
282 280
283 void GetUsageAndQuotaForEviction() { 281 void GetEvictionRoundInfo() {
284 quota_status_ = kQuotaStatusUnknown; 282 quota_status_ = kQuotaStatusUnknown;
283 config_ = storage::TemporaryStorageConfiguration();
284 available_space_ = -1;
285 total_space_ = -1;
285 usage_ = -1; 286 usage_ = -1;
286 unlimited_usage_ = -1; 287 quota_manager_->GetEvictionRoundInfo(
287 quota_ = -1; 288 base::Bind(&QuotaManagerTest::DidGetEvictionRoundInfo,
288 available_space_ = -1;
289 quota_manager_->GetUsageAndQuotaForEviction(
290 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction,
291 weak_factory_.GetWeakPtr())); 289 weak_factory_.GetWeakPtr()));
292 } 290 }
293 291
294 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { 292 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) {
295 ASSERT_TRUE(origins != NULL); 293 ASSERT_TRUE(origins != NULL);
296 origins->clear(); 294 origins->clear();
297 quota_manager_->GetCachedOrigins(type, origins); 295 quota_manager_->GetCachedOrigins(type, origins);
298 } 296 }
299 297
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, 298 void NotifyStorageAccessed(QuotaClient* client,
307 const GURL& origin, 299 const GURL& origin,
308 StorageType type) { 300 StorageType type) {
309 DCHECK(client); 301 DCHECK(client);
310 quota_manager_->NotifyStorageAccessedInternal( 302 quota_manager_->NotifyStorageAccessedInternal(
311 client->id(), origin, type, IncrementMockTime()); 303 client->id(), origin, type, IncrementMockTime());
312 } 304 }
313 305
314 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { 306 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) {
315 quota_manager_->DeleteOriginFromDatabase(origin, type, false); 307 quota_manager_->DeleteOriginFromDatabase(origin, type, false);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 quota_status_ = status; 358 quota_status_ = status;
367 usage_ = usage; 359 usage_ = usage;
368 quota_ = quota; 360 quota_ = quota;
369 } 361 }
370 362
371 void DidGetQuota(QuotaStatusCode status, int64_t quota) { 363 void DidGetQuota(QuotaStatusCode status, int64_t quota) {
372 quota_status_ = status; 364 quota_status_ = status;
373 quota_ = quota; 365 quota_ = quota;
374 } 366 }
375 367
376 void DidGetAvailableSpace(QuotaStatusCode status, int64_t available_space) { 368 void DidGetStorageCapacity(int64_t total_space, int64_t available_space) {
377 quota_status_ = status; 369 total_space_ = total_space;
378 available_space_ = available_space; 370 available_space_ = available_space;
379 } 371 }
380 372
381 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) { 373 void DidGetHostQuota(QuotaStatusCode status, int64_t quota) {
382 quota_status_ = status; 374 quota_status_ = status;
383 quota_ = quota; 375 quota_ = quota;
384 } 376 }
385 377
386 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) { 378 void DidGetGlobalUsage(int64_t usage, int64_t unlimited_usage) {
387 usage_ = usage; 379 usage_ = usage;
388 unlimited_usage_ = unlimited_usage; 380 unlimited_usage_ = unlimited_usage;
389 } 381 }
390 382
391 void DidGetHostUsage(int64_t usage) { usage_ = usage; } 383 void DidGetHostUsage(int64_t usage) { usage_ = usage; }
392 384
393 void StatusCallback(QuotaStatusCode status) { 385 void StatusCallback(QuotaStatusCode status) {
394 ++status_callback_count_; 386 ++status_callback_count_;
395 quota_status_ = status; 387 quota_status_ = status;
396 } 388 }
397 389
398 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, 390 void DidGetEvictionRoundInfo(
399 const UsageAndQuota& usage_and_quota) { 391 QuotaStatusCode status,
392 const storage::TemporaryStorageConfiguration& config,
393 int64_t available_space, int64_t total_space,
394 int64_t global_usage, bool global_usage_is_complete) {
400 quota_status_ = status; 395 quota_status_ = status;
401 limited_usage_ = usage_and_quota.global_limited_usage; 396 config_ = config;
402 quota_ = usage_and_quota.quota; 397 available_space_ = available_space;
403 available_space_ = usage_and_quota.available_disk_space; 398 total_space_ = total_space;
399 usage_ = global_usage;
404 } 400 }
405 401
406 void DidGetEvictionOrigin(const GURL& origin) { 402 void DidGetEvictionOrigin(const GURL& origin) {
407 eviction_origin_ = origin; 403 eviction_origin_ = origin;
408 } 404 }
409 405
410 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { 406 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) {
411 modified_origins_ = origins; 407 modified_origins_ = origins;
412 modified_origins_type_ = type; 408 modified_origins_type_ = type;
413 } 409 }
(...skipping 24 matching lines...) Expand all
438 MockSpecialStoragePolicy* mock_special_storage_policy() const { 434 MockSpecialStoragePolicy* mock_special_storage_policy() const {
439 return mock_special_storage_policy_.get(); 435 return mock_special_storage_policy_.get();
440 } 436 }
441 437
442 QuotaStatusCode status() const { return quota_status_; } 438 QuotaStatusCode status() const { return quota_status_; }
443 const UsageInfoEntries& usage_info() const { return usage_info_; } 439 const UsageInfoEntries& usage_info() const { return usage_info_; }
444 int64_t usage() const { return usage_; } 440 int64_t usage() const { return usage_; }
445 int64_t limited_usage() const { return limited_usage_; } 441 int64_t limited_usage() const { return limited_usage_; }
446 int64_t unlimited_usage() const { return unlimited_usage_; } 442 int64_t unlimited_usage() const { return unlimited_usage_; }
447 int64_t quota() const { return quota_; } 443 int64_t quota() const { return quota_; }
444 int64_t total_space() const { return total_space_; }
448 int64_t available_space() const { return available_space_; } 445 int64_t available_space() const { return available_space_; }
449 const GURL& eviction_origin() const { return eviction_origin_; } 446 const GURL& eviction_origin() const { return eviction_origin_; }
450 const std::set<GURL>& modified_origins() const { return modified_origins_; } 447 const std::set<GURL>& modified_origins() const { return modified_origins_; }
451 StorageType modified_origins_type() const { return modified_origins_type_; } 448 StorageType modified_origins_type() const { return modified_origins_type_; }
452 const QuotaTableEntries& quota_entries() const { return quota_entries_; } 449 const QuotaTableEntries& quota_entries() const { return quota_entries_; }
453 const OriginInfoTableEntries& origin_info_entries() const { 450 const OriginInfoTableEntries& origin_info_entries() const {
454 return origin_info_entries_; 451 return origin_info_entries_;
455 } 452 }
453 const storage::TemporaryStorageConfiguration& config() const {
454 return config_;
455 }
456 base::FilePath profile_path() const { return data_dir_.GetPath(); } 456 base::FilePath profile_path() const { return data_dir_.GetPath(); }
457 int status_callback_count() const { return status_callback_count_; } 457 int status_callback_count() const { return status_callback_count_; }
458 void reset_status_callback_count() { status_callback_count_ = 0; } 458 void reset_status_callback_count() { status_callback_count_ = 0; }
459 459
460 private: 460 private:
461 base::Time IncrementMockTime() { 461 base::Time IncrementMockTime() {
462 ++mock_time_counter_; 462 ++mock_time_counter_;
463 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); 463 return base::Time::FromDoubleT(mock_time_counter_ * 10.0);
464 } 464 }
465 465
466 base::MessageLoop message_loop_; 466 base::MessageLoop message_loop_;
467 base::ScopedTempDir data_dir_; 467 base::ScopedTempDir data_dir_;
468 468
469 scoped_refptr<QuotaManager> quota_manager_; 469 scoped_refptr<QuotaManager> quota_manager_;
470 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; 470 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_;
471 471
472 QuotaStatusCode quota_status_; 472 QuotaStatusCode quota_status_;
473 UsageInfoEntries usage_info_; 473 UsageInfoEntries usage_info_;
474 int64_t usage_; 474 int64_t usage_;
475 int64_t limited_usage_; 475 int64_t limited_usage_;
476 int64_t unlimited_usage_; 476 int64_t unlimited_usage_;
477 int64_t quota_; 477 int64_t quota_;
478 int64_t total_space_;
478 int64_t available_space_; 479 int64_t available_space_;
479 GURL eviction_origin_; 480 GURL eviction_origin_;
480 std::set<GURL> modified_origins_; 481 std::set<GURL> modified_origins_;
481 StorageType modified_origins_type_; 482 StorageType modified_origins_type_;
482 QuotaTableEntries quota_entries_; 483 QuotaTableEntries quota_entries_;
483 OriginInfoTableEntries origin_info_entries_; 484 OriginInfoTableEntries origin_info_entries_;
485 storage::TemporaryStorageConfiguration config_;
484 int status_callback_count_; 486 int status_callback_count_;
485 487
486 int additional_callback_count_; 488 int additional_callback_count_;
487 489
488 int mock_time_counter_; 490 int mock_time_counter_;
489 491
490 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; 492 base::WeakPtrFactory<QuotaManagerTest> weak_factory_;
491 493
492 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); 494 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest);
493 }; 495 };
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 { "http://foo.com:8080/", kTemp, 20 }, 628 { "http://foo.com:8080/", kTemp, 20 },
627 { "http://bar.com/", kTemp, 5 }, 629 { "http://bar.com/", kTemp, 5 },
628 { "https://bar.com/", kTemp, 7 }, 630 { "https://bar.com/", kTemp, 7 },
629 { "http://baz.com/", kTemp, 30 }, 631 { "http://baz.com/", kTemp, 30 },
630 { "http://foo.com/", kPerm, 40 }, 632 { "http://foo.com/", kPerm, 40 },
631 }; 633 };
632 RegisterClient(CreateClient(kData, arraysize(kData), 634 RegisterClient(CreateClient(kData, arraysize(kData),
633 QuotaClient::kFileSystem)); 635 QuotaClient::kFileSystem));
634 636
635 // This time explicitly sets a temporary global quota. 637 // This time explicitly sets a temporary global quota.
636 SetTemporaryGlobalQuota(100); 638 const int kPoolSize = 100;
637 base::RunLoop().RunUntilIdle(); 639 const int kPerHostQuota = 20;
638 EXPECT_EQ(kQuotaStatusOk, status()); 640 SetStorageConfig(kPoolSize, kPerHostQuota,
639 EXPECT_EQ(100, quota()); 641 kMustRemainAvailableForSystem);
640 642
641 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 643 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
642 base::RunLoop().RunUntilIdle(); 644 base::RunLoop().RunUntilIdle();
643 EXPECT_EQ(kQuotaStatusOk, status()); 645 EXPECT_EQ(kQuotaStatusOk, status());
644 EXPECT_EQ(10 + 20, usage()); 646 EXPECT_EQ(10 + 20, usage());
645 647
646 const int kPerHostQuota = 100 / kPerHostTemporaryPortion;
647
648 // The host's quota should be its full portion of the global quota 648 // The host's quota should be its full portion of the global quota
649 // since global usage is under the global quota. 649 // since there's plenty of diskspace.
650 EXPECT_EQ(kPerHostQuota, quota()); 650 EXPECT_EQ(kPerHostQuota, quota());
651 651
652 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp); 652 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp);
653 base::RunLoop().RunUntilIdle(); 653 base::RunLoop().RunUntilIdle();
654 EXPECT_EQ(kQuotaStatusOk, status()); 654 EXPECT_EQ(kQuotaStatusOk, status());
655 EXPECT_EQ(5 + 7, usage()); 655 EXPECT_EQ(5 + 7, usage());
656 EXPECT_EQ(kPerHostQuota, quota()); 656 EXPECT_EQ(kPerHostQuota, quota());
657 } 657 }
658 658
659 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { 659 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) {
(...skipping 10 matching lines...) Expand all
670 { "http://unlimited/", kTemp, 512 }, 670 { "http://unlimited/", kTemp, 512 },
671 { "http://installed/", kTemp, 1024 }, 671 { "http://installed/", kTemp, 1024 },
672 }; 672 };
673 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); 673 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
674 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); 674 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/"));
675 RegisterClient(CreateClient(kData1, arraysize(kData1), 675 RegisterClient(CreateClient(kData1, arraysize(kData1),
676 QuotaClient::kFileSystem)); 676 QuotaClient::kFileSystem));
677 RegisterClient(CreateClient(kData2, arraysize(kData2), 677 RegisterClient(CreateClient(kData2, arraysize(kData2),
678 QuotaClient::kDatabase)); 678 QuotaClient::kDatabase));
679 679
680 const int64_t kTempQuotaBase = 680 const int64_t kPoolSize = 100;
681 GetAvailableDiskSpaceForTest() / kPerHostTemporaryPortion; 681 const int64_t kPerHostQuota = 20;
682 SetStorageConfig(kPoolSize, kPerHostQuota,
683 kMustRemainAvailableForSystem);
682 684
683 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 685 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
684 base::RunLoop().RunUntilIdle(); 686 base::RunLoop().RunUntilIdle();
685 EXPECT_EQ(kQuotaStatusOk, status()); 687 EXPECT_EQ(kQuotaStatusOk, status());
686 EXPECT_EQ(1 + 128, usage()); 688 EXPECT_EQ(1 + 128, usage());
687 689
688 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm); 690 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm);
689 base::RunLoop().RunUntilIdle(); 691 base::RunLoop().RunUntilIdle();
690 EXPECT_EQ(kQuotaStatusOk, status()); 692 EXPECT_EQ(kQuotaStatusOk, status());
691 EXPECT_EQ(4, usage()); 693 EXPECT_EQ(4, usage());
692 694
693 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); 695 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
694 base::RunLoop().RunUntilIdle(); 696 base::RunLoop().RunUntilIdle();
695 EXPECT_EQ(kQuotaStatusOk, status()); 697 EXPECT_EQ(kQuotaStatusOk, status());
696 EXPECT_EQ(512, usage()); 698 EXPECT_EQ(512, usage());
697 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota()); 699 EXPECT_EQ(std::min(kAvailableSpaceForApp, kPerHostQuota) + usage(), quota());
698 700
699 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); 701 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm);
700 base::RunLoop().RunUntilIdle(); 702 base::RunLoop().RunUntilIdle();
701 EXPECT_EQ(kQuotaStatusOk, status()); 703 EXPECT_EQ(kQuotaStatusOk, status());
702 EXPECT_EQ(8, usage()); 704 EXPECT_EQ(8, usage());
703 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); 705 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
704 706
705 GetAvailableSpace();
706 base::RunLoop().RunUntilIdle();
707 EXPECT_EQ(kQuotaStatusOk, status());
708 EXPECT_LE(0, available_space());
709
710 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kTemp); 707 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kTemp);
711 base::RunLoop().RunUntilIdle(); 708 base::RunLoop().RunUntilIdle();
712 EXPECT_EQ(kQuotaStatusOk, status()); 709 EXPECT_EQ(kQuotaStatusOk, status());
713 EXPECT_EQ(1024, usage()); 710 EXPECT_EQ(1024, usage());
714 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota()); 711 EXPECT_EQ(std::min(kAvailableSpaceForApp, kPerHostQuota) + usage(), quota());
715 712
716 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); 713 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm);
717 base::RunLoop().RunUntilIdle(); 714 base::RunLoop().RunUntilIdle();
718 EXPECT_EQ(kQuotaStatusOk, status()); 715 EXPECT_EQ(kQuotaStatusOk, status());
719 EXPECT_EQ(16, usage()); 716 EXPECT_EQ(16, usage());
720 EXPECT_EQ(usage(), quota()); // Over-budget case. 717 EXPECT_EQ(usage(), quota()); // Over-budget case. todo:bug
721 718
722 GetGlobalUsage(kTemp); 719 GetGlobalUsage(kTemp);
723 base::RunLoop().RunUntilIdle(); 720 base::RunLoop().RunUntilIdle();
724 EXPECT_EQ(kQuotaStatusOk, status()); 721 EXPECT_EQ(kQuotaStatusOk, status());
725 EXPECT_EQ(1 + 2 + 128 + 512 + 1024, usage()); 722 EXPECT_EQ(1 + 2 + 128 + 512 + 1024, usage());
726 EXPECT_EQ(512, unlimited_usage()); 723 EXPECT_EQ(512, unlimited_usage());
727 724
728 GetGlobalUsage(kPerm); 725 GetGlobalUsage(kPerm);
729 base::RunLoop().RunUntilIdle(); 726 base::RunLoop().RunUntilIdle();
730 EXPECT_EQ(kQuotaStatusOk, status()); 727 EXPECT_EQ(kQuotaStatusOk, status());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 771
775 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { 772 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) {
776 static const MockOriginData kData[] = { 773 static const MockOriginData kData[] = {
777 { "http://foo.com/", kTemp, 10 }, 774 { "http://foo.com/", kTemp, 10 },
778 { "http://foo.com:8080/", kTemp, 20 }, 775 { "http://foo.com:8080/", kTemp, 20 },
779 { "http://bar.com/", kTemp, 13 }, 776 { "http://bar.com/", kTemp, 13 },
780 { "http://foo.com/", kPerm, 40 }, 777 { "http://foo.com/", kPerm, 40 },
781 }; 778 };
782 RegisterClient(CreateClient(kData, arraysize(kData), 779 RegisterClient(CreateClient(kData, arraysize(kData),
783 QuotaClient::kFileSystem)); 780 QuotaClient::kFileSystem));
784 SetTemporaryGlobalQuota(100);
785 base::RunLoop().RunUntilIdle();
786 781
787 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; 782 const int kPoolSize = 100;
783 const int kPerHostQuota = 20;
784 SetStorageConfig(kPoolSize, kPerHostQuota,
785 kMustRemainAvailableForSystem);
788 786
789 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 787 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
790 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 788 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
791 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 789 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
792 base::RunLoop().RunUntilIdle(); 790 base::RunLoop().RunUntilIdle();
793 EXPECT_EQ(kQuotaStatusOk, status()); 791 EXPECT_EQ(kQuotaStatusOk, status());
794 EXPECT_EQ(10 + 20, usage()); 792 EXPECT_EQ(10 + 20, usage());
795 EXPECT_EQ(kPerHostQuota, quota()); 793 EXPECT_EQ(kPerHostQuota, quota());
796 794
797 set_additional_callback_count(0); 795 set_additional_callback_count(0);
(...skipping 10 matching lines...) Expand all
808 806
809 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { 807 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) {
810 static const MockOriginData kData[] = { 808 static const MockOriginData kData[] = {
811 { "http://foo.com/", kTemp, 10 }, 809 { "http://foo.com/", kTemp, 10 },
812 { "http://foo.com:8080/", kTemp, 20 }, 810 { "http://foo.com:8080/", kTemp, 20 },
813 { "http://bar.com/", kTemp, 13 }, 811 { "http://bar.com/", kTemp, 13 },
814 { "http://foo.com/", kPerm, 40 }, 812 { "http://foo.com/", kPerm, 40 },
815 }; 813 };
816 RegisterClient(CreateClient(kData, arraysize(kData), 814 RegisterClient(CreateClient(kData, arraysize(kData),
817 QuotaClient::kFileSystem)); 815 QuotaClient::kFileSystem));
818 SetTemporaryGlobalQuota(100); 816 const int kPoolSize = 100;
819 base::RunLoop().RunUntilIdle(); 817 const int kPerHostQuota = 20;
818 SetStorageConfig(kPoolSize, kPerHostQuota,
819 kMustRemainAvailableForSystem);
820 820
821 set_additional_callback_count(0); 821 set_additional_callback_count(0);
822 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 822 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
823 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), 823 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
824 kTemp); 824 kTemp);
825 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), 825 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
826 kTemp); 826 kTemp);
827 827
828 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); 828 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
829 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); 829 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients);
830 830
831 // Nuke before waiting for callbacks. 831 // Nuke before waiting for callbacks.
832 set_quota_manager(NULL); 832 set_quota_manager(NULL);
833 base::RunLoop().RunUntilIdle(); 833 base::RunLoop().RunUntilIdle();
834 EXPECT_EQ(kQuotaErrorAbort, status()); 834 EXPECT_EQ(kQuotaErrorAbort, status());
835 } 835 }
836 836
837 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { 837 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) {
838 static const MockOriginData kData[] = { 838 static const MockOriginData kData[] = {
839 { "http://usage1/", kTemp, 1 }, 839 { "http://usage1/", kTemp, 1 },
840 { "http://usage10/", kTemp, 10 }, 840 { "http://usage10/", kTemp, 10 },
841 { "http://usage200/", kTemp, 200 }, 841 { "http://usage200/", kTemp, 200 },
842 }; 842 };
843 RegisterClient(CreateClient(kData, arraysize(kData), 843 RegisterClient(CreateClient(kData, arraysize(kData),
844 QuotaClient::kFileSystem)); 844 QuotaClient::kFileSystem));
845 SetTemporaryGlobalQuota(100); 845 const int kPoolSize = 100;
846 base::RunLoop().RunUntilIdle(); 846 const int kPerHostQuota = 20;
847 SetStorageConfig(kPoolSize, kPerHostQuota,
848 kMustRemainAvailableForSystem);
847 849
848 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; 850 // not sure this test is relevant anymore?
849 851
850 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); 852 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp);
851 base::RunLoop().RunUntilIdle(); 853 base::RunLoop().RunUntilIdle();
852 EXPECT_EQ(kQuotaStatusOk, status()); 854 EXPECT_EQ(kQuotaStatusOk, status());
853 EXPECT_EQ(1, usage()); 855 EXPECT_EQ(1, usage());
854 EXPECT_EQ(1, quota()); // should be clamped to our current usage 856 EXPECT_EQ(kPerHostQuota, quota());
855 857
856 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); 858 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
857 base::RunLoop().RunUntilIdle(); 859 base::RunLoop().RunUntilIdle();
858 EXPECT_EQ(kQuotaStatusOk, status()); 860 EXPECT_EQ(kQuotaStatusOk, status());
859 EXPECT_EQ(10, usage()); 861 EXPECT_EQ(10, usage());
860 EXPECT_EQ(10, quota()); 862 EXPECT_EQ(kPerHostQuota, quota());
861 863
862 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); 864 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp);
863 base::RunLoop().RunUntilIdle(); 865 base::RunLoop().RunUntilIdle();
864 EXPECT_EQ(kQuotaStatusOk, status()); 866 EXPECT_EQ(kQuotaStatusOk, status());
865 EXPECT_EQ(200, usage()); 867 EXPECT_EQ(200, usage());
866 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota 868 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota
867 } 869 }
868 870
869 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { 871 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
870 static const MockOriginData kData[] = { 872 static const MockOriginData kData[] = {
871 { "http://usage10/", kTemp, 10 }, 873 { "http://usage10/", kTemp, 10 },
872 { "http://usage50/", kTemp, 50 }, 874 { "http://usage50/", kTemp, 50 },
873 { "http://unlimited/", kTemp, 4000 }, 875 { "http://unlimited/", kTemp, 4000 },
874 }; 876 };
875 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); 877 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
876 MockStorageClient* client = CreateClient(kData, arraysize(kData), 878 MockStorageClient* client = CreateClient(kData, arraysize(kData),
877 QuotaClient::kFileSystem); 879 QuotaClient::kFileSystem);
878 RegisterClient(client); 880 RegisterClient(client);
879 881
880 // Test when not overbugdet. 882 // Test when not overbugdet.
881 SetTemporaryGlobalQuota(1000); 883 const int kPerHostQuotaFor1000 = 200;
882 base::RunLoop().RunUntilIdle(); 884 SetStorageConfig(1000, kPerHostQuotaFor1000, kMustRemainAvailableForSystem);
883 885
884 GetGlobalUsage(kTemp); 886 GetGlobalUsage(kTemp);
885 base::RunLoop().RunUntilIdle(); 887 base::RunLoop().RunUntilIdle();
886 EXPECT_EQ(10 + 50 + 4000, usage()); 888 EXPECT_EQ(10 + 50 + 4000, usage());
887 EXPECT_EQ(4000, unlimited_usage()); 889 EXPECT_EQ(4000, unlimited_usage());
888 890
889 const int kPerHostQuotaFor1000 =
890 1000 / QuotaManager::kPerHostTemporaryPortion;
891
892 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); 891 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
893 base::RunLoop().RunUntilIdle(); 892 base::RunLoop().RunUntilIdle();
894 EXPECT_EQ(kQuotaStatusOk, status()); 893 EXPECT_EQ(kQuotaStatusOk, status());
895 EXPECT_EQ(10, usage()); 894 EXPECT_EQ(10, usage());
896 EXPECT_EQ(kPerHostQuotaFor1000, quota()); 895 EXPECT_EQ(kPerHostQuotaFor1000, quota());
897 896
898 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); 897 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
899 base::RunLoop().RunUntilIdle(); 898 base::RunLoop().RunUntilIdle();
900 EXPECT_EQ(kQuotaStatusOk, status()); 899 EXPECT_EQ(kQuotaStatusOk, status());
901 EXPECT_EQ(50, usage()); 900 EXPECT_EQ(50, usage());
902 EXPECT_EQ(kPerHostQuotaFor1000, quota()); 901 EXPECT_EQ(kPerHostQuotaFor1000, quota());
903 902
904 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); 903 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
905 base::RunLoop().RunUntilIdle(); 904 base::RunLoop().RunUntilIdle();
906 EXPECT_EQ(kQuotaStatusOk, status()); 905 EXPECT_EQ(kQuotaStatusOk, status());
907 EXPECT_EQ(4000, usage()); 906 EXPECT_EQ(4000, usage());
908 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); 907 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
909 908
910 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); 909 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp);
911 base::RunLoop().RunUntilIdle(); 910 base::RunLoop().RunUntilIdle();
912 EXPECT_EQ(kQuotaStatusOk, status()); 911 EXPECT_EQ(kQuotaStatusOk, status());
913 EXPECT_EQ(0, usage()); 912 EXPECT_EQ(0, usage());
914 EXPECT_EQ(QuotaManager::kNoLimit, quota()); 913 EXPECT_EQ(QuotaManager::kNoLimit, quota());
915 914
916 // Test when overbugdet. 915 // Test when overbugdet.
917 SetTemporaryGlobalQuota(100); 916 const int kPerHostQuotaFor100 = 20;
917 SetStorageConfig(100, kPerHostQuotaFor100, kMustRemainAvailableForSystem);
918 base::RunLoop().RunUntilIdle(); 918 base::RunLoop().RunUntilIdle();
919 919
920 const int kPerHostQuotaFor100 =
921 100 / QuotaManager::kPerHostTemporaryPortion;
922
923 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); 920 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
924 base::RunLoop().RunUntilIdle(); 921 base::RunLoop().RunUntilIdle();
925 EXPECT_EQ(kQuotaStatusOk, status()); 922 EXPECT_EQ(kQuotaStatusOk, status());
926 EXPECT_EQ(10, usage()); 923 EXPECT_EQ(10, usage());
927 EXPECT_EQ(kPerHostQuotaFor100, quota()); 924 EXPECT_EQ(kPerHostQuotaFor100, quota());
928 925
929 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); 926 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
930 base::RunLoop().RunUntilIdle(); 927 base::RunLoop().RunUntilIdle();
931 EXPECT_EQ(kQuotaStatusOk, status()); 928 EXPECT_EQ(kQuotaStatusOk, status());
932 EXPECT_EQ(50, usage()); 929 EXPECT_EQ(50, usage());
933 EXPECT_EQ(kPerHostQuotaFor100, quota()); 930 EXPECT_EQ(20, quota());
934 931
935 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); 932 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
936 base::RunLoop().RunUntilIdle(); 933 base::RunLoop().RunUntilIdle();
937 EXPECT_EQ(kQuotaStatusOk, status()); 934 EXPECT_EQ(kQuotaStatusOk, status());
938 EXPECT_EQ(4000, usage()); 935 EXPECT_EQ(4000, usage());
939 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota()); 936 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
940 937
941 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp); 938 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp);
942 base::RunLoop().RunUntilIdle(); 939 base::RunLoop().RunUntilIdle();
943 EXPECT_EQ(kQuotaStatusOk, status()); 940 EXPECT_EQ(kQuotaStatusOk, status());
944 EXPECT_EQ(0, usage()); 941 EXPECT_EQ(0, usage());
945 EXPECT_EQ(QuotaManager::kNoLimit, quota()); 942 EXPECT_EQ(QuotaManager::kNoLimit, quota());
946 943
947 // Revoke the unlimited rights and make sure the change is noticed. 944 // Revoke the unlimited rights and make sure the change is noticed.
948 mock_special_storage_policy()->Reset(); 945 mock_special_storage_policy()->Reset();
949 mock_special_storage_policy()->NotifyCleared(); 946 mock_special_storage_policy()->NotifyCleared();
950 947
951 GetGlobalUsage(kTemp); 948 GetGlobalUsage(kTemp);
952 base::RunLoop().RunUntilIdle(); 949 base::RunLoop().RunUntilIdle();
953 EXPECT_EQ(10 + 50 + 4000, usage()); 950 EXPECT_EQ(10 + 50 + 4000, usage());
954 EXPECT_EQ(0, unlimited_usage()); 951 EXPECT_EQ(0, unlimited_usage());
955 952
956 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); 953 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
957 base::RunLoop().RunUntilIdle(); 954 base::RunLoop().RunUntilIdle();
958 EXPECT_EQ(kQuotaStatusOk, status()); 955 EXPECT_EQ(kQuotaStatusOk, status());
959 EXPECT_EQ(10, usage()); 956 EXPECT_EQ(10, usage());
960 EXPECT_EQ(10, quota()); // should be clamped to our current usage 957 EXPECT_EQ(kPerHostQuotaFor100, quota());
961 958
962 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); 959 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
963 base::RunLoop().RunUntilIdle(); 960 base::RunLoop().RunUntilIdle();
964 EXPECT_EQ(kQuotaStatusOk, status()); 961 EXPECT_EQ(kQuotaStatusOk, status());
965 EXPECT_EQ(50, usage()); 962 EXPECT_EQ(50, usage());
966 EXPECT_EQ(kPerHostQuotaFor100, quota()); 963 EXPECT_EQ(kPerHostQuotaFor100, quota());
967 964
968 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); 965 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
969 base::RunLoop().RunUntilIdle(); 966 base::RunLoop().RunUntilIdle();
970 EXPECT_EQ(kQuotaStatusOk, status()); 967 EXPECT_EQ(kQuotaStatusOk, status());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 EXPECT_EQ(kQuotaStatusOk, status()); 1077 EXPECT_EQ(kQuotaStatusOk, status());
1081 EXPECT_EQ(0, usage()); 1078 EXPECT_EQ(0, usage());
1082 EXPECT_EQ(kAvailableSpaceForApp, quota()); 1079 EXPECT_EQ(kAvailableSpaceForApp, quota());
1083 1080
1084 // If it's not installed (which shouldn't happen in real case) it 1081 // If it's not installed (which shouldn't happen in real case) it
1085 // should just return the default host quota for syncable. 1082 // should just return the default host quota for syncable.
1086 GetUsageAndQuotaForWebApps(GURL("http://foo/"), kSync); 1083 GetUsageAndQuotaForWebApps(GURL("http://foo/"), kSync);
1087 base::RunLoop().RunUntilIdle(); 1084 base::RunLoop().RunUntilIdle();
1088 EXPECT_EQ(kQuotaStatusOk, status()); 1085 EXPECT_EQ(kQuotaStatusOk, status());
1089 EXPECT_EQ(0, usage()); 1086 EXPECT_EQ(0, usage());
1090 EXPECT_EQ(QuotaManager::kSyncableStorageDefaultHostQuota, quota()); 1087 //EXPECT_EQ(QuotaManager::kSyncableStorageDefaultHostQuota, quota()); ????
1091 } 1088 }
1092 1089
1093 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { 1090 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) {
1094 static const MockOriginData kData[] = { 1091 static const MockOriginData kData[] = {
1095 { "http://foo.com/", kPerm, 10 }, 1092 { "http://foo.com/", kPerm, 10 },
1096 { "http://foo.com:8080/", kPerm, 20 }, 1093 { "http://foo.com:8080/", kPerm, 20 },
1097 { "https://foo.com/", kPerm, 13 }, 1094 { "https://foo.com/", kPerm, 13 },
1098 { "https://foo.com:8081/", kPerm, 19 }, 1095 { "https://foo.com:8081/", kPerm, 19 },
1099 { "http://bar.com/", kPerm, 5 }, 1096 { "http://bar.com/", kPerm, 5 },
1100 { "https://bar.com/", kPerm, 7 }, 1097 { "https://bar.com/", kPerm, 7 },
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 1284
1288 GetHostUsage("foo.com", kTemp); 1285 GetHostUsage("foo.com", kTemp);
1289 base::RunLoop().RunUntilIdle(); 1286 base::RunLoop().RunUntilIdle();
1290 EXPECT_EQ(predelete_host_tmp - 1, usage()); 1287 EXPECT_EQ(predelete_host_tmp - 1, usage());
1291 1288
1292 GetHostUsage("foo.com", kPerm); 1289 GetHostUsage("foo.com", kPerm);
1293 base::RunLoop().RunUntilIdle(); 1290 base::RunLoop().RunUntilIdle();
1294 EXPECT_EQ(predelete_host_pers, usage()); 1291 EXPECT_EQ(predelete_host_pers, usage());
1295 } 1292 }
1296 1293
1297 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { 1294 TEST_F(QuotaManagerTest, GetDeviceStorageCapacity) {
1298 GetAvailableSpace(); 1295 GetDeviceStorageCapacity();
1299 base::RunLoop().RunUntilIdle(); 1296 base::RunLoop().RunUntilIdle();
1300 EXPECT_EQ(kQuotaStatusOk, status()); 1297 EXPECT_LE(0, total_space());
1301 EXPECT_LE(0, available_space()); 1298 EXPECT_LE(0, available_space());
1302 } 1299 }
1303 1300
1304 TEST_F(QuotaManagerTest, SetTemporaryStorageEvictionPolicy) { 1301 TEST_F(QuotaManagerTest, SetTemporaryStorageEvictionPolicy) {
1305 quota_manager()->SetTemporaryStorageEvictionPolicy( 1302 quota_manager()->SetTemporaryStorageEvictionPolicy(
1306 base::WrapUnique(new TestEvictionPolicy)); 1303 base::WrapUnique(new TestEvictionPolicy));
1307 1304
1308 GetEvictionOrigin(kTemp); 1305 GetEvictionOrigin(kTemp);
1309 base::RunLoop().RunUntilIdle(); 1306 base::RunLoop().RunUntilIdle();
1310 EXPECT_EQ(kTestEvictionOrigin, eviction_origin()); 1307 EXPECT_EQ(kTestEvictionOrigin, eviction_origin());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 1519
1523 GetHostUsage("foo.com", kTemp); 1520 GetHostUsage("foo.com", kTemp);
1524 base::RunLoop().RunUntilIdle(); 1521 base::RunLoop().RunUntilIdle();
1525 EXPECT_EQ(predelete_host_tmp, usage()); 1522 EXPECT_EQ(predelete_host_tmp, usage());
1526 1523
1527 GetHostUsage("foo.com", kPerm); 1524 GetHostUsage("foo.com", kPerm);
1528 base::RunLoop().RunUntilIdle(); 1525 base::RunLoop().RunUntilIdle();
1529 EXPECT_EQ(predelete_host_pers, usage()); 1526 EXPECT_EQ(predelete_host_pers, usage());
1530 } 1527 }
1531 1528
1532 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { 1529 TEST_F(QuotaManagerTest, GetEvictionRoundInfo) {
1533 static const MockOriginData kData[] = { 1530 static const MockOriginData kData[] = {
1534 { "http://foo.com/", kTemp, 1 }, 1531 { "http://foo.com/", kTemp, 1 },
1535 { "http://foo.com:1/", kTemp, 20 }, 1532 { "http://foo.com:1/", kTemp, 20 },
1536 { "http://foo.com/", kPerm, 300 }, 1533 { "http://foo.com/", kPerm, 300 },
1537 { "http://unlimited/", kTemp, 4000 }, 1534 { "http://unlimited/", kTemp, 4000 },
1538 }; 1535 };
1539 1536
1540 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); 1537 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
1541 MockStorageClient* client = CreateClient(kData, arraysize(kData), 1538 MockStorageClient* client = CreateClient(kData, arraysize(kData),
1542 QuotaClient::kFileSystem); 1539 QuotaClient::kFileSystem);
1543 RegisterClient(client); 1540 RegisterClient(client);
1544 1541
1545 SetTemporaryGlobalQuota(10000000); 1542 const int kPoolSize = 10000000;
1546 base::RunLoop().RunUntilIdle(); 1543 const int kPerHostQuota = kPoolSize / 5;
1544 SetStorageConfig(kPoolSize, kPerHostQuota,
1545 kMustRemainAvailableForSystem);
1547 1546
1548 GetUsageAndQuotaForEviction(); 1547 GetEvictionRoundInfo();
1549 base::RunLoop().RunUntilIdle(); 1548 base::RunLoop().RunUntilIdle();
1550 EXPECT_EQ(kQuotaStatusOk, status()); 1549 EXPECT_EQ(kQuotaStatusOk, status());
1551 EXPECT_EQ(21, limited_usage()); 1550 EXPECT_EQ(21, usage());
1552 EXPECT_EQ(10000000, quota()); 1551 EXPECT_EQ(kPoolSize, config().pool_size);
1553 EXPECT_LE(0, available_space()); 1552 EXPECT_LE(0, available_space());
1554 } 1553 }
1555 1554
1556 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { 1555 TEST_F(QuotaManagerTest, DeleteHostDataSimple) {
1557 static const MockOriginData kData[] = { 1556 static const MockOriginData kData[] = {
1558 { "http://foo.com/", kTemp, 1 }, 1557 { "http://foo.com/", kTemp, 1 },
1559 }; 1558 };
1560 MockStorageClient* client = CreateClient(kData, arraysize(kData), 1559 MockStorageClient* client = CreateClient(kData, arraysize(kData),
1561 QuotaClient::kFileSystem); 1560 QuotaClient::kFileSystem);
1562 RegisterClient(client); 1561 RegisterClient(client);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 MockStorageClient* client = CreateClient(kData, arraysize(kData), 1794 MockStorageClient* client = CreateClient(kData, arraysize(kData),
1796 QuotaClient::kFileSystem); 1795 QuotaClient::kFileSystem);
1797 RegisterClient(client); 1796 RegisterClient(client);
1798 1797
1799 // TODO(kinuko): Be careful when we add cache pruner. 1798 // TODO(kinuko): Be careful when we add cache pruner.
1800 1799
1801 std::set<GURL> origins; 1800 std::set<GURL> origins;
1802 GetCachedOrigins(kTemp, &origins); 1801 GetCachedOrigins(kTemp, &origins);
1803 EXPECT_TRUE(origins.empty()); 1802 EXPECT_TRUE(origins.empty());
1804 1803
1805 // No matter how we make queries the quota manager tries to cache all
1806 // the origins at startup.
1807 GetHostUsage("a.com", kTemp); 1804 GetHostUsage("a.com", kTemp);
1808 base::RunLoop().RunUntilIdle(); 1805 base::RunLoop().RunUntilIdle();
1809 GetCachedOrigins(kTemp, &origins); 1806 GetCachedOrigins(kTemp, &origins);
1810 EXPECT_EQ(3U, origins.size()); 1807 EXPECT_EQ(2U, origins.size());
1811 1808
1812 GetHostUsage("b.com", kTemp); 1809 GetHostUsage("b.com", kTemp);
1813 base::RunLoop().RunUntilIdle(); 1810 base::RunLoop().RunUntilIdle();
1814 GetCachedOrigins(kTemp, &origins); 1811 GetCachedOrigins(kTemp, &origins);
1812 EXPECT_EQ(2U, origins.size());
1813
1814 GetHostUsage("c.com", kTemp);
1815 base::RunLoop().RunUntilIdle();
1816 GetCachedOrigins(kTemp, &origins);
1815 EXPECT_EQ(3U, origins.size()); 1817 EXPECT_EQ(3U, origins.size());
1816 1818
1817 GetCachedOrigins(kPerm, &origins); 1819 GetCachedOrigins(kPerm, &origins);
1818 EXPECT_TRUE(origins.empty()); 1820 EXPECT_TRUE(origins.empty());
1819 1821
1820 GetGlobalUsage(kTemp); 1822 GetGlobalUsage(kTemp);
1821 base::RunLoop().RunUntilIdle(); 1823 base::RunLoop().RunUntilIdle();
1822 GetCachedOrigins(kTemp, &origins); 1824 GetCachedOrigins(kTemp, &origins);
1823 EXPECT_EQ(3U, origins.size()); 1825 EXPECT_EQ(3U, origins.size());
1824 1826
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) { 2263 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) {
2262 ResetQuotaManager(true); 2264 ResetQuotaManager(true);
2263 2265
2264 static const MockOriginData kData[] = { 2266 static const MockOriginData kData[] = {
2265 { "http://foo.com/", kTemp, 10 }, 2267 { "http://foo.com/", kTemp, 10 },
2266 { "http://foo.com/", kPerm, 80 }, 2268 { "http://foo.com/", kPerm, 80 },
2267 }; 2269 };
2268 RegisterClient(CreateClient(kData, arraysize(kData), 2270 RegisterClient(CreateClient(kData, arraysize(kData),
2269 QuotaClient::kFileSystem)); 2271 QuotaClient::kFileSystem));
2270 2272
2273 // ooops support, kPerm for incognito too :(
2271 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); 2274 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
2272 base::RunLoop().RunUntilIdle(); 2275 base::RunLoop().RunUntilIdle();
2273 EXPECT_EQ(kQuotaStatusOk, status()); 2276 EXPECT_EQ(kQuotaStatusOk, status());
2274 EXPECT_EQ(80, usage()); 2277 EXPECT_EQ(80, usage());
2275 EXPECT_EQ(0, quota()); 2278 EXPECT_EQ(0, quota());
2276 2279
2277 SetTemporaryGlobalQuota(100); 2280 const int kPoolSize = 100;
2281 const int kPerHostQuota = kPoolSize / 5;
2282 SetStorageConfig(kPoolSize, kPerHostQuota,
2283 kMustRemainAvailableForSystem);
2284
2278 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 2285 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2279 base::RunLoop().RunUntilIdle(); 2286 base::RunLoop().RunUntilIdle();
2280 EXPECT_EQ(kQuotaStatusOk, status()); 2287 EXPECT_EQ(kQuotaStatusOk, status());
2281 EXPECT_EQ(10, usage()); 2288 EXPECT_EQ(10, usage());
2282 EXPECT_LE(std::min(static_cast<int64_t>(100 / kPerHostTemporaryPortion), 2289 EXPECT_LE(kPerHostQuota, quota());
2283 QuotaManager::kIncognitoDefaultQuotaLimit),
2284 quota());
2285 2290
2286 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); 2291 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/"));
2287 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); 2292 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
2288 base::RunLoop().RunUntilIdle(); 2293 base::RunLoop().RunUntilIdle();
2289 EXPECT_EQ(kQuotaStatusOk, status()); 2294 EXPECT_EQ(kQuotaStatusOk, status());
2290 EXPECT_EQ(80, usage()); 2295 EXPECT_EQ(80, usage());
2291 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); 2296 EXPECT_EQ(kPerHostQuota, quota());
2292 2297
2293 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 2298 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2294 base::RunLoop().RunUntilIdle(); 2299 base::RunLoop().RunUntilIdle();
2295 EXPECT_EQ(kQuotaStatusOk, status()); 2300 EXPECT_EQ(kQuotaStatusOk, status());
2296 EXPECT_EQ(10, usage()); 2301 EXPECT_EQ(10, usage());
2297 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); 2302 EXPECT_EQ(kPerHostQuota, 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 } 2303 }
2310 2304
2311 } // namespace content 2305 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698