| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 { "http://unlimited/", kPerm, 8 }, | 624 { "http://unlimited/", kPerm, 8 }, |
| 625 { "http://installed/", kPerm, 16 }, | 625 { "http://installed/", kPerm, 16 }, |
| 626 }; | 626 }; |
| 627 static const MockOriginData kData2[] = { | 627 static const MockOriginData kData2[] = { |
| 628 { "https://foo.com/", kTemp, 128 }, | 628 { "https://foo.com/", kTemp, 128 }, |
| 629 { "http://example.com/", kPerm, 256 }, | 629 { "http://example.com/", kPerm, 256 }, |
| 630 { "http://unlimited/", kTemp, 512 }, | 630 { "http://unlimited/", kTemp, 512 }, |
| 631 { "http://installed/", kTemp, 1024 }, | 631 { "http://installed/", kTemp, 1024 }, |
| 632 }; | 632 }; |
| 633 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 633 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
| 634 mock_special_storage_policy()->AddInstalledApp(GURL("http://installed/")); | 634 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
| 635 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 635 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
| 636 QuotaClient::kFileSystem)); | 636 QuotaClient::kFileSystem)); |
| 637 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 637 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
| 638 QuotaClient::kDatabase)); | 638 QuotaClient::kDatabase)); |
| 639 | 639 |
| 640 const int64 kTempQuotaBase = | 640 const int64 kTempQuotaBase = |
| 641 GetAvailableDiskSpaceForTest(base::FilePath()) / kPerHostTemporaryPortion; | 641 GetAvailableDiskSpaceForTest(base::FilePath()) / kPerHostTemporaryPortion; |
| 642 | 642 |
| 643 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 643 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
| 644 MessageLoop::current()->RunUntilIdle(); | 644 MessageLoop::current()->RunUntilIdle(); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 EXPECT_EQ(0, quota()); | 990 EXPECT_EQ(0, quota()); |
| 991 | 991 |
| 992 SetPersistentHostQuota("foo.com", 100); | 992 SetPersistentHostQuota("foo.com", 100); |
| 993 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); | 993 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kPerm); |
| 994 MessageLoop::current()->RunUntilIdle(); | 994 MessageLoop::current()->RunUntilIdle(); |
| 995 EXPECT_EQ(kQuotaStatusOk, status()); | 995 EXPECT_EQ(kQuotaStatusOk, status()); |
| 996 EXPECT_EQ(0, usage()); | 996 EXPECT_EQ(0, usage()); |
| 997 EXPECT_EQ(100, quota()); | 997 EXPECT_EQ(100, quota()); |
| 998 | 998 |
| 999 // For installed app GetUsageAndQuotaForWebApps returns the capped quota. | 999 // For installed app GetUsageAndQuotaForWebApps returns the capped quota. |
| 1000 mock_special_storage_policy()->AddInstalledApp(GURL("http://installed/")); | 1000 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
| 1001 SetPersistentHostQuota("installed", kAvailableSpaceForApp + 100); | 1001 SetPersistentHostQuota("installed", kAvailableSpaceForApp + 100); |
| 1002 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); | 1002 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kPerm); |
| 1003 MessageLoop::current()->RunUntilIdle(); | 1003 MessageLoop::current()->RunUntilIdle(); |
| 1004 EXPECT_EQ(kAvailableSpaceForApp, quota()); | 1004 EXPECT_EQ(kAvailableSpaceForApp, quota()); |
| 1005 | 1005 |
| 1006 // Ditto for unlimited apps. | 1006 // Ditto for unlimited apps. |
| 1007 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 1007 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
| 1008 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); | 1008 GetUsageAndQuotaForWebApps(GURL("http://unlimited/"), kPerm); |
| 1009 MessageLoop::current()->RunUntilIdle(); | 1009 MessageLoop::current()->RunUntilIdle(); |
| 1010 EXPECT_EQ(kAvailableSpaceForApp, quota()); | 1010 EXPECT_EQ(kAvailableSpaceForApp, quota()); |
| 1011 | 1011 |
| 1012 // GetUsageAndQuotaForStorageClient should just return 0 usage and | 1012 // GetUsageAndQuotaForStorageClient should just return 0 usage and |
| 1013 // kNoLimit quota. | 1013 // kNoLimit quota. |
| 1014 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kPerm); | 1014 GetUsageAndQuotaForStorageClient(GURL("http://unlimited/"), kPerm); |
| 1015 MessageLoop::current()->RunUntilIdle(); | 1015 MessageLoop::current()->RunUntilIdle(); |
| 1016 EXPECT_EQ(0, usage()); | 1016 EXPECT_EQ(0, usage()); |
| 1017 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 1017 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 TEST_F(QuotaManagerTest, GetSyncableQuota) { | 1020 TEST_F(QuotaManagerTest, GetSyncableQuota) { |
| 1021 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | 1021 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); |
| 1022 | 1022 |
| 1023 // Pre-condition check: available disk space (for testing) is less than | 1023 // Pre-condition check: available disk space (for testing) is less than |
| 1024 // the default quota for syncable storage. | 1024 // the default quota for syncable storage. |
| 1025 EXPECT_LE(kAvailableSpaceForApp, | 1025 EXPECT_LE(kAvailableSpaceForApp, |
| 1026 QuotaManager::kSyncableStorageDefaultHostQuota); | 1026 QuotaManager::kSyncableStorageDefaultHostQuota); |
| 1027 | 1027 |
| 1028 // For installed apps the quota manager should return | 1028 // For installed apps the quota manager should return |
| 1029 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). | 1029 // kAvailableSpaceForApp as syncable quota (because of the pre-condition). |
| 1030 mock_special_storage_policy()->AddInstalledApp(GURL("http://installed/")); | 1030 mock_special_storage_policy()->GrantQueryDiskSize(GURL("http://installed/")); |
| 1031 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kSync); | 1031 GetUsageAndQuotaForWebApps(GURL("http://installed/"), kSync); |
| 1032 MessageLoop::current()->RunUntilIdle(); | 1032 MessageLoop::current()->RunUntilIdle(); |
| 1033 EXPECT_EQ(kQuotaStatusOk, status()); | 1033 EXPECT_EQ(kQuotaStatusOk, status()); |
| 1034 EXPECT_EQ(0, usage()); | 1034 EXPECT_EQ(0, usage()); |
| 1035 EXPECT_EQ(kAvailableSpaceForApp, quota()); | 1035 EXPECT_EQ(kAvailableSpaceForApp, quota()); |
| 1036 | 1036 |
| 1037 // If it's not installed (which shouldn't happen in real case) it | 1037 // If it's not installed (which shouldn't happen in real case) it |
| 1038 // should just return the default host quota for syncable. | 1038 // should just return the default host quota for syncable. |
| 1039 GetUsageAndQuotaForWebApps(GURL("http://foo/"), kSync); | 1039 GetUsageAndQuotaForWebApps(GURL("http://foo/"), kSync); |
| 1040 MessageLoop::current()->RunUntilIdle(); | 1040 MessageLoop::current()->RunUntilIdle(); |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 | 2133 |
| 2134 DeleteHostData("foo.com", kTemp, | 2134 DeleteHostData("foo.com", kTemp, |
| 2135 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); | 2135 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); |
| 2136 MessageLoop::current()->RunUntilIdle(); | 2136 MessageLoop::current()->RunUntilIdle(); |
| 2137 GetHostUsage("foo.com", kTemp); | 2137 GetHostUsage("foo.com", kTemp); |
| 2138 MessageLoop::current()->RunUntilIdle(); | 2138 MessageLoop::current()->RunUntilIdle(); |
| 2139 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | 2139 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); |
| 2140 } | 2140 } |
| 2141 | 2141 |
| 2142 } // namespace quota | 2142 } // namespace quota |
| OLD | NEW |