Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / quota / quota_manager_unittest.cc
blobe97bf0a92c9f5d87180c5640ba95ba1d25c6a2e0
1 // Copyright (c) 2012 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.
5 #include <set>
6 #include <sstream>
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop.h"
15 #include "base/message_loop_proxy.h"
16 #include "base/stl_util.h"
17 #include "base/sys_info.h"
18 #include "base/time.h"
19 #include "googleurl/src/gurl.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webkit/quota/mock_special_storage_policy.h"
22 #include "webkit/quota/mock_storage_client.h"
23 #include "webkit/quota/quota_database.h"
24 #include "webkit/quota/quota_manager.h"
26 using base::MessageLoopProxy;
28 namespace quota {
30 namespace {
32 // For shorter names.
33 const StorageType kTemp = kStorageTypeTemporary;
34 const StorageType kPerm = kStorageTypePersistent;
35 const StorageType kSync = kStorageTypeSyncable;
37 const int kAllClients = QuotaClient::kAllClientsMask;
39 const int64 kAvailableSpaceForApp = 13377331U;
41 const int64 kMinimumPreserveForSystem = QuotaManager::kMinimumPreserveForSystem;
42 const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion;
44 // Returns a deterministic value for the amount of available disk space.
45 int64 GetAvailableDiskSpaceForTest(const base::FilePath&) {
46 return kAvailableSpaceForApp + kMinimumPreserveForSystem;
49 } // namespace
51 class QuotaManagerTest : public testing::Test {
52 protected:
53 typedef QuotaManager::QuotaTableEntry QuotaTableEntry;
54 typedef QuotaManager::QuotaTableEntries QuotaTableEntries;
55 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries;
57 public:
58 QuotaManagerTest()
59 : weak_factory_(this),
60 mock_time_counter_(0) {
63 virtual void SetUp() {
64 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
65 mock_special_storage_policy_ = new MockSpecialStoragePolicy;
66 ResetQuotaManager(false /* is_incognito */);
69 virtual void TearDown() {
70 // Make sure the quota manager cleans up correctly.
71 quota_manager_ = NULL;
72 base::MessageLoop::current()->RunUntilIdle();
75 protected:
76 void ResetQuotaManager(bool is_incognito) {
77 quota_manager_ = new QuotaManager(
78 is_incognito,
79 data_dir_.path(),
80 MessageLoopProxy::current(),
81 MessageLoopProxy::current(),
82 mock_special_storage_policy_);
83 // Don't (automatically) start the eviction for testing.
84 quota_manager_->eviction_disabled_ = true;
85 // Don't query the hard disk for remaining capacity.
86 quota_manager_->get_disk_space_fn_ = &GetAvailableDiskSpaceForTest;
87 additional_callback_count_ = 0;
90 MockStorageClient* CreateClient(
91 const MockOriginData* mock_data,
92 size_t mock_data_size,
93 QuotaClient::ID id) {
94 return new MockStorageClient(quota_manager_->proxy(),
95 mock_data, id, mock_data_size);
98 void RegisterClient(MockStorageClient* client) {
99 quota_manager_->proxy()->RegisterClient(client);
102 void GetUsageInfo() {
103 usage_info_.clear();
104 quota_manager_->GetUsageInfo(
105 base::Bind(&QuotaManagerTest::DidGetUsageInfo,
106 weak_factory_.GetWeakPtr()));
109 void GetUsageAndQuotaForWebApps(const GURL& origin,
110 StorageType type) {
111 quota_status_ = kQuotaStatusUnknown;
112 usage_ = -1;
113 quota_ = -1;
114 quota_manager_->GetUsageAndQuotaForWebApps(
115 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota,
116 weak_factory_.GetWeakPtr()));
119 void GetUsageAndQuotaForStorageClient(const GURL& origin,
120 StorageType type) {
121 quota_status_ = kQuotaStatusUnknown;
122 usage_ = -1;
123 quota_ = -1;
124 quota_manager_->GetUsageAndQuota(
125 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota,
126 weak_factory_.GetWeakPtr()));
129 void GetTemporaryGlobalQuota() {
130 quota_status_ = kQuotaStatusUnknown;
131 quota_ = -1;
132 quota_manager_->GetTemporaryGlobalQuota(
133 base::Bind(&QuotaManagerTest::DidGetQuota,
134 weak_factory_.GetWeakPtr()));
137 void SetTemporaryGlobalQuota(int64 new_quota) {
138 quota_status_ = kQuotaStatusUnknown;
139 quota_ = -1;
140 quota_manager_->SetTemporaryGlobalOverrideQuota(
141 new_quota,
142 base::Bind(&QuotaManagerTest::DidGetQuota,
143 weak_factory_.GetWeakPtr()));
146 void GetPersistentHostQuota(const std::string& host) {
147 quota_status_ = kQuotaStatusUnknown;
148 quota_ = -1;
149 quota_manager_->GetPersistentHostQuota(
150 host,
151 base::Bind(&QuotaManagerTest::DidGetHostQuota,
152 weak_factory_.GetWeakPtr()));
155 void SetPersistentHostQuota(const std::string& host, int64 new_quota) {
156 quota_status_ = kQuotaStatusUnknown;
157 quota_ = -1;
158 quota_manager_->SetPersistentHostQuota(
159 host, new_quota,
160 base::Bind(&QuotaManagerTest::DidGetHostQuota,
161 weak_factory_.GetWeakPtr()));
164 void GetGlobalUsage(StorageType type) {
165 usage_ = -1;
166 unlimited_usage_ = -1;
167 quota_manager_->GetGlobalUsage(
168 type,
169 base::Bind(&QuotaManagerTest::DidGetGlobalUsage,
170 weak_factory_.GetWeakPtr()));
173 void GetHostUsage(const std::string& host, StorageType type) {
174 usage_ = -1;
175 quota_manager_->GetHostUsage(
176 host, type,
177 base::Bind(&QuotaManagerTest::DidGetHostUsage,
178 weak_factory_.GetWeakPtr()));
181 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) {
182 quota_manager_->GetUsageAndQuota(
183 origin, type,
184 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional,
185 weak_factory_.GetWeakPtr()));
188 void DeleteClientOriginData(QuotaClient* client,
189 const GURL& origin,
190 StorageType type) {
191 DCHECK(client);
192 quota_status_ = kQuotaStatusUnknown;
193 client->DeleteOriginData(
194 origin, type,
195 base::Bind(&QuotaManagerTest::StatusCallback,
196 weak_factory_.GetWeakPtr()));
199 void EvictOriginData(const GURL& origin,
200 StorageType type) {
201 quota_status_ = kQuotaStatusUnknown;
202 quota_manager_->EvictOriginData(
203 origin, type,
204 base::Bind(&QuotaManagerTest::StatusCallback,
205 weak_factory_.GetWeakPtr()));
208 void DeleteOriginData(const GURL& origin,
209 StorageType type,
210 int quota_client_mask) {
211 quota_status_ = kQuotaStatusUnknown;
212 quota_manager_->DeleteOriginData(
213 origin, type, quota_client_mask,
214 base::Bind(&QuotaManagerTest::StatusCallback,
215 weak_factory_.GetWeakPtr()));
218 void DeleteHostData(const std::string& host,
219 StorageType type,
220 int quota_client_mask) {
221 quota_status_ = kQuotaStatusUnknown;
222 quota_manager_->DeleteHostData(
223 host, type, quota_client_mask,
224 base::Bind(&QuotaManagerTest::StatusCallback,
225 weak_factory_.GetWeakPtr()));
228 void GetAvailableSpace() {
229 quota_status_ = kQuotaStatusUnknown;
230 available_space_ = -1;
231 quota_manager_->GetAvailableSpace(
232 base::Bind(&QuotaManagerTest::DidGetAvailableSpace,
233 weak_factory_.GetWeakPtr()));
236 void GetUsageAndQuotaForEviction() {
237 quota_status_ = kQuotaStatusUnknown;
238 usage_ = -1;
239 unlimited_usage_ = -1;
240 quota_ = -1;
241 available_space_ = -1;
242 quota_manager_->GetUsageAndQuotaForEviction(
243 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction,
244 weak_factory_.GetWeakPtr()));
247 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) {
248 ASSERT_TRUE(origins != NULL);
249 origins->clear();
250 quota_manager_->GetCachedOrigins(type, origins);
253 void NotifyStorageAccessed(QuotaClient* client,
254 const GURL& origin,
255 StorageType type) {
256 DCHECK(client);
257 quota_manager_->NotifyStorageAccessedInternal(
258 client->id(), origin, type, IncrementMockTime());
261 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) {
262 quota_manager_->DeleteOriginFromDatabase(origin, type);
265 void GetLRUOrigin(StorageType type) {
266 lru_origin_ = GURL();
267 quota_manager_->GetLRUOrigin(
268 type,
269 base::Bind(&QuotaManagerTest::DidGetLRUOrigin,
270 weak_factory_.GetWeakPtr()));
273 void NotifyOriginInUse(const GURL& origin) {
274 quota_manager_->NotifyOriginInUse(origin);
277 void NotifyOriginNoLongerInUse(const GURL& origin) {
278 quota_manager_->NotifyOriginNoLongerInUse(origin);
281 void GetOriginsModifiedSince(StorageType type, base::Time modified_since) {
282 modified_origins_.clear();
283 modified_origins_type_ = kStorageTypeUnknown;
284 quota_manager_->GetOriginsModifiedSince(
285 type, modified_since,
286 base::Bind(&QuotaManagerTest::DidGetModifiedOrigins,
287 weak_factory_.GetWeakPtr()));
290 void DumpQuotaTable() {
291 quota_entries_.clear();
292 quota_manager_->DumpQuotaTable(
293 base::Bind(&QuotaManagerTest::DidDumpQuotaTable,
294 weak_factory_.GetWeakPtr()));
297 void DumpOriginInfoTable() {
298 origin_info_entries_.clear();
299 quota_manager_->DumpOriginInfoTable(
300 base::Bind(&QuotaManagerTest::DidDumpOriginInfoTable,
301 weak_factory_.GetWeakPtr()));
304 void DidGetUsageInfo(const UsageInfoEntries& entries) {
305 usage_info_.insert(usage_info_.begin(), entries.begin(), entries.end());
308 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) {
309 quota_status_ = status;
310 usage_ = usage;
311 quota_ = quota;
314 void DidGetQuota(QuotaStatusCode status,
315 int64 quota) {
316 quota_status_ = status;
317 quota_ = quota;
320 void DidGetAvailableSpace(QuotaStatusCode status, int64 available_space) {
321 quota_status_ = status;
322 available_space_ = available_space;
325 void DidGetHostQuota(QuotaStatusCode status,
326 int64 quota) {
327 quota_status_ = status;
328 quota_ = quota;
331 void DidGetGlobalUsage(int64 usage,
332 int64 unlimited_usage) {
333 usage_ = usage;
334 unlimited_usage_ = unlimited_usage;
337 void DidGetHostUsage(int64 usage) {
338 usage_ = usage;
341 void StatusCallback(QuotaStatusCode status) {
342 ++status_callback_count_;
343 quota_status_ = status;
346 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status,
347 const UsageAndQuota& usage_and_quota) {
348 quota_status_ = status;
349 usage_ = usage_and_quota.global_usage;
350 unlimited_usage_ = usage_and_quota.global_unlimited_usage;
351 quota_ = usage_and_quota.quota;
352 available_space_ = usage_and_quota.available_disk_space;
355 void DidGetLRUOrigin(const GURL& origin) {
356 lru_origin_ = origin;
359 void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) {
360 modified_origins_ = origins;
361 modified_origins_type_ = type;
364 void DidDumpQuotaTable(const QuotaTableEntries& entries) {
365 quota_entries_ = entries;
368 void DidDumpOriginInfoTable(const OriginInfoTableEntries& entries) {
369 origin_info_entries_ = entries;
372 void GetUsage_WithModifyTestBody(const StorageType type);
374 void set_additional_callback_count(int c) { additional_callback_count_ = c; }
375 int additional_callback_count() const { return additional_callback_count_; }
376 void DidGetUsageAndQuotaAdditional(
377 QuotaStatusCode status, int64 usage, int64 quota) {
378 ++additional_callback_count_;
381 QuotaManager* quota_manager() const { return quota_manager_.get(); }
382 void set_quota_manager(QuotaManager* quota_manager) {
383 quota_manager_ = quota_manager;
386 MockSpecialStoragePolicy* mock_special_storage_policy() const {
387 return mock_special_storage_policy_.get();
390 QuotaStatusCode status() const { return quota_status_; }
391 const UsageInfoEntries& usage_info() const { return usage_info_; }
392 int64 usage() const { return usage_; }
393 int64 unlimited_usage() const { return unlimited_usage_; }
394 int64 quota() const { return quota_; }
395 int64 available_space() const { return available_space_; }
396 const GURL& lru_origin() const { return lru_origin_; }
397 const std::set<GURL>& modified_origins() const { return modified_origins_; }
398 StorageType modified_origins_type() const { return modified_origins_type_; }
399 const QuotaTableEntries& quota_entries() const { return quota_entries_; }
400 const OriginInfoTableEntries& origin_info_entries() const {
401 return origin_info_entries_;
403 base::FilePath profile_path() const { return data_dir_.path(); }
404 int status_callback_count() const { return status_callback_count_; }
405 void reset_status_callback_count() { status_callback_count_ = 0; }
407 private:
408 base::Time IncrementMockTime() {
409 ++mock_time_counter_;
410 return base::Time::FromDoubleT(mock_time_counter_ * 10.0);
413 base::MessageLoop message_loop_;
414 base::ScopedTempDir data_dir_;
415 base::WeakPtrFactory<QuotaManagerTest> weak_factory_;
417 scoped_refptr<QuotaManager> quota_manager_;
418 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_;
420 QuotaStatusCode quota_status_;
421 UsageInfoEntries usage_info_;
422 int64 usage_;
423 int64 unlimited_usage_;
424 int64 quota_;
425 int64 available_space_;
426 GURL lru_origin_;
427 std::set<GURL> modified_origins_;
428 StorageType modified_origins_type_;
429 QuotaTableEntries quota_entries_;
430 OriginInfoTableEntries origin_info_entries_;
431 int status_callback_count_;
433 int additional_callback_count_;
435 int mock_time_counter_;
437 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest);
440 TEST_F(QuotaManagerTest, GetUsageInfo) {
441 static const MockOriginData kData1[] = {
442 { "http://foo.com/", kTemp, 10 },
443 { "http://foo.com:8080/", kTemp, 15 },
444 { "http://bar.com/", kTemp, 20 },
445 { "http://bar.com/", kPerm, 50 },
447 static const MockOriginData kData2[] = {
448 { "https://foo.com/", kTemp, 30 },
449 { "https://foo.com:8081/", kTemp, 35 },
450 { "http://bar.com/", kPerm, 40 },
451 { "http://example.com/", kPerm, 40 },
453 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
454 QuotaClient::kFileSystem));
455 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
456 QuotaClient::kDatabase));
458 GetUsageInfo();
459 base::MessageLoop::current()->RunUntilIdle();
461 EXPECT_EQ(4U, usage_info().size());
462 for (size_t i = 0; i < usage_info().size(); ++i) {
463 const UsageInfo& info = usage_info()[i];
464 if (info.host == "foo.com" && info.type == kTemp) {
465 EXPECT_EQ(10 + 15 + 30 + 35, info.usage);
466 } else if (info.host == "bar.com" && info.type == kTemp) {
467 EXPECT_EQ(20, info.usage);
468 } else if (info.host == "bar.com" && info.type == kPerm) {
469 EXPECT_EQ(50 + 40, info.usage);
470 } else if (info.host == "example.com" && info.type == kPerm) {
471 EXPECT_EQ(40, info.usage);
472 } else {
473 ADD_FAILURE()
474 << "Unexpected host, type: " << info.host << ", " << info.type;
479 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) {
480 static const MockOriginData kData[] = {
481 { "http://foo.com/", kTemp, 10 },
482 { "http://foo.com/", kPerm, 80 },
484 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
485 QuotaClient::kFileSystem));
487 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
488 base::MessageLoop::current()->RunUntilIdle();
489 EXPECT_EQ(kQuotaStatusOk, status());
490 EXPECT_EQ(80, usage());
491 EXPECT_EQ(0, quota());
493 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
494 base::MessageLoop::current()->RunUntilIdle();
495 EXPECT_EQ(kQuotaStatusOk, status());
496 EXPECT_EQ(10, usage());
497 EXPECT_LE(0, quota());
498 int64 quota_returned_for_foo = quota();
500 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp);
501 base::MessageLoop::current()->RunUntilIdle();
502 EXPECT_EQ(kQuotaStatusOk, status());
503 EXPECT_EQ(0, usage());
504 EXPECT_EQ(quota_returned_for_foo, quota());
507 TEST_F(QuotaManagerTest, GetUsage_NoClient) {
508 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
509 base::MessageLoop::current()->RunUntilIdle();
510 EXPECT_EQ(kQuotaStatusOk, status());
511 EXPECT_EQ(0, usage());
513 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
514 base::MessageLoop::current()->RunUntilIdle();
515 EXPECT_EQ(kQuotaStatusOk, status());
516 EXPECT_EQ(0, usage());
518 GetHostUsage("foo.com", kTemp);
519 base::MessageLoop::current()->RunUntilIdle();
520 EXPECT_EQ(0, usage());
522 GetHostUsage("foo.com", kPerm);
523 base::MessageLoop::current()->RunUntilIdle();
524 EXPECT_EQ(0, usage());
526 GetGlobalUsage(kTemp);
527 base::MessageLoop::current()->RunUntilIdle();
528 EXPECT_EQ(0, usage());
529 EXPECT_EQ(0, unlimited_usage());
531 GetGlobalUsage(kPerm);
532 base::MessageLoop::current()->RunUntilIdle();
533 EXPECT_EQ(0, usage());
534 EXPECT_EQ(0, unlimited_usage());
537 TEST_F(QuotaManagerTest, GetUsage_EmptyClient) {
538 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem));
539 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
540 base::MessageLoop::current()->RunUntilIdle();
541 EXPECT_EQ(kQuotaStatusOk, status());
542 EXPECT_EQ(0, usage());
544 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
545 base::MessageLoop::current()->RunUntilIdle();
546 EXPECT_EQ(kQuotaStatusOk, status());
547 EXPECT_EQ(0, usage());
549 GetHostUsage("foo.com", kTemp);
550 base::MessageLoop::current()->RunUntilIdle();
551 EXPECT_EQ(0, usage());
553 GetHostUsage("foo.com", kPerm);
554 base::MessageLoop::current()->RunUntilIdle();
555 EXPECT_EQ(0, usage());
557 GetGlobalUsage(kTemp);
558 base::MessageLoop::current()->RunUntilIdle();
559 EXPECT_EQ(0, usage());
560 EXPECT_EQ(0, unlimited_usage());
562 GetGlobalUsage(kPerm);
563 base::MessageLoop::current()->RunUntilIdle();
564 EXPECT_EQ(0, usage());
565 EXPECT_EQ(0, unlimited_usage());
568 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) {
569 static const MockOriginData kData[] = {
570 { "http://foo.com/", kTemp, 10 },
571 { "http://foo.com:8080/", kTemp, 20 },
572 { "http://bar.com/", kTemp, 5 },
573 { "https://bar.com/", kTemp, 7 },
574 { "http://baz.com/", kTemp, 30 },
575 { "http://foo.com/", kPerm, 40 },
577 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
578 QuotaClient::kFileSystem));
580 // This time explicitly sets a temporary global quota.
581 SetTemporaryGlobalQuota(100);
582 base::MessageLoop::current()->RunUntilIdle();
583 EXPECT_EQ(kQuotaStatusOk, status());
584 EXPECT_EQ(100, quota());
586 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
587 base::MessageLoop::current()->RunUntilIdle();
588 EXPECT_EQ(kQuotaStatusOk, status());
589 EXPECT_EQ(10 + 20, usage());
591 const int kPerHostQuota = 100 / kPerHostTemporaryPortion;
593 // The host's quota should be its full portion of the global quota
594 // since global usage is under the global quota.
595 EXPECT_EQ(kPerHostQuota, quota());
597 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kTemp);
598 base::MessageLoop::current()->RunUntilIdle();
599 EXPECT_EQ(kQuotaStatusOk, status());
600 EXPECT_EQ(5 + 7, usage());
601 EXPECT_EQ(kPerHostQuota, quota());
604 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) {
605 static const MockOriginData kData1[] = {
606 { "http://foo.com/", kTemp, 1 },
607 { "http://bar.com/", kTemp, 2 },
608 { "http://bar.com/", kPerm, 4 },
609 { "http://unlimited/", kPerm, 8 },
610 { "http://installed/", kPerm, 16 },
612 static const MockOriginData kData2[] = {
613 { "https://foo.com/", kTemp, 128 },
614 { "http://example.com/", kPerm, 256 },
615 { "http://unlimited/", kTemp, 512 },
616 { "http://installed/", kTemp, 1024 },
618 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
619 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/"));
620 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
621 QuotaClient::kFileSystem));
622 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
623 QuotaClient::kDatabase));
625 const int64 kTempQuotaBase =
626 GetAvailableDiskSpaceForTest(base::FilePath()) / kPerHostTemporaryPortion;
628 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
629 base::MessageLoop::current()->RunUntilIdle();
630 EXPECT_EQ(kQuotaStatusOk, status());
631 EXPECT_EQ(1 + 128, usage());
633 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), kPerm);
634 base::MessageLoop::current()->RunUntilIdle();
635 EXPECT_EQ(kQuotaStatusOk, status());
636 EXPECT_EQ(4, usage());
638 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
639 base::MessageLoop::current()->RunUntilIdle();
640 EXPECT_EQ(kQuotaStatusOk, status());
641 EXPECT_EQ(512, usage());
642 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota());
644 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm);
645 base::MessageLoop::current()->RunUntilIdle();
646 EXPECT_EQ(kQuotaStatusOk, status());
647 EXPECT_EQ(8, usage());
648 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
650 GetAvailableSpace();
651 base::MessageLoop::current()->RunUntilIdle();
652 EXPECT_EQ(kQuotaStatusOk, status());
653 EXPECT_LE(0, available_space());
655 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kTemp);
656 base::MessageLoop::current()->RunUntilIdle();
657 EXPECT_EQ(kQuotaStatusOk, status());
658 EXPECT_EQ(1024, usage());
659 EXPECT_EQ(std::min(kAvailableSpaceForApp, kTempQuotaBase) + usage(), quota());
661 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm);
662 base::MessageLoop::current()->RunUntilIdle();
663 EXPECT_EQ(kQuotaStatusOk, status());
664 EXPECT_EQ(16, usage());
665 EXPECT_EQ(usage(), quota()); // Over-budget case.
667 GetGlobalUsage(kTemp);
668 base::MessageLoop::current()->RunUntilIdle();
669 EXPECT_EQ(kQuotaStatusOk, status());
670 EXPECT_EQ(1 + 2 + 128 + 512 + 1024, usage());
671 EXPECT_EQ(512, unlimited_usage());
673 GetGlobalUsage(kPerm);
674 base::MessageLoop::current()->RunUntilIdle();
675 EXPECT_EQ(kQuotaStatusOk, status());
676 EXPECT_EQ(4 + 8 + 16 + 256, usage());
677 EXPECT_EQ(8, unlimited_usage());
680 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) {
681 const MockOriginData data[] = {
682 { "http://foo.com/", type, 10 },
683 { "http://foo.com:1/", type, 20 },
685 MockStorageClient* client = CreateClient(data, ARRAYSIZE_UNSAFE(data),
686 QuotaClient::kFileSystem);
687 RegisterClient(client);
689 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), type);
690 base::MessageLoop::current()->RunUntilIdle();
691 EXPECT_EQ(kQuotaStatusOk, status());
692 EXPECT_EQ(10 + 20, usage());
694 client->ModifyOriginAndNotify(GURL("http://foo.com/"), type, 30);
695 client->ModifyOriginAndNotify(GURL("http://foo.com:1/"), type, -5);
696 client->AddOriginAndNotify(GURL("https://foo.com/"), type, 1);
698 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), type);
699 base::MessageLoop::current()->RunUntilIdle();
700 EXPECT_EQ(kQuotaStatusOk, status());
701 EXPECT_EQ(10 + 20 + 30 - 5 + 1, usage());
702 int foo_usage = usage();
704 client->AddOriginAndNotify(GURL("http://bar.com/"), type, 40);
705 GetUsageAndQuotaForWebApps(GURL("http://bar.com/"), type);
706 base::MessageLoop::current()->RunUntilIdle();
707 EXPECT_EQ(kQuotaStatusOk, status());
708 EXPECT_EQ(40, usage());
710 GetGlobalUsage(type);
711 base::MessageLoop::current()->RunUntilIdle();
712 EXPECT_EQ(foo_usage + 40, usage());
713 EXPECT_EQ(0, unlimited_usage());
716 TEST_F(QuotaManagerTest, GetTemporaryUsage_WithModify) {
717 GetUsage_WithModifyTestBody(kTemp);
720 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) {
721 static const MockOriginData kData[] = {
722 { "http://foo.com/", kTemp, 10 },
723 { "http://foo.com:8080/", kTemp, 20 },
724 { "http://bar.com/", kTemp, 13 },
725 { "http://foo.com/", kPerm, 40 },
727 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
728 QuotaClient::kFileSystem));
729 SetTemporaryGlobalQuota(100);
730 base::MessageLoop::current()->RunUntilIdle();
732 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion;
734 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
735 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
736 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
737 base::MessageLoop::current()->RunUntilIdle();
738 EXPECT_EQ(kQuotaStatusOk, status());
739 EXPECT_EQ(10 + 20, usage());
740 EXPECT_EQ(kPerHostQuota, quota());
742 set_additional_callback_count(0);
743 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
744 kTemp);
745 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
746 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kTemp);
747 base::MessageLoop::current()->RunUntilIdle();
748 EXPECT_EQ(kQuotaStatusOk, status());
749 EXPECT_EQ(10 + 20, usage());
750 EXPECT_EQ(kPerHostQuota, quota());
751 EXPECT_EQ(2, additional_callback_count());
754 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) {
755 static const MockOriginData kData[] = {
756 { "http://foo.com/", kTemp, 10 },
757 { "http://foo.com:8080/", kTemp, 20 },
758 { "http://bar.com/", kTemp, 13 },
759 { "http://foo.com/", kPerm, 40 },
761 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
762 QuotaClient::kFileSystem));
763 SetTemporaryGlobalQuota(100);
764 base::MessageLoop::current()->RunUntilIdle();
766 set_additional_callback_count(0);
767 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
768 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
769 kTemp);
770 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
771 kTemp);
773 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
774 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients);
776 // Nuke before waiting for callbacks.
777 set_quota_manager(NULL);
778 base::MessageLoop::current()->RunUntilIdle();
779 EXPECT_EQ(kQuotaErrorAbort, status());
782 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) {
783 static const MockOriginData kData[] = {
784 { "http://usage1/", kTemp, 1 },
785 { "http://usage10/", kTemp, 10 },
786 { "http://usage200/", kTemp, 200 },
788 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
789 QuotaClient::kFileSystem));
790 SetTemporaryGlobalQuota(100);
791 base::MessageLoop::current()->RunUntilIdle();
793 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion;
795 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp);
796 base::MessageLoop::current()->RunUntilIdle();
797 EXPECT_EQ(kQuotaStatusOk, status());
798 EXPECT_EQ(1, usage());
799 EXPECT_EQ(1, quota()); // should be clamped to our current usage
801 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
802 base::MessageLoop::current()->RunUntilIdle();
803 EXPECT_EQ(kQuotaStatusOk, status());
804 EXPECT_EQ(10, usage());
805 EXPECT_EQ(10, quota());
807 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp);
808 base::MessageLoop::current()->RunUntilIdle();
809 EXPECT_EQ(kQuotaStatusOk, status());
810 EXPECT_EQ(200, usage());
811 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota
814 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
815 static const MockOriginData kData[] = {
816 { "http://usage10/", kTemp, 10 },
817 { "http://usage50/", kTemp, 50 },
818 { "http://unlimited/", kTemp, 4000 },
820 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
821 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
822 QuotaClient::kFileSystem);
823 RegisterClient(client);
825 // Test when not overbugdet.
826 SetTemporaryGlobalQuota(1000);
827 base::MessageLoop::current()->RunUntilIdle();
829 GetGlobalUsage(kTemp);
830 base::MessageLoop::current()->RunUntilIdle();
831 EXPECT_EQ(10 + 50 + 4000, usage());
832 EXPECT_EQ(4000, unlimited_usage());
834 const int kPerHostQuotaFor1000 =
835 1000 / QuotaManager::kPerHostTemporaryPortion;
837 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
838 base::MessageLoop::current()->RunUntilIdle();
839 EXPECT_EQ(kQuotaStatusOk, status());
840 EXPECT_EQ(10, usage());
841 EXPECT_EQ(kPerHostQuotaFor1000, quota());
843 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
844 base::MessageLoop::current()->RunUntilIdle();
845 EXPECT_EQ(kQuotaStatusOk, status());
846 EXPECT_EQ(50, usage());
847 EXPECT_EQ(kPerHostQuotaFor1000, quota());
849 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
850 base::MessageLoop::current()->RunUntilIdle();
851 EXPECT_EQ(kQuotaStatusOk, status());
852 EXPECT_EQ(4000, usage());
853 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
855 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp);
856 base::MessageLoop::current()->RunUntilIdle();
857 EXPECT_EQ(kQuotaStatusOk, status());
858 EXPECT_EQ(0, usage());
859 EXPECT_EQ(QuotaManager::kNoLimit, quota());
861 // Test when overbugdet.
862 SetTemporaryGlobalQuota(100);
863 base::MessageLoop::current()->RunUntilIdle();
865 const int kPerHostQuotaFor100 =
866 100 / QuotaManager::kPerHostTemporaryPortion;
868 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
869 base::MessageLoop::current()->RunUntilIdle();
870 EXPECT_EQ(kQuotaStatusOk, status());
871 EXPECT_EQ(10, usage());
872 EXPECT_EQ(kPerHostQuotaFor100, quota());
874 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
875 base::MessageLoop::current()->RunUntilIdle();
876 EXPECT_EQ(kQuotaStatusOk, status());
877 EXPECT_EQ(50, usage());
878 EXPECT_EQ(kPerHostQuotaFor100, quota());
880 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
881 base::MessageLoop::current()->RunUntilIdle();
882 EXPECT_EQ(kQuotaStatusOk, status());
883 EXPECT_EQ(4000, usage());
884 EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
886 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp);
887 base::MessageLoop::current()->RunUntilIdle();
888 EXPECT_EQ(kQuotaStatusOk, status());
889 EXPECT_EQ(0, usage());
890 EXPECT_EQ(QuotaManager::kNoLimit, quota());
892 // Revoke the unlimited rights and make sure the change is noticed.
893 mock_special_storage_policy()->Reset();
894 mock_special_storage_policy()->NotifyCleared();
896 GetGlobalUsage(kTemp);
897 base::MessageLoop::current()->RunUntilIdle();
898 EXPECT_EQ(10 + 50 + 4000, usage());
899 EXPECT_EQ(0, unlimited_usage());
901 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
902 base::MessageLoop::current()->RunUntilIdle();
903 EXPECT_EQ(kQuotaStatusOk, status());
904 EXPECT_EQ(10, usage());
905 EXPECT_EQ(10, quota()); // should be clamped to our current usage
907 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
908 base::MessageLoop::current()->RunUntilIdle();
909 EXPECT_EQ(kQuotaStatusOk, status());
910 EXPECT_EQ(50, usage());
911 EXPECT_EQ(kPerHostQuotaFor100, quota());
913 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
914 base::MessageLoop::current()->RunUntilIdle();
915 EXPECT_EQ(kQuotaStatusOk, status());
916 EXPECT_EQ(4000, usage());
917 EXPECT_EQ(kPerHostQuotaFor100, quota());
919 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kTemp);
920 base::MessageLoop::current()->RunUntilIdle();
921 EXPECT_EQ(kQuotaStatusOk, status());
922 EXPECT_EQ(4000, usage());
923 EXPECT_EQ(kPerHostQuotaFor100, quota());
926 TEST_F(QuotaManagerTest, OriginInUse) {
927 const GURL kFooOrigin("http://foo.com/");
928 const GURL kBarOrigin("http://bar.com/");
930 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin));
931 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 1
932 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin));
933 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 2
934 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin));
935 quota_manager()->NotifyOriginNoLongerInUse(kFooOrigin); // count of 1
936 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin));
938 EXPECT_FALSE(quota_manager()->IsOriginInUse(kBarOrigin));
939 quota_manager()->NotifyOriginInUse(kBarOrigin);
940 EXPECT_TRUE(quota_manager()->IsOriginInUse(kBarOrigin));
941 quota_manager()->NotifyOriginNoLongerInUse(kBarOrigin);
942 EXPECT_FALSE(quota_manager()->IsOriginInUse(kBarOrigin));
944 quota_manager()->NotifyOriginNoLongerInUse(kFooOrigin);
945 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin));
948 TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) {
949 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem));
951 GetPersistentHostQuota("foo.com");
952 base::MessageLoop::current()->RunUntilIdle();
953 EXPECT_EQ(0, quota());
955 SetPersistentHostQuota("foo.com", 100);
956 base::MessageLoop::current()->RunUntilIdle();
957 EXPECT_EQ(100, quota());
959 GetPersistentHostQuota("foo.com");
960 SetPersistentHostQuota("foo.com", 200);
961 GetPersistentHostQuota("foo.com");
962 SetPersistentHostQuota("foo.com", 300000000000ll);
963 GetPersistentHostQuota("foo.com");
964 base::MessageLoop::current()->RunUntilIdle();
965 EXPECT_EQ(300000000000ll, quota());
968 TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) {
969 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem));
971 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
972 base::MessageLoop::current()->RunUntilIdle();
973 EXPECT_EQ(kQuotaStatusOk, status());
974 EXPECT_EQ(0, usage());
975 EXPECT_EQ(0, quota());
977 SetPersistentHostQuota("foo.com", 100);
978 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
979 base::MessageLoop::current()->RunUntilIdle();
980 EXPECT_EQ(kQuotaStatusOk, status());
981 EXPECT_EQ(0, usage());
982 EXPECT_EQ(100, quota());
984 // For installed app GetUsageAndQuotaForWebApps returns the capped quota.
985 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/"));
986 SetPersistentHostQuota("installed", kAvailableSpaceForApp + 100);
987 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm);
988 base::MessageLoop::current()->RunUntilIdle();
989 EXPECT_EQ(kAvailableSpaceForApp, quota());
991 // Ditto for unlimited apps.
992 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
993 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm);
994 base::MessageLoop::current()->RunUntilIdle();
995 EXPECT_EQ(kAvailableSpaceForApp, quota());
997 // GetUsageAndQuotaForStorageClient should just return 0 usage and
998 // kNoLimit quota.
999 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kPerm);
1000 base::MessageLoop::current()->RunUntilIdle();
1001 EXPECT_EQ(0, usage());
1002 EXPECT_EQ(QuotaManager::kNoLimit, quota());
1005 TEST_F(QuotaManagerTest, GetSyncableQuota) {
1006 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem));
1008 // Pre-condition check: available disk space (for testing) is less than
1009 // the default quota for syncable storage.
1010 EXPECT_LE(kAvailableSpaceForApp,
1011 QuotaManager::kSyncableStorageDefaultHostQuota);
1013 // For installed apps the quota manager should return
1014 // kAvailableSpaceForApp as syncable quota (because of the pre-condition).
1015 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/"));
1016 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kSync);
1017 base::MessageLoop::current()->RunUntilIdle();
1018 EXPECT_EQ(kQuotaStatusOk, status());
1019 EXPECT_EQ(0, usage());
1020 EXPECT_EQ(kAvailableSpaceForApp, quota());
1022 // If it's not installed (which shouldn't happen in real case) it
1023 // should just return the default host quota for syncable.
1024 GetUsageAndQuotaForWebApps(GURL("http://foo/"), kSync);
1025 base::MessageLoop::current()->RunUntilIdle();
1026 EXPECT_EQ(kQuotaStatusOk, status());
1027 EXPECT_EQ(0, usage());
1028 EXPECT_EQ(QuotaManager::kSyncableStorageDefaultHostQuota, quota());
1031 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) {
1032 static const MockOriginData kData[] = {
1033 { "http://foo.com/", kPerm, 10 },
1034 { "http://foo.com:8080/", kPerm, 20 },
1035 { "https://foo.com/", kPerm, 13 },
1036 { "https://foo.com:8081/", kPerm, 19 },
1037 { "http://bar.com/", kPerm, 5 },
1038 { "https://bar.com/", kPerm, 7 },
1039 { "http://baz.com/", kPerm, 30 },
1040 { "http://foo.com/", kTemp, 40 },
1042 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1043 QuotaClient::kFileSystem));
1045 SetPersistentHostQuota("foo.com", 100);
1046 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
1047 base::MessageLoop::current()->RunUntilIdle();
1048 EXPECT_EQ(kQuotaStatusOk, status());
1049 EXPECT_EQ(10 + 20 + 13 + 19, usage());
1050 EXPECT_EQ(100, quota());
1053 TEST_F(QuotaManagerTest, GetPersistentUsage_WithModify) {
1054 GetUsage_WithModifyTestBody(kPerm);
1057 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) {
1058 static const MockOriginData kData[] = {
1059 { "http://foo.com/", kPerm, 10 },
1060 { "http://foo.com:8080/", kPerm, 20 },
1061 { "http://bar.com/", kPerm, 13 },
1062 { "http://foo.com/", kTemp, 40 },
1064 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1065 QuotaClient::kFileSystem));
1066 SetPersistentHostQuota("foo.com", 100);
1068 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
1069 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
1070 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
1071 base::MessageLoop::current()->RunUntilIdle();
1072 EXPECT_EQ(kQuotaStatusOk, status());
1073 EXPECT_EQ(10 + 20, usage());
1074 EXPECT_EQ(100, quota());
1076 set_additional_callback_count(0);
1077 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
1078 kPerm);
1079 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
1080 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm);
1081 base::MessageLoop::current()->RunUntilIdle();
1082 EXPECT_EQ(kQuotaStatusOk, status());
1083 EXPECT_EQ(10 + 20, usage());
1084 EXPECT_EQ(2, additional_callback_count());
1087 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) {
1088 static const MockOriginData kData[] = {
1089 { "http://foo.com/", kPerm, 10 },
1090 { "http://foo.com:8080/", kPerm, 20 },
1091 { "http://bar.com/", kPerm, 13 },
1092 { "http://foo.com/", kTemp, 40 },
1094 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1095 QuotaClient::kFileSystem));
1096 SetPersistentHostQuota("foo.com", 100);
1098 set_additional_callback_count(0);
1099 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
1100 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), kPerm);
1101 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm);
1103 // Nuke before waiting for callbacks.
1104 set_quota_manager(NULL);
1105 base::MessageLoop::current()->RunUntilIdle();
1106 EXPECT_EQ(kQuotaErrorAbort, status());
1109 TEST_F(QuotaManagerTest, GetUsage_Simple) {
1110 static const MockOriginData kData[] = {
1111 { "http://foo.com/", kPerm, 1 },
1112 { "http://foo.com:1/", kPerm, 20 },
1113 { "http://bar.com/", kTemp, 300 },
1114 { "https://buz.com/", kTemp, 4000 },
1115 { "http://buz.com/", kTemp, 50000 },
1116 { "http://bar.com:1/", kPerm, 600000 },
1117 { "http://foo.com/", kTemp, 7000000 },
1119 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1120 QuotaClient::kFileSystem));
1122 GetGlobalUsage(kPerm);
1123 base::MessageLoop::current()->RunUntilIdle();
1124 EXPECT_EQ(usage(), 1 + 20 + 600000);
1125 EXPECT_EQ(0, unlimited_usage());
1127 GetGlobalUsage(kTemp);
1128 base::MessageLoop::current()->RunUntilIdle();
1129 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000);
1130 EXPECT_EQ(0, unlimited_usage());
1132 GetHostUsage("foo.com", kPerm);
1133 base::MessageLoop::current()->RunUntilIdle();
1134 EXPECT_EQ(usage(), 1 + 20);
1136 GetHostUsage("buz.com", kTemp);
1137 base::MessageLoop::current()->RunUntilIdle();
1138 EXPECT_EQ(usage(), 4000 + 50000);
1141 TEST_F(QuotaManagerTest, GetUsage_WithModification) {
1142 static const MockOriginData kData[] = {
1143 { "http://foo.com/", kPerm, 1 },
1144 { "http://foo.com:1/", kPerm, 20 },
1145 { "http://bar.com/", kTemp, 300 },
1146 { "https://buz.com/", kTemp, 4000 },
1147 { "http://buz.com/", kTemp, 50000 },
1148 { "http://bar.com:1/", kPerm, 600000 },
1149 { "http://foo.com/", kTemp, 7000000 },
1152 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1153 QuotaClient::kFileSystem);
1154 RegisterClient(client);
1156 GetGlobalUsage(kPerm);
1157 base::MessageLoop::current()->RunUntilIdle();
1158 EXPECT_EQ(usage(), 1 + 20 + 600000);
1159 EXPECT_EQ(0, unlimited_usage());
1161 client->ModifyOriginAndNotify(
1162 GURL("http://foo.com/"), kPerm, 80000000);
1164 GetGlobalUsage(kPerm);
1165 base::MessageLoop::current()->RunUntilIdle();
1166 EXPECT_EQ(usage(), 1 + 20 + 600000 + 80000000);
1167 EXPECT_EQ(0, unlimited_usage());
1169 GetGlobalUsage(kTemp);
1170 base::MessageLoop::current()->RunUntilIdle();
1171 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000);
1172 EXPECT_EQ(0, unlimited_usage());
1174 client->ModifyOriginAndNotify(
1175 GURL("http://foo.com/"), kTemp, 1);
1177 GetGlobalUsage(kTemp);
1178 base::MessageLoop::current()->RunUntilIdle();
1179 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000 + 1);
1180 EXPECT_EQ(0, unlimited_usage());
1182 GetHostUsage("buz.com", kTemp);
1183 base::MessageLoop::current()->RunUntilIdle();
1184 EXPECT_EQ(usage(), 4000 + 50000);
1186 client->ModifyOriginAndNotify(
1187 GURL("http://buz.com/"), kTemp, 900000000);
1189 GetHostUsage("buz.com", kTemp);
1190 base::MessageLoop::current()->RunUntilIdle();
1191 EXPECT_EQ(usage(), 4000 + 50000 + 900000000);
1194 TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) {
1195 static const MockOriginData kData[] = {
1196 { "http://foo.com/", kTemp, 1 },
1197 { "http://foo.com:1/", kTemp, 20 },
1198 { "http://foo.com/", kPerm, 300 },
1199 { "http://bar.com/", kTemp, 4000 },
1201 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1202 QuotaClient::kFileSystem);
1203 RegisterClient(client);
1205 GetGlobalUsage(kTemp);
1206 base::MessageLoop::current()->RunUntilIdle();
1207 int64 predelete_global_tmp = usage();
1209 GetHostUsage("foo.com", kTemp);
1210 base::MessageLoop::current()->RunUntilIdle();
1211 int64 predelete_host_tmp = usage();
1213 GetHostUsage("foo.com", kPerm);
1214 base::MessageLoop::current()->RunUntilIdle();
1215 int64 predelete_host_pers = usage();
1217 DeleteClientOriginData(client, GURL("http://foo.com/"),
1218 kTemp);
1219 base::MessageLoop::current()->RunUntilIdle();
1220 EXPECT_EQ(kQuotaStatusOk, status());
1222 GetGlobalUsage(kTemp);
1223 base::MessageLoop::current()->RunUntilIdle();
1224 EXPECT_EQ(predelete_global_tmp - 1, usage());
1226 GetHostUsage("foo.com", kTemp);
1227 base::MessageLoop::current()->RunUntilIdle();
1228 EXPECT_EQ(predelete_host_tmp - 1, usage());
1230 GetHostUsage("foo.com", kPerm);
1231 base::MessageLoop::current()->RunUntilIdle();
1232 EXPECT_EQ(predelete_host_pers, usage());
1235 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) {
1236 GetAvailableSpace();
1237 base::MessageLoop::current()->RunUntilIdle();
1238 EXPECT_EQ(kQuotaStatusOk, status());
1239 EXPECT_LE(0, available_space());
1242 TEST_F(QuotaManagerTest, EvictOriginData) {
1243 static const MockOriginData kData1[] = {
1244 { "http://foo.com/", kTemp, 1 },
1245 { "http://foo.com:1/", kTemp, 20 },
1246 { "http://foo.com/", kPerm, 300 },
1247 { "http://bar.com/", kTemp, 4000 },
1249 static const MockOriginData kData2[] = {
1250 { "http://foo.com/", kTemp, 50000 },
1251 { "http://foo.com:1/", kTemp, 6000 },
1252 { "http://foo.com/", kPerm, 700 },
1253 { "https://foo.com/", kTemp, 80 },
1254 { "http://bar.com/", kTemp, 9 },
1256 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
1257 QuotaClient::kFileSystem);
1258 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
1259 QuotaClient::kDatabase);
1260 RegisterClient(client1);
1261 RegisterClient(client2);
1263 GetGlobalUsage(kTemp);
1264 base::MessageLoop::current()->RunUntilIdle();
1265 int64 predelete_global_tmp = usage();
1267 GetHostUsage("foo.com", kTemp);
1268 base::MessageLoop::current()->RunUntilIdle();
1269 int64 predelete_host_tmp = usage();
1271 GetHostUsage("foo.com", kPerm);
1272 base::MessageLoop::current()->RunUntilIdle();
1273 int64 predelete_host_pers = usage();
1275 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i)
1276 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown,
1277 GURL(kData1[i].origin), kData1[i].type);
1278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i)
1279 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown,
1280 GURL(kData2[i].origin), kData2[i].type);
1281 base::MessageLoop::current()->RunUntilIdle();
1283 EvictOriginData(GURL("http://foo.com/"), kTemp);
1284 base::MessageLoop::current()->RunUntilIdle();
1286 DumpOriginInfoTable();
1287 base::MessageLoop::current()->RunUntilIdle();
1289 typedef OriginInfoTableEntries::const_iterator iterator;
1290 for (iterator itr(origin_info_entries().begin()),
1291 end(origin_info_entries().end());
1292 itr != end; ++itr) {
1293 if (itr->type == kTemp)
1294 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec());
1297 GetGlobalUsage(kTemp);
1298 base::MessageLoop::current()->RunUntilIdle();
1299 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage());
1301 GetHostUsage("foo.com", kTemp);
1302 base::MessageLoop::current()->RunUntilIdle();
1303 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage());
1305 GetHostUsage("foo.com", kPerm);
1306 base::MessageLoop::current()->RunUntilIdle();
1307 EXPECT_EQ(predelete_host_pers, usage());
1310 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) {
1311 static const MockOriginData kData[] = {
1312 { "http://foo.com/", kTemp, 1 },
1313 { "http://foo.com:1/", kTemp, 20 },
1314 { "http://foo.com/", kPerm, 300 },
1315 { "http://bar.com/", kTemp, 4000 },
1317 static const int kNumberOfTemporaryOrigins = 3;
1318 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1319 QuotaClient::kFileSystem);
1320 RegisterClient(client);
1322 GetGlobalUsage(kTemp);
1323 base::MessageLoop::current()->RunUntilIdle();
1324 int64 predelete_global_tmp = usage();
1326 GetHostUsage("foo.com", kTemp);
1327 base::MessageLoop::current()->RunUntilIdle();
1328 int64 predelete_host_tmp = usage();
1330 GetHostUsage("foo.com", kPerm);
1331 base::MessageLoop::current()->RunUntilIdle();
1332 int64 predelete_host_pers = usage();
1334 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i)
1335 NotifyStorageAccessed(client, GURL(kData[i].origin), kData[i].type);
1336 base::MessageLoop::current()->RunUntilIdle();
1338 client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp);
1340 for (int i = 0;
1341 i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1;
1342 ++i) {
1343 EvictOriginData(GURL("http://foo.com/"), kTemp);
1344 base::MessageLoop::current()->RunUntilIdle();
1345 EXPECT_EQ(kQuotaErrorInvalidModification, status());
1348 DumpOriginInfoTable();
1349 base::MessageLoop::current()->RunUntilIdle();
1351 bool found_origin_in_database = false;
1352 typedef OriginInfoTableEntries::const_iterator iterator;
1353 for (iterator itr(origin_info_entries().begin()),
1354 end(origin_info_entries().end());
1355 itr != end; ++itr) {
1356 if (itr->type == kTemp &&
1357 GURL("http://foo.com/") == itr->origin) {
1358 found_origin_in_database = true;
1359 break;
1362 // The origin "http://foo.com/" should be in the database.
1363 EXPECT_TRUE(found_origin_in_database);
1365 for (size_t i = 0; i < kNumberOfTemporaryOrigins - 1; ++i) {
1366 GetLRUOrigin(kTemp);
1367 base::MessageLoop::current()->RunUntilIdle();
1368 EXPECT_FALSE(lru_origin().is_empty());
1369 // The origin "http://foo.com/" should not be in the LRU list.
1370 EXPECT_NE(std::string("http://foo.com/"), lru_origin().spec());
1371 DeleteOriginFromDatabase(lru_origin(), kTemp);
1372 base::MessageLoop::current()->RunUntilIdle();
1375 // Now the LRU list must be empty.
1376 GetLRUOrigin(kTemp);
1377 base::MessageLoop::current()->RunUntilIdle();
1378 EXPECT_TRUE(lru_origin().is_empty());
1380 // Deleting origins from the database should not affect the results of the
1381 // following checks.
1382 GetGlobalUsage(kTemp);
1383 base::MessageLoop::current()->RunUntilIdle();
1384 EXPECT_EQ(predelete_global_tmp, usage());
1386 GetHostUsage("foo.com", kTemp);
1387 base::MessageLoop::current()->RunUntilIdle();
1388 EXPECT_EQ(predelete_host_tmp, usage());
1390 GetHostUsage("foo.com", kPerm);
1391 base::MessageLoop::current()->RunUntilIdle();
1392 EXPECT_EQ(predelete_host_pers, usage());
1395 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) {
1396 static const MockOriginData kData[] = {
1397 { "http://foo.com/", kTemp, 1 },
1398 { "http://foo.com:1/", kTemp, 20 },
1399 { "http://foo.com/", kPerm, 300 },
1400 { "http://unlimited/", kTemp, 4000 },
1403 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
1404 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1405 QuotaClient::kFileSystem);
1406 RegisterClient(client);
1408 SetTemporaryGlobalQuota(10000000);
1409 base::MessageLoop::current()->RunUntilIdle();
1411 GetUsageAndQuotaForEviction();
1412 base::MessageLoop::current()->RunUntilIdle();
1413 EXPECT_EQ(kQuotaStatusOk, status());
1414 EXPECT_EQ(4021, usage());
1415 EXPECT_EQ(4000, unlimited_usage());
1416 EXPECT_EQ(10000000, quota());
1417 EXPECT_LE(0, available_space());
1420 TEST_F(QuotaManagerTest, DeleteHostDataSimple) {
1421 static const MockOriginData kData[] = {
1422 { "http://foo.com/", kTemp, 1 },
1424 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1425 QuotaClient::kFileSystem);
1426 RegisterClient(client);
1428 GetGlobalUsage(kTemp);
1429 base::MessageLoop::current()->RunUntilIdle();
1430 const int64 predelete_global_tmp = usage();
1432 GetHostUsage("foo.com", kTemp);
1433 base::MessageLoop::current()->RunUntilIdle();
1434 int64 predelete_host_tmp = usage();
1436 GetHostUsage("foo.com", kPerm);
1437 base::MessageLoop::current()->RunUntilIdle();
1438 int64 predelete_host_pers = usage();
1440 DeleteHostData(std::string(), kTemp, kAllClients);
1441 base::MessageLoop::current()->RunUntilIdle();
1442 EXPECT_EQ(kQuotaStatusOk, status());
1444 GetGlobalUsage(kTemp);
1445 base::MessageLoop::current()->RunUntilIdle();
1446 EXPECT_EQ(predelete_global_tmp, usage());
1448 GetHostUsage("foo.com", kTemp);
1449 base::MessageLoop::current()->RunUntilIdle();
1450 EXPECT_EQ(predelete_host_tmp, usage());
1452 GetHostUsage("foo.com", kPerm);
1453 base::MessageLoop::current()->RunUntilIdle();
1454 EXPECT_EQ(predelete_host_pers, usage());
1456 DeleteHostData("foo.com", kTemp, kAllClients);
1457 base::MessageLoop::current()->RunUntilIdle();
1458 EXPECT_EQ(kQuotaStatusOk, status());
1460 GetGlobalUsage(kTemp);
1461 base::MessageLoop::current()->RunUntilIdle();
1462 EXPECT_EQ(predelete_global_tmp - 1, usage());
1464 GetHostUsage("foo.com", kTemp);
1465 base::MessageLoop::current()->RunUntilIdle();
1466 EXPECT_EQ(predelete_host_tmp - 1, usage());
1468 GetHostUsage("foo.com", kPerm);
1469 base::MessageLoop::current()->RunUntilIdle();
1470 EXPECT_EQ(predelete_host_pers, usage());
1473 TEST_F(QuotaManagerTest, DeleteHostDataMultiple) {
1474 static const MockOriginData kData1[] = {
1475 { "http://foo.com/", kTemp, 1 },
1476 { "http://foo.com:1/", kTemp, 20 },
1477 { "http://foo.com/", kPerm, 300 },
1478 { "http://bar.com/", kTemp, 4000 },
1480 static const MockOriginData kData2[] = {
1481 { "http://foo.com/", kTemp, 50000 },
1482 { "http://foo.com:1/", kTemp, 6000 },
1483 { "http://foo.com/", kPerm, 700 },
1484 { "https://foo.com/", kTemp, 80 },
1485 { "http://bar.com/", kTemp, 9 },
1487 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
1488 QuotaClient::kFileSystem);
1489 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
1490 QuotaClient::kDatabase);
1491 RegisterClient(client1);
1492 RegisterClient(client2);
1494 GetGlobalUsage(kTemp);
1495 base::MessageLoop::current()->RunUntilIdle();
1496 const int64 predelete_global_tmp = usage();
1498 GetHostUsage("foo.com", kTemp);
1499 base::MessageLoop::current()->RunUntilIdle();
1500 const int64 predelete_foo_tmp = usage();
1502 GetHostUsage("bar.com", kTemp);
1503 base::MessageLoop::current()->RunUntilIdle();
1504 const int64 predelete_bar_tmp = usage();
1506 GetHostUsage("foo.com", kPerm);
1507 base::MessageLoop::current()->RunUntilIdle();
1508 const int64 predelete_foo_pers = usage();
1510 GetHostUsage("bar.com", kPerm);
1511 base::MessageLoop::current()->RunUntilIdle();
1512 const int64 predelete_bar_pers = usage();
1514 reset_status_callback_count();
1515 DeleteHostData("foo.com", kTemp, kAllClients);
1516 DeleteHostData("bar.com", kTemp, kAllClients);
1517 DeleteHostData("foo.com", kTemp, kAllClients);
1518 base::MessageLoop::current()->RunUntilIdle();
1520 EXPECT_EQ(3, status_callback_count());
1522 DumpOriginInfoTable();
1523 base::MessageLoop::current()->RunUntilIdle();
1525 typedef OriginInfoTableEntries::const_iterator iterator;
1526 for (iterator itr(origin_info_entries().begin()),
1527 end(origin_info_entries().end());
1528 itr != end; ++itr) {
1529 if (itr->type == kTemp) {
1530 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec());
1531 EXPECT_NE(std::string("http://foo.com:1/"), itr->origin.spec());
1532 EXPECT_NE(std::string("https://foo.com/"), itr->origin.spec());
1533 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec());
1537 GetGlobalUsage(kTemp);
1538 base::MessageLoop::current()->RunUntilIdle();
1539 EXPECT_EQ(predelete_global_tmp - (1 + 20 + 4000 + 50000 + 6000 + 80 + 9),
1540 usage());
1542 GetHostUsage("foo.com", kTemp);
1543 base::MessageLoop::current()->RunUntilIdle();
1544 EXPECT_EQ(predelete_foo_tmp - (1 + 20 + 50000 + 6000 + 80), usage());
1546 GetHostUsage("bar.com", kTemp);
1547 base::MessageLoop::current()->RunUntilIdle();
1548 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage());
1550 GetHostUsage("foo.com", kPerm);
1551 base::MessageLoop::current()->RunUntilIdle();
1552 EXPECT_EQ(predelete_foo_pers, usage());
1554 GetHostUsage("bar.com", kPerm);
1555 base::MessageLoop::current()->RunUntilIdle();
1556 EXPECT_EQ(predelete_bar_pers, usage());
1559 // Single-run DeleteOriginData cases must be well covered by
1560 // EvictOriginData tests.
1561 TEST_F(QuotaManagerTest, DeleteOriginDataMultiple) {
1562 static const MockOriginData kData1[] = {
1563 { "http://foo.com/", kTemp, 1 },
1564 { "http://foo.com:1/", kTemp, 20 },
1565 { "http://foo.com/", kPerm, 300 },
1566 { "http://bar.com/", kTemp, 4000 },
1568 static const MockOriginData kData2[] = {
1569 { "http://foo.com/", kTemp, 50000 },
1570 { "http://foo.com:1/", kTemp, 6000 },
1571 { "http://foo.com/", kPerm, 700 },
1572 { "https://foo.com/", kTemp, 80 },
1573 { "http://bar.com/", kTemp, 9 },
1575 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
1576 QuotaClient::kFileSystem);
1577 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
1578 QuotaClient::kDatabase);
1579 RegisterClient(client1);
1580 RegisterClient(client2);
1582 GetGlobalUsage(kTemp);
1583 base::MessageLoop::current()->RunUntilIdle();
1584 const int64 predelete_global_tmp = usage();
1586 GetHostUsage("foo.com", kTemp);
1587 base::MessageLoop::current()->RunUntilIdle();
1588 const int64 predelete_foo_tmp = usage();
1590 GetHostUsage("bar.com", kTemp);
1591 base::MessageLoop::current()->RunUntilIdle();
1592 const int64 predelete_bar_tmp = usage();
1594 GetHostUsage("foo.com", kPerm);
1595 base::MessageLoop::current()->RunUntilIdle();
1596 const int64 predelete_foo_pers = usage();
1598 GetHostUsage("bar.com", kPerm);
1599 base::MessageLoop::current()->RunUntilIdle();
1600 const int64 predelete_bar_pers = usage();
1602 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i)
1603 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown,
1604 GURL(kData1[i].origin), kData1[i].type);
1605 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i)
1606 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown,
1607 GURL(kData2[i].origin), kData2[i].type);
1608 base::MessageLoop::current()->RunUntilIdle();
1610 reset_status_callback_count();
1611 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
1612 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients);
1613 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
1614 base::MessageLoop::current()->RunUntilIdle();
1616 EXPECT_EQ(3, status_callback_count());
1618 DumpOriginInfoTable();
1619 base::MessageLoop::current()->RunUntilIdle();
1621 typedef OriginInfoTableEntries::const_iterator iterator;
1622 for (iterator itr(origin_info_entries().begin()),
1623 end(origin_info_entries().end());
1624 itr != end; ++itr) {
1625 if (itr->type == kTemp) {
1626 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec());
1627 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec());
1631 GetGlobalUsage(kTemp);
1632 base::MessageLoop::current()->RunUntilIdle();
1633 EXPECT_EQ(predelete_global_tmp - (1 + 4000 + 50000 + 9), usage());
1635 GetHostUsage("foo.com", kTemp);
1636 base::MessageLoop::current()->RunUntilIdle();
1637 EXPECT_EQ(predelete_foo_tmp - (1 + 50000), usage());
1639 GetHostUsage("bar.com", kTemp);
1640 base::MessageLoop::current()->RunUntilIdle();
1641 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage());
1643 GetHostUsage("foo.com", kPerm);
1644 base::MessageLoop::current()->RunUntilIdle();
1645 EXPECT_EQ(predelete_foo_pers, usage());
1647 GetHostUsage("bar.com", kPerm);
1648 base::MessageLoop::current()->RunUntilIdle();
1649 EXPECT_EQ(predelete_bar_pers, usage());
1652 TEST_F(QuotaManagerTest, GetCachedOrigins) {
1653 static const MockOriginData kData[] = {
1654 { "http://a.com/", kTemp, 1 },
1655 { "http://a.com:1/", kTemp, 20 },
1656 { "http://b.com/", kPerm, 300 },
1657 { "http://c.com/", kTemp, 4000 },
1659 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1660 QuotaClient::kFileSystem);
1661 RegisterClient(client);
1663 // TODO(kinuko): Be careful when we add cache pruner.
1665 std::set<GURL> origins;
1666 GetCachedOrigins(kTemp, &origins);
1667 EXPECT_TRUE(origins.empty());
1669 // No matter how we make queries the quota manager tries to cache all
1670 // the origins at startup.
1671 GetHostUsage("a.com", kTemp);
1672 base::MessageLoop::current()->RunUntilIdle();
1673 GetCachedOrigins(kTemp, &origins);
1674 EXPECT_EQ(3U, origins.size());
1676 GetHostUsage("b.com", kTemp);
1677 base::MessageLoop::current()->RunUntilIdle();
1678 GetCachedOrigins(kTemp, &origins);
1679 EXPECT_EQ(3U, origins.size());
1681 GetCachedOrigins(kPerm, &origins);
1682 EXPECT_TRUE(origins.empty());
1684 GetGlobalUsage(kTemp);
1685 base::MessageLoop::current()->RunUntilIdle();
1686 GetCachedOrigins(kTemp, &origins);
1687 EXPECT_EQ(3U, origins.size());
1689 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) {
1690 if (kData[i].type == kTemp)
1691 EXPECT_TRUE(origins.find(GURL(kData[i].origin)) != origins.end());
1695 TEST_F(QuotaManagerTest, NotifyAndLRUOrigin) {
1696 static const MockOriginData kData[] = {
1697 { "http://a.com/", kTemp, 0 },
1698 { "http://a.com:1/", kTemp, 0 },
1699 { "https://a.com/", kTemp, 0 },
1700 { "http://b.com/", kPerm, 0 }, // persistent
1701 { "http://c.com/", kTemp, 0 },
1703 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1704 QuotaClient::kFileSystem);
1705 RegisterClient(client);
1707 GURL origin;
1708 GetLRUOrigin(kTemp);
1709 base::MessageLoop::current()->RunUntilIdle();
1710 EXPECT_TRUE(lru_origin().is_empty());
1712 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp);
1713 GetLRUOrigin(kTemp);
1714 base::MessageLoop::current()->RunUntilIdle();
1715 EXPECT_EQ("http://a.com/", lru_origin().spec());
1717 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm);
1718 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp);
1719 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp);
1720 GetLRUOrigin(kTemp);
1721 base::MessageLoop::current()->RunUntilIdle();
1722 EXPECT_EQ("http://a.com/", lru_origin().spec());
1724 DeleteOriginFromDatabase(lru_origin(), kTemp);
1725 GetLRUOrigin(kTemp);
1726 base::MessageLoop::current()->RunUntilIdle();
1727 EXPECT_EQ("https://a.com/", lru_origin().spec());
1729 DeleteOriginFromDatabase(lru_origin(), kTemp);
1730 GetLRUOrigin(kTemp);
1731 base::MessageLoop::current()->RunUntilIdle();
1732 EXPECT_EQ("http://c.com/", lru_origin().spec());
1735 TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) {
1736 static const MockOriginData kData[] = {
1737 { "http://a.com/", kTemp, 0 },
1738 { "http://a.com:1/", kTemp, 0 },
1739 { "https://a.com/", kTemp, 0 },
1740 { "http://b.com/", kPerm, 0 }, // persistent
1741 { "http://c.com/", kTemp, 0 },
1743 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1744 QuotaClient::kFileSystem);
1745 RegisterClient(client);
1747 GURL origin;
1748 GetLRUOrigin(kTemp);
1749 base::MessageLoop::current()->RunUntilIdle();
1750 EXPECT_TRUE(lru_origin().is_empty());
1752 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp);
1753 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm);
1754 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp);
1755 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp);
1757 GetLRUOrigin(kTemp);
1758 base::MessageLoop::current()->RunUntilIdle();
1759 EXPECT_EQ("http://a.com/", lru_origin().spec());
1761 // Notify origin http://a.com is in use.
1762 NotifyOriginInUse(GURL("http://a.com/"));
1763 GetLRUOrigin(kTemp);
1764 base::MessageLoop::current()->RunUntilIdle();
1765 EXPECT_EQ("https://a.com/", lru_origin().spec());
1767 // Notify origin https://a.com is in use while GetLRUOrigin is running.
1768 GetLRUOrigin(kTemp);
1769 NotifyOriginInUse(GURL("https://a.com/"));
1770 base::MessageLoop::current()->RunUntilIdle();
1771 // Post-filtering must have excluded the returned origin, so we will
1772 // see empty result here.
1773 EXPECT_TRUE(lru_origin().is_empty());
1775 // Notify access for http://c.com while GetLRUOrigin is running.
1776 GetLRUOrigin(kTemp);
1777 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp);
1778 base::MessageLoop::current()->RunUntilIdle();
1779 // Post-filtering must have excluded the returned origin, so we will
1780 // see empty result here.
1781 EXPECT_TRUE(lru_origin().is_empty());
1783 NotifyOriginNoLongerInUse(GURL("http://a.com/"));
1784 NotifyOriginNoLongerInUse(GURL("https://a.com/"));
1785 GetLRUOrigin(kTemp);
1786 base::MessageLoop::current()->RunUntilIdle();
1787 EXPECT_EQ("http://a.com/", lru_origin().spec());
1790 TEST_F(QuotaManagerTest, GetOriginsModifiedSince) {
1791 static const MockOriginData kData[] = {
1792 { "http://a.com/", kTemp, 0 },
1793 { "http://a.com:1/", kTemp, 0 },
1794 { "https://a.com/", kTemp, 0 },
1795 { "http://b.com/", kPerm, 0 }, // persistent
1796 { "http://c.com/", kTemp, 0 },
1798 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
1799 QuotaClient::kFileSystem);
1800 RegisterClient(client);
1802 GetOriginsModifiedSince(kTemp, base::Time());
1803 base::MessageLoop::current()->RunUntilIdle();
1804 EXPECT_TRUE(modified_origins().empty());
1805 EXPECT_EQ(modified_origins_type(), kTemp);
1807 base::Time time1 = client->IncrementMockTime();
1808 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10);
1809 client->ModifyOriginAndNotify(GURL("http://a.com:1/"), kTemp, 10);
1810 client->ModifyOriginAndNotify(GURL("http://b.com/"), kPerm, 10);
1811 base::Time time2 = client->IncrementMockTime();
1812 client->ModifyOriginAndNotify(GURL("https://a.com/"), kTemp, 10);
1813 client->ModifyOriginAndNotify(GURL("http://c.com/"), kTemp, 10);
1814 base::Time time3 = client->IncrementMockTime();
1816 GetOriginsModifiedSince(kTemp, time1);
1817 base::MessageLoop::current()->RunUntilIdle();
1818 EXPECT_EQ(4U, modified_origins().size());
1819 EXPECT_EQ(modified_origins_type(), kTemp);
1820 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) {
1821 if (kData[i].type == kTemp)
1822 EXPECT_EQ(1U, modified_origins().count(GURL(kData[i].origin)));
1825 GetOriginsModifiedSince(kTemp, time2);
1826 base::MessageLoop::current()->RunUntilIdle();
1827 EXPECT_EQ(2U, modified_origins().size());
1829 GetOriginsModifiedSince(kTemp, time3);
1830 base::MessageLoop::current()->RunUntilIdle();
1831 EXPECT_TRUE(modified_origins().empty());
1832 EXPECT_EQ(modified_origins_type(), kTemp);
1834 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10);
1836 GetOriginsModifiedSince(kTemp, time3);
1837 base::MessageLoop::current()->RunUntilIdle();
1838 EXPECT_EQ(1U, modified_origins().size());
1839 EXPECT_EQ(1U, modified_origins().count(GURL("http://a.com/")));
1840 EXPECT_EQ(modified_origins_type(), kTemp);
1843 TEST_F(QuotaManagerTest, DumpQuotaTable) {
1844 SetPersistentHostQuota("example1.com", 1);
1845 SetPersistentHostQuota("example2.com", 20);
1846 SetPersistentHostQuota("example3.com", 300);
1847 base::MessageLoop::current()->RunUntilIdle();
1849 DumpQuotaTable();
1850 base::MessageLoop::current()->RunUntilIdle();
1852 const QuotaTableEntry kEntries[] = {
1853 QuotaTableEntry("example1.com", kPerm, 1),
1854 QuotaTableEntry("example2.com", kPerm, 20),
1855 QuotaTableEntry("example3.com", kPerm, 300),
1857 std::set<QuotaTableEntry> entries
1858 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries));
1860 typedef QuotaTableEntries::const_iterator iterator;
1861 for (iterator itr(quota_entries().begin()), end(quota_entries().end());
1862 itr != end; ++itr) {
1863 SCOPED_TRACE(testing::Message()
1864 << "host = " << itr->host << ", "
1865 << "quota = " << itr->quota);
1866 EXPECT_EQ(1u, entries.erase(*itr));
1868 EXPECT_TRUE(entries.empty());
1871 TEST_F(QuotaManagerTest, DumpOriginInfoTable) {
1872 using std::make_pair;
1874 quota_manager()->NotifyStorageAccessed(
1875 QuotaClient::kUnknown,
1876 GURL("http://example.com/"),
1877 kTemp);
1878 quota_manager()->NotifyStorageAccessed(
1879 QuotaClient::kUnknown,
1880 GURL("http://example.com/"),
1881 kPerm);
1882 quota_manager()->NotifyStorageAccessed(
1883 QuotaClient::kUnknown,
1884 GURL("http://example.com/"),
1885 kPerm);
1886 base::MessageLoop::current()->RunUntilIdle();
1888 DumpOriginInfoTable();
1889 base::MessageLoop::current()->RunUntilIdle();
1891 typedef std::pair<GURL, StorageType> TypedOrigin;
1892 typedef std::pair<TypedOrigin, int> Entry;
1893 const Entry kEntries[] = {
1894 make_pair(make_pair(GURL("http://example.com/"), kTemp), 1),
1895 make_pair(make_pair(GURL("http://example.com/"), kPerm), 2),
1897 std::set<Entry> entries
1898 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries));
1900 typedef OriginInfoTableEntries::const_iterator iterator;
1901 for (iterator itr(origin_info_entries().begin()),
1902 end(origin_info_entries().end());
1903 itr != end; ++itr) {
1904 SCOPED_TRACE(testing::Message()
1905 << "host = " << itr->origin << ", "
1906 << "type = " << itr->type << ", "
1907 << "used_count = " << itr->used_count);
1908 EXPECT_EQ(1u, entries.erase(
1909 make_pair(make_pair(itr->origin, itr->type),
1910 itr->used_count)));
1912 EXPECT_TRUE(entries.empty());
1915 TEST_F(QuotaManagerTest, QuotaForEmptyHost) {
1916 GetPersistentHostQuota(std::string());
1917 base::MessageLoop::current()->RunUntilIdle();
1918 EXPECT_EQ(kQuotaStatusOk, status());
1919 EXPECT_EQ(0, quota());
1921 SetPersistentHostQuota(std::string(), 10);
1922 base::MessageLoop::current()->RunUntilIdle();
1923 EXPECT_EQ(kQuotaErrorNotSupported, status());
1926 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleOrigin) {
1927 static const MockOriginData kData1[] = {
1928 { "http://foo.com/", kTemp, 1 },
1930 static const MockOriginData kData2[] = {
1931 { "http://foo.com/", kTemp, 2 },
1933 static const MockOriginData kData3[] = {
1934 { "http://foo.com/", kTemp, 4 },
1936 static const MockOriginData kData4[] = {
1937 { "http://foo.com/", kTemp, 8 },
1939 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
1940 QuotaClient::kFileSystem);
1941 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
1942 QuotaClient::kAppcache);
1943 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3),
1944 QuotaClient::kDatabase);
1945 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4),
1946 QuotaClient::kIndexedDatabase);
1947 RegisterClient(client1);
1948 RegisterClient(client2);
1949 RegisterClient(client3);
1950 RegisterClient(client4);
1952 GetHostUsage("foo.com", kTemp);
1953 base::MessageLoop::current()->RunUntilIdle();
1954 const int64 predelete_foo_tmp = usage();
1956 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kFileSystem);
1957 base::MessageLoop::current()->RunUntilIdle();
1958 GetHostUsage("foo.com", kTemp);
1959 base::MessageLoop::current()->RunUntilIdle();
1960 EXPECT_EQ(predelete_foo_tmp - 1, usage());
1962 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kAppcache);
1963 base::MessageLoop::current()->RunUntilIdle();
1964 GetHostUsage("foo.com", kTemp);
1965 base::MessageLoop::current()->RunUntilIdle();
1966 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage());
1968 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kDatabase);
1969 base::MessageLoop::current()->RunUntilIdle();
1970 GetHostUsage("foo.com", kTemp);
1971 base::MessageLoop::current()->RunUntilIdle();
1972 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage());
1974 DeleteOriginData(GURL("http://foo.com/"), kTemp,
1975 QuotaClient::kIndexedDatabase);
1976 base::MessageLoop::current()->RunUntilIdle();
1977 GetHostUsage("foo.com", kTemp);
1978 base::MessageLoop::current()->RunUntilIdle();
1979 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage());
1982 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleHost) {
1983 static const MockOriginData kData1[] = {
1984 { "http://foo.com:1111/", kTemp, 1 },
1986 static const MockOriginData kData2[] = {
1987 { "http://foo.com:2222/", kTemp, 2 },
1989 static const MockOriginData kData3[] = {
1990 { "http://foo.com:3333/", kTemp, 4 },
1992 static const MockOriginData kData4[] = {
1993 { "http://foo.com:4444/", kTemp, 8 },
1995 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
1996 QuotaClient::kFileSystem);
1997 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
1998 QuotaClient::kAppcache);
1999 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3),
2000 QuotaClient::kDatabase);
2001 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4),
2002 QuotaClient::kIndexedDatabase);
2003 RegisterClient(client1);
2004 RegisterClient(client2);
2005 RegisterClient(client3);
2006 RegisterClient(client4);
2008 GetHostUsage("foo.com", kTemp);
2009 base::MessageLoop::current()->RunUntilIdle();
2010 const int64 predelete_foo_tmp = usage();
2012 DeleteHostData("foo.com", kTemp, QuotaClient::kFileSystem);
2013 base::MessageLoop::current()->RunUntilIdle();
2014 GetHostUsage("foo.com", kTemp);
2015 base::MessageLoop::current()->RunUntilIdle();
2016 EXPECT_EQ(predelete_foo_tmp - 1, usage());
2018 DeleteHostData("foo.com", kTemp, QuotaClient::kAppcache);
2019 base::MessageLoop::current()->RunUntilIdle();
2020 GetHostUsage("foo.com", kTemp);
2021 base::MessageLoop::current()->RunUntilIdle();
2022 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage());
2024 DeleteHostData("foo.com", kTemp, QuotaClient::kDatabase);
2025 base::MessageLoop::current()->RunUntilIdle();
2026 GetHostUsage("foo.com", kTemp);
2027 base::MessageLoop::current()->RunUntilIdle();
2028 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage());
2030 DeleteHostData("foo.com", kTemp, QuotaClient::kIndexedDatabase);
2031 base::MessageLoop::current()->RunUntilIdle();
2032 GetHostUsage("foo.com", kTemp);
2033 base::MessageLoop::current()->RunUntilIdle();
2034 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage());
2037 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleOrigin) {
2038 static const MockOriginData kData1[] = {
2039 { "http://foo.com/", kTemp, 1 },
2041 static const MockOriginData kData2[] = {
2042 { "http://foo.com/", kTemp, 2 },
2044 static const MockOriginData kData3[] = {
2045 { "http://foo.com/", kTemp, 4 },
2047 static const MockOriginData kData4[] = {
2048 { "http://foo.com/", kTemp, 8 },
2050 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
2051 QuotaClient::kFileSystem);
2052 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
2053 QuotaClient::kAppcache);
2054 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3),
2055 QuotaClient::kDatabase);
2056 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4),
2057 QuotaClient::kIndexedDatabase);
2058 RegisterClient(client1);
2059 RegisterClient(client2);
2060 RegisterClient(client3);
2061 RegisterClient(client4);
2063 GetHostUsage("foo.com", kTemp);
2064 base::MessageLoop::current()->RunUntilIdle();
2065 const int64 predelete_foo_tmp = usage();
2067 DeleteOriginData(GURL("http://foo.com/"), kTemp,
2068 QuotaClient::kFileSystem | QuotaClient::kDatabase);
2069 base::MessageLoop::current()->RunUntilIdle();
2070 GetHostUsage("foo.com", kTemp);
2071 base::MessageLoop::current()->RunUntilIdle();
2072 EXPECT_EQ(predelete_foo_tmp - 4 - 1, usage());
2074 DeleteOriginData(GURL("http://foo.com/"), kTemp,
2075 QuotaClient::kAppcache | QuotaClient::kIndexedDatabase);
2076 base::MessageLoop::current()->RunUntilIdle();
2077 GetHostUsage("foo.com", kTemp);
2078 base::MessageLoop::current()->RunUntilIdle();
2079 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage());
2082 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleHost) {
2083 static const MockOriginData kData1[] = {
2084 { "http://foo.com:1111/", kTemp, 1 },
2086 static const MockOriginData kData2[] = {
2087 { "http://foo.com:2222/", kTemp, 2 },
2089 static const MockOriginData kData3[] = {
2090 { "http://foo.com:3333/", kTemp, 4 },
2092 static const MockOriginData kData4[] = {
2093 { "http://foo.com:4444/", kTemp, 8 },
2095 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1),
2096 QuotaClient::kFileSystem);
2097 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2),
2098 QuotaClient::kAppcache);
2099 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3),
2100 QuotaClient::kDatabase);
2101 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4),
2102 QuotaClient::kIndexedDatabase);
2103 RegisterClient(client1);
2104 RegisterClient(client2);
2105 RegisterClient(client3);
2106 RegisterClient(client4);
2108 GetHostUsage("foo.com", kTemp);
2109 base::MessageLoop::current()->RunUntilIdle();
2110 const int64 predelete_foo_tmp = usage();
2112 DeleteHostData("foo.com", kTemp,
2113 QuotaClient::kFileSystem | QuotaClient::kAppcache);
2114 base::MessageLoop::current()->RunUntilIdle();
2115 GetHostUsage("foo.com", kTemp);
2116 base::MessageLoop::current()->RunUntilIdle();
2117 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage());
2119 DeleteHostData("foo.com", kTemp,
2120 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase);
2121 base::MessageLoop::current()->RunUntilIdle();
2122 GetHostUsage("foo.com", kTemp);
2123 base::MessageLoop::current()->RunUntilIdle();
2124 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage());
2127 TEST_F(QuotaManagerTest, GetUsageAndQuota_Incognito) {
2128 ResetQuotaManager(true);
2130 static const MockOriginData kData[] = {
2131 { "http://foo.com/", kTemp, 10 },
2132 { "http://foo.com/", kPerm, 80 },
2134 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData),
2135 QuotaClient::kFileSystem));
2137 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
2138 base::MessageLoop::current()->RunUntilIdle();
2139 EXPECT_EQ(kQuotaStatusOk, status());
2140 EXPECT_EQ(80, usage());
2141 EXPECT_EQ(0, quota());
2143 SetTemporaryGlobalQuota(100);
2144 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2145 base::MessageLoop::current()->RunUntilIdle();
2146 EXPECT_EQ(kQuotaStatusOk, status());
2147 EXPECT_EQ(10, usage());
2148 EXPECT_LE(std::min(static_cast<int64>(100 / kPerHostTemporaryPortion),
2149 QuotaManager::kIncognitoDefaultQuotaLimit), quota());
2151 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/"));
2152 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
2153 base::MessageLoop::current()->RunUntilIdle();
2154 EXPECT_EQ(kQuotaStatusOk, status());
2155 EXPECT_EQ(80, usage());
2156 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota());
2158 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2159 base::MessageLoop::current()->RunUntilIdle();
2160 EXPECT_EQ(kQuotaStatusOk, status());
2161 EXPECT_EQ(10, usage());
2162 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota());
2165 } // namespace quota