OLD | NEW |
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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SetTemporaryGlobalQuota(100); |
846 base::RunLoop().RunUntilIdle(); | 846 base::RunLoop().RunUntilIdle(); |
847 | 847 |
| 848 // not sure this test is relevant anymore? |
| 849 |
848 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; | 850 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; |
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[] = { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 | 952 |
951 GetGlobalUsage(kTemp); | 953 GetGlobalUsage(kTemp); |
952 base::RunLoop().RunUntilIdle(); | 954 base::RunLoop().RunUntilIdle(); |
953 EXPECT_EQ(10 + 50 + 4000, usage()); | 955 EXPECT_EQ(10 + 50 + 4000, usage()); |
954 EXPECT_EQ(0, unlimited_usage()); | 956 EXPECT_EQ(0, unlimited_usage()); |
955 | 957 |
956 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); | 958 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); |
957 base::RunLoop().RunUntilIdle(); | 959 base::RunLoop().RunUntilIdle(); |
958 EXPECT_EQ(kQuotaStatusOk, status()); | 960 EXPECT_EQ(kQuotaStatusOk, status()); |
959 EXPECT_EQ(10, usage()); | 961 EXPECT_EQ(10, usage()); |
960 EXPECT_EQ(10, quota()); // should be clamped to our current usage | 962 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
961 | 963 |
962 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); | 964 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); |
963 base::RunLoop().RunUntilIdle(); | 965 base::RunLoop().RunUntilIdle(); |
964 EXPECT_EQ(kQuotaStatusOk, status()); | 966 EXPECT_EQ(kQuotaStatusOk, status()); |
965 EXPECT_EQ(50, usage()); | 967 EXPECT_EQ(50, usage()); |
966 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 968 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
967 | 969 |
968 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); | 970 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); |
969 base::RunLoop().RunUntilIdle(); | 971 base::RunLoop().RunUntilIdle(); |
970 EXPECT_EQ(kQuotaStatusOk, status()); | 972 EXPECT_EQ(kQuotaStatusOk, status()); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1797 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
1796 QuotaClient::kFileSystem); | 1798 QuotaClient::kFileSystem); |
1797 RegisterClient(client); | 1799 RegisterClient(client); |
1798 | 1800 |
1799 // TODO(kinuko): Be careful when we add cache pruner. | 1801 // TODO(kinuko): Be careful when we add cache pruner. |
1800 | 1802 |
1801 std::set<GURL> origins; | 1803 std::set<GURL> origins; |
1802 GetCachedOrigins(kTemp, &origins); | 1804 GetCachedOrigins(kTemp, &origins); |
1803 EXPECT_TRUE(origins.empty()); | 1805 EXPECT_TRUE(origins.empty()); |
1804 | 1806 |
1805 // No matter how we make queries the quota manager tries to cache all | |
1806 // the origins at startup. | |
1807 GetHostUsage("a.com", kTemp); | 1807 GetHostUsage("a.com", kTemp); |
1808 base::RunLoop().RunUntilIdle(); | 1808 base::RunLoop().RunUntilIdle(); |
1809 GetCachedOrigins(kTemp, &origins); | 1809 GetCachedOrigins(kTemp, &origins); |
1810 EXPECT_EQ(3U, origins.size()); | 1810 EXPECT_EQ(2U, origins.size()); |
1811 | 1811 |
1812 GetHostUsage("b.com", kTemp); | 1812 GetHostUsage("b.com", kTemp); |
1813 base::RunLoop().RunUntilIdle(); | 1813 base::RunLoop().RunUntilIdle(); |
1814 GetCachedOrigins(kTemp, &origins); | 1814 GetCachedOrigins(kTemp, &origins); |
| 1815 EXPECT_EQ(2U, origins.size()); |
| 1816 |
| 1817 GetHostUsage("c.com", kTemp); |
| 1818 base::RunLoop().RunUntilIdle(); |
| 1819 GetCachedOrigins(kTemp, &origins); |
1815 EXPECT_EQ(3U, origins.size()); | 1820 EXPECT_EQ(3U, origins.size()); |
1816 | 1821 |
1817 GetCachedOrigins(kPerm, &origins); | 1822 GetCachedOrigins(kPerm, &origins); |
1818 EXPECT_TRUE(origins.empty()); | 1823 EXPECT_TRUE(origins.empty()); |
1819 | 1824 |
1820 GetGlobalUsage(kTemp); | 1825 GetGlobalUsage(kTemp); |
1821 base::RunLoop().RunUntilIdle(); | 1826 base::RunLoop().RunUntilIdle(); |
1822 GetCachedOrigins(kTemp, &origins); | 1827 GetCachedOrigins(kTemp, &origins); |
1823 EXPECT_EQ(3U, origins.size()); | 1828 EXPECT_EQ(3U, origins.size()); |
1824 | 1829 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 RegisterClient(CreateClient(kData, arraysize(kData), | 2273 RegisterClient(CreateClient(kData, arraysize(kData), |
2269 QuotaClient::kFileSystem)); | 2274 QuotaClient::kFileSystem)); |
2270 | 2275 |
2271 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 2276 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
2272 base::RunLoop().RunUntilIdle(); | 2277 base::RunLoop().RunUntilIdle(); |
2273 EXPECT_EQ(kQuotaStatusOk, status()); | 2278 EXPECT_EQ(kQuotaStatusOk, status()); |
2274 EXPECT_EQ(80, usage()); | 2279 EXPECT_EQ(80, usage()); |
2275 EXPECT_EQ(0, quota()); | 2280 EXPECT_EQ(0, quota()); |
2276 | 2281 |
2277 SetTemporaryGlobalQuota(100); | 2282 SetTemporaryGlobalQuota(100); |
| 2283 base::RunLoop().RunUntilIdle(); |
| 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(std::min(static_cast<int64_t>(100 / kPerHostTemporaryPortion), |
2283 QuotaManager::kIncognitoDefaultQuotaLimit), | 2290 QuotaManager::kIncognitoDefaultQuotaLimit), |
2284 quota()); | 2291 quota()); |
2285 | 2292 |
2286 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); | 2293 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); |
2287 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 2294 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
(...skipping 14 matching lines...) Expand all Loading... |
2302 base::FilePath tmp_dir; | 2309 base::FilePath tmp_dir; |
2303 ASSERT_TRUE(base::GetTempDir(&tmp_dir)); | 2310 ASSERT_TRUE(base::GetTempDir(&tmp_dir)); |
2304 uint64_t available_space = 0; | 2311 uint64_t available_space = 0; |
2305 uint64_t total_size = 0; | 2312 uint64_t total_size = 0; |
2306 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size)); | 2313 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size)); |
2307 EXPECT_GT(available_space, 0u) << tmp_dir.value(); | 2314 EXPECT_GT(available_space, 0u) << tmp_dir.value(); |
2308 EXPECT_GT(total_size, 0u) << tmp_dir.value(); | 2315 EXPECT_GT(total_size, 0u) << tmp_dir.value(); |
2309 } | 2316 } |
2310 | 2317 |
2311 } // namespace content | 2318 } // namespace content |
OLD | NEW |