| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_callback_factory.h" | 10 #include "base/memory/scoped_callback_factory.h" |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 { "http://unlimited/", kTemp, 4000 }, | 703 { "http://unlimited/", kTemp, 4000 }, |
| 704 }; | 704 }; |
| 705 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 705 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
| 706 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData)); | 706 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData)); |
| 707 RegisterClient(client); | 707 RegisterClient(client); |
| 708 | 708 |
| 709 // Test when not overbugdet. | 709 // Test when not overbugdet. |
| 710 SetTemporaryGlobalQuota(1000); | 710 SetTemporaryGlobalQuota(1000); |
| 711 MessageLoop::current()->RunAllPending(); | 711 MessageLoop::current()->RunAllPending(); |
| 712 | 712 |
| 713 GetGlobalUsage(kTemp); |
| 714 MessageLoop::current()->RunAllPending(); |
| 715 EXPECT_EQ(10 + 50 + 4000, usage()); |
| 716 EXPECT_EQ(4000, unlimited_usage()); |
| 717 |
| 713 const int kPerHostQuotaFor1000 = | 718 const int kPerHostQuotaFor1000 = |
| 714 1000 / QuotaManager::kPerHostTemporaryPortion; | 719 1000 / QuotaManager::kPerHostTemporaryPortion; |
| 715 | 720 |
| 716 GetUsageAndQuota(GURL("http://usage10/"), kTemp); | 721 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
| 717 MessageLoop::current()->RunAllPending(); | 722 MessageLoop::current()->RunAllPending(); |
| 718 EXPECT_EQ(kQuotaStatusOk, status()); | 723 EXPECT_EQ(kQuotaStatusOk, status()); |
| 719 EXPECT_EQ(10, usage()); | 724 EXPECT_EQ(10, usage()); |
| 720 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 725 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
| 721 | 726 |
| 722 GetUsageAndQuota(GURL("http://usage50/"), kTemp); | 727 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 748 MessageLoop::current()->RunAllPending(); | 753 MessageLoop::current()->RunAllPending(); |
| 749 EXPECT_EQ(kQuotaStatusOk, status()); | 754 EXPECT_EQ(kQuotaStatusOk, status()); |
| 750 EXPECT_EQ(50, usage()); | 755 EXPECT_EQ(50, usage()); |
| 751 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 756 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
| 752 | 757 |
| 753 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 758 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
| 754 MessageLoop::current()->RunAllPending(); | 759 MessageLoop::current()->RunAllPending(); |
| 755 EXPECT_EQ(kQuotaStatusOk, status()); | 760 EXPECT_EQ(kQuotaStatusOk, status()); |
| 756 EXPECT_EQ(4000, usage()); | 761 EXPECT_EQ(4000, usage()); |
| 757 EXPECT_EQ(kint64max, quota()); | 762 EXPECT_EQ(kint64max, quota()); |
| 763 |
| 764 // Revoke the unlimited rights and make sure the change is noticed. |
| 765 mock_special_storage_policy()->Reset(); |
| 766 mock_special_storage_policy()->NotifyChanged(); |
| 767 |
| 768 GetGlobalUsage(kTemp); |
| 769 MessageLoop::current()->RunAllPending(); |
| 770 EXPECT_EQ(10 + 50 + 4000, usage()); |
| 771 EXPECT_EQ(0, unlimited_usage()); |
| 772 |
| 773 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
| 774 MessageLoop::current()->RunAllPending(); |
| 775 EXPECT_EQ(kQuotaStatusOk, status()); |
| 776 EXPECT_EQ(10, usage()); |
| 777 EXPECT_EQ(10, quota()); // should be clamped to our current usage |
| 778 |
| 779 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
| 780 MessageLoop::current()->RunAllPending(); |
| 781 EXPECT_EQ(kQuotaStatusOk, status()); |
| 782 EXPECT_EQ(50, usage()); |
| 783 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
| 784 |
| 785 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
| 786 MessageLoop::current()->RunAllPending(); |
| 787 EXPECT_EQ(kQuotaStatusOk, status()); |
| 788 EXPECT_EQ(4000, usage()); |
| 789 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
| 758 } | 790 } |
| 759 | 791 |
| 760 TEST_F(QuotaManagerTest, OriginInUse) { | 792 TEST_F(QuotaManagerTest, OriginInUse) { |
| 761 const GURL kFooOrigin("http://foo.com/"); | 793 const GURL kFooOrigin("http://foo.com/"); |
| 762 const GURL kBarOrigin("http://bar.com/"); | 794 const GURL kBarOrigin("http://bar.com/"); |
| 763 | 795 |
| 764 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); | 796 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); |
| 765 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 1 | 797 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 1 |
| 766 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin)); | 798 EXPECT_TRUE(quota_manager()->IsOriginInUse(kFooOrigin)); |
| 767 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 2 | 799 quota_manager()->NotifyOriginInUse(kFooOrigin); // count of 2 |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 GetPersistentHostQuota(std::string()); | 1585 GetPersistentHostQuota(std::string()); |
| 1554 MessageLoop::current()->RunAllPending(); | 1586 MessageLoop::current()->RunAllPending(); |
| 1555 EXPECT_EQ(kQuotaStatusOk, status()); | 1587 EXPECT_EQ(kQuotaStatusOk, status()); |
| 1556 EXPECT_EQ(0, quota()); | 1588 EXPECT_EQ(0, quota()); |
| 1557 | 1589 |
| 1558 SetPersistentHostQuota(std::string(), 10); | 1590 SetPersistentHostQuota(std::string(), 10); |
| 1559 MessageLoop::current()->RunAllPending(); | 1591 MessageLoop::current()->RunAllPending(); |
| 1560 EXPECT_EQ(kQuotaErrorNotSupported, status()); | 1592 EXPECT_EQ(kQuotaErrorNotSupported, status()); |
| 1561 } | 1593 } |
| 1562 } // namespace quota | 1594 } // namespace quota |
| OLD | NEW |