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

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

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <set> 9 #include <set>
10 #include <sstream> 10 #include <sstream>
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 static const MockOriginData kData[] = { 837 static const MockOriginData kData[] = {
838 { "http://usage1/", kTemp, 1 }, 838 { "http://usage1/", kTemp, 1 },
839 { "http://usage10/", kTemp, 10 }, 839 { "http://usage10/", kTemp, 10 },
840 { "http://usage200/", kTemp, 200 }, 840 { "http://usage200/", kTemp, 200 },
841 }; 841 };
842 RegisterClient(CreateClient(kData, arraysize(kData), 842 RegisterClient(CreateClient(kData, arraysize(kData),
843 QuotaClient::kFileSystem)); 843 QuotaClient::kFileSystem));
844 SetTemporaryGlobalQuota(100); 844 SetTemporaryGlobalQuota(100);
845 base::RunLoop().RunUntilIdle(); 845 base::RunLoop().RunUntilIdle();
846 846
847 // not sure this test is relevant anymore?
michaeln 2016/04/07 20:54:47 tests aren't ready yet, all i've done thusfar is m
848
847 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; 849 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion;
848 850
849 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp); 851 GetUsageAndQuotaForWebApps(GURL("http://usage1/"), kTemp);
850 base::RunLoop().RunUntilIdle(); 852 base::RunLoop().RunUntilIdle();
851 EXPECT_EQ(kQuotaStatusOk, status()); 853 EXPECT_EQ(kQuotaStatusOk, status());
852 EXPECT_EQ(1, usage()); 854 EXPECT_EQ(1, usage());
853 EXPECT_EQ(1, quota()); // should be clamped to our current usage 855 EXPECT_EQ(kPerHostQuota, quota());
854 856
855 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); 857 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
856 base::RunLoop().RunUntilIdle(); 858 base::RunLoop().RunUntilIdle();
857 EXPECT_EQ(kQuotaStatusOk, status()); 859 EXPECT_EQ(kQuotaStatusOk, status());
858 EXPECT_EQ(10, usage()); 860 EXPECT_EQ(10, usage());
859 EXPECT_EQ(10, quota()); 861 EXPECT_EQ(kPerHostQuota, quota());
860 862
861 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp); 863 GetUsageAndQuotaForWebApps(GURL("http://usage200/"), kTemp);
862 base::RunLoop().RunUntilIdle(); 864 base::RunLoop().RunUntilIdle();
863 EXPECT_EQ(kQuotaStatusOk, status()); 865 EXPECT_EQ(kQuotaStatusOk, status());
864 EXPECT_EQ(200, usage()); 866 EXPECT_EQ(200, usage());
865 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota 867 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota
866 } 868 }
867 869
868 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { 870 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
869 static const MockOriginData kData[] = { 871 static const MockOriginData kData[] = {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 951
950 GetGlobalUsage(kTemp); 952 GetGlobalUsage(kTemp);
951 base::RunLoop().RunUntilIdle(); 953 base::RunLoop().RunUntilIdle();
952 EXPECT_EQ(10 + 50 + 4000, usage()); 954 EXPECT_EQ(10 + 50 + 4000, usage());
953 EXPECT_EQ(0, unlimited_usage()); 955 EXPECT_EQ(0, unlimited_usage());
954 956
955 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp); 957 GetUsageAndQuotaForWebApps(GURL("http://usage10/"), kTemp);
956 base::RunLoop().RunUntilIdle(); 958 base::RunLoop().RunUntilIdle();
957 EXPECT_EQ(kQuotaStatusOk, status()); 959 EXPECT_EQ(kQuotaStatusOk, status());
958 EXPECT_EQ(10, usage()); 960 EXPECT_EQ(10, usage());
959 EXPECT_EQ(10, quota()); // should be clamped to our current usage 961 EXPECT_EQ(kPerHostQuotaFor100, quota());
960 962
961 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp); 963 GetUsageAndQuotaForWebApps(GURL("http://usage50/"), kTemp);
962 base::RunLoop().RunUntilIdle(); 964 base::RunLoop().RunUntilIdle();
963 EXPECT_EQ(kQuotaStatusOk, status()); 965 EXPECT_EQ(kQuotaStatusOk, status());
964 EXPECT_EQ(50, usage()); 966 EXPECT_EQ(50, usage());
965 EXPECT_EQ(kPerHostQuotaFor100, quota()); 967 EXPECT_EQ(kPerHostQuotaFor100, quota());
966 968
967 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp); 969 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kTemp);
968 base::RunLoop().RunUntilIdle(); 970 base::RunLoop().RunUntilIdle();
969 EXPECT_EQ(kQuotaStatusOk, status()); 971 EXPECT_EQ(kQuotaStatusOk, status());
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 MockStorageClient* client = CreateClient(kData, arraysize(kData), 1796 MockStorageClient* client = CreateClient(kData, arraysize(kData),
1795 QuotaClient::kFileSystem); 1797 QuotaClient::kFileSystem);
1796 RegisterClient(client); 1798 RegisterClient(client);
1797 1799
1798 // TODO(kinuko): Be careful when we add cache pruner. 1800 // TODO(kinuko): Be careful when we add cache pruner.
1799 1801
1800 std::set<GURL> origins; 1802 std::set<GURL> origins;
1801 GetCachedOrigins(kTemp, &origins); 1803 GetCachedOrigins(kTemp, &origins);
1802 EXPECT_TRUE(origins.empty()); 1804 EXPECT_TRUE(origins.empty());
1803 1805
1804 // No matter how we make queries the quota manager tries to cache all
1805 // the origins at startup.
1806 GetHostUsage("a.com", kTemp); 1806 GetHostUsage("a.com", kTemp);
1807 base::RunLoop().RunUntilIdle(); 1807 base::RunLoop().RunUntilIdle();
1808 GetCachedOrigins(kTemp, &origins); 1808 GetCachedOrigins(kTemp, &origins);
1809 EXPECT_EQ(3U, origins.size()); 1809 EXPECT_EQ(2U, origins.size());
1810 1810
1811 GetHostUsage("b.com", kTemp); 1811 GetHostUsage("b.com", kTemp);
1812 base::RunLoop().RunUntilIdle(); 1812 base::RunLoop().RunUntilIdle();
1813 GetCachedOrigins(kTemp, &origins); 1813 GetCachedOrigins(kTemp, &origins);
1814 EXPECT_EQ(2U, origins.size());
1815
1816 GetHostUsage("c.com", kTemp);
1817 base::RunLoop().RunUntilIdle();
1818 GetCachedOrigins(kTemp, &origins);
1814 EXPECT_EQ(3U, origins.size()); 1819 EXPECT_EQ(3U, origins.size());
1815 1820
1816 GetCachedOrigins(kPerm, &origins); 1821 GetCachedOrigins(kPerm, &origins);
1817 EXPECT_TRUE(origins.empty()); 1822 EXPECT_TRUE(origins.empty());
1818 1823
1819 GetGlobalUsage(kTemp); 1824 GetGlobalUsage(kTemp);
1820 base::RunLoop().RunUntilIdle(); 1825 base::RunLoop().RunUntilIdle();
1821 GetCachedOrigins(kTemp, &origins); 1826 GetCachedOrigins(kTemp, &origins);
1822 EXPECT_EQ(3U, origins.size()); 1827 EXPECT_EQ(3U, origins.size());
1823 1828
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 RegisterClient(CreateClient(kData, arraysize(kData), 2272 RegisterClient(CreateClient(kData, arraysize(kData),
2268 QuotaClient::kFileSystem)); 2273 QuotaClient::kFileSystem));
2269 2274
2270 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); 2275 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
2271 base::RunLoop().RunUntilIdle(); 2276 base::RunLoop().RunUntilIdle();
2272 EXPECT_EQ(kQuotaStatusOk, status()); 2277 EXPECT_EQ(kQuotaStatusOk, status());
2273 EXPECT_EQ(80, usage()); 2278 EXPECT_EQ(80, usage());
2274 EXPECT_EQ(0, quota()); 2279 EXPECT_EQ(0, quota());
2275 2280
2276 SetTemporaryGlobalQuota(100); 2281 SetTemporaryGlobalQuota(100);
2282 base::RunLoop().RunUntilIdle();
2283
2277 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 2284 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2278 base::RunLoop().RunUntilIdle(); 2285 base::RunLoop().RunUntilIdle();
2279 EXPECT_EQ(kQuotaStatusOk, status()); 2286 EXPECT_EQ(kQuotaStatusOk, status());
2280 EXPECT_EQ(10, usage()); 2287 EXPECT_EQ(10, usage());
2281 EXPECT_LE(std::min(static_cast<int64_t>(100 / kPerHostTemporaryPortion), 2288 EXPECT_LE(std::min(static_cast<int64_t>(100 / kPerHostTemporaryPortion),
2282 QuotaManager::kIncognitoDefaultQuotaLimit), 2289 QuotaManager::kIncognitoDefaultQuotaLimit),
2283 quota()); 2290 quota());
2284 2291
2285 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/")); 2292 mock_special_storage_policy()->AddUnlimited(GURL("http://foo.com/"));
2286 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); 2293 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm);
(...skipping 14 matching lines...) Expand all
2301 base::FilePath tmp_dir; 2308 base::FilePath tmp_dir;
2302 ASSERT_TRUE(base::GetTempDir(&tmp_dir)); 2309 ASSERT_TRUE(base::GetTempDir(&tmp_dir));
2303 uint64_t available_space = 0; 2310 uint64_t available_space = 0;
2304 uint64_t total_size = 0; 2311 uint64_t total_size = 0;
2305 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size)); 2312 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size));
2306 EXPECT_GT(available_space, 0u) << tmp_dir.value(); 2313 EXPECT_GT(available_space, 0u) << tmp_dir.value();
2307 EXPECT_GT(total_size, 0u) << tmp_dir.value(); 2314 EXPECT_GT(total_size, 0u) << tmp_dir.value();
2308 } 2315 }
2309 2316
2310 } // namespace content 2317 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | storage/browser/quota/quota_manager.h » ('j') | storage/browser/quota/quota_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698