| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion; | 66 const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion; |
| 67 | 67 |
| 68 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); | 68 const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); |
| 69 | 69 |
| 70 // Returns a deterministic value for the amount of available disk space. | 70 // Returns a deterministic value for the amount of available disk space. |
| 71 int64_t GetAvailableDiskSpaceForTest() { | 71 int64_t GetAvailableDiskSpaceForTest() { |
| 72 return kAvailableSpaceForApp + kMinimumPreserveForSystem; | 72 return kAvailableSpaceForApp + kMinimumPreserveForSystem; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool GetVolumeInfoForTests(const base::FilePath&, | 75 bool GetVolumeInfoForTests(const base::FilePath&, |
| 76 uint64_t* available, uint64_t* total) { | 76 int64_t* available, int64_t* total) { |
| 77 *available = static_cast<uint64_t>(GetAvailableDiskSpaceForTest()); | 77 *available = GetAvailableDiskSpaceForTest(); |
| 78 *total = *available * 2; | 78 *total = *available * 2; |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 class TestEvictionPolicy : public storage::QuotaEvictionPolicy { | 82 class TestEvictionPolicy : public storage::QuotaEvictionPolicy { |
| 83 public: | 83 public: |
| 84 TestEvictionPolicy() {} | 84 TestEvictionPolicy() {} |
| 85 ~TestEvictionPolicy() override {} | 85 ~TestEvictionPolicy() override {} |
| 86 | 86 |
| 87 // Overridden from storage::QuotaEvictionPolicy: | 87 // Overridden from storage::QuotaEvictionPolicy: |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction, | 290 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction, |
| 291 weak_factory_.GetWeakPtr())); | 291 weak_factory_.GetWeakPtr())); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { | 294 void GetCachedOrigins(StorageType type, std::set<GURL>* origins) { |
| 295 ASSERT_TRUE(origins != NULL); | 295 ASSERT_TRUE(origins != NULL); |
| 296 origins->clear(); | 296 origins->clear(); |
| 297 quota_manager_->GetCachedOrigins(type, origins); | 297 quota_manager_->GetCachedOrigins(type, origins); |
| 298 } | 298 } |
| 299 | 299 |
| 300 bool GetVolumeInfo(const base::FilePath& path, | |
| 301 uint64_t* available_space, | |
| 302 uint64_t* total_size) { | |
| 303 return QuotaManager::GetVolumeInfo(path, available_space, total_size); | |
| 304 } | |
| 305 | |
| 306 void NotifyStorageAccessed(QuotaClient* client, | 300 void NotifyStorageAccessed(QuotaClient* client, |
| 307 const GURL& origin, | 301 const GURL& origin, |
| 308 StorageType type) { | 302 StorageType type) { |
| 309 DCHECK(client); | 303 DCHECK(client); |
| 310 quota_manager_->NotifyStorageAccessedInternal( | 304 quota_manager_->NotifyStorageAccessedInternal( |
| 311 client->id(), origin, type, IncrementMockTime()); | 305 client->id(), origin, type, IncrementMockTime()); |
| 312 } | 306 } |
| 313 | 307 |
| 314 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { | 308 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { |
| 315 quota_manager_->DeleteOriginFromDatabase(origin, type, false); | 309 quota_manager_->DeleteOriginFromDatabase(origin, type, false); |
| (...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2290 EXPECT_EQ(80, usage()); | 2284 EXPECT_EQ(80, usage()); |
| 2291 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2285 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2292 | 2286 |
| 2293 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2287 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
| 2294 base::RunLoop().RunUntilIdle(); | 2288 base::RunLoop().RunUntilIdle(); |
| 2295 EXPECT_EQ(kQuotaStatusOk, status()); | 2289 EXPECT_EQ(kQuotaStatusOk, status()); |
| 2296 EXPECT_EQ(10, usage()); | 2290 EXPECT_EQ(10, usage()); |
| 2297 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2291 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2298 } | 2292 } |
| 2299 | 2293 |
| 2300 TEST_F(QuotaManagerTest, GetVolumeInfo) { | |
| 2301 // We aren't actually testing that it's correct, just that it's sane. | |
| 2302 base::FilePath tmp_dir; | |
| 2303 ASSERT_TRUE(base::GetTempDir(&tmp_dir)); | |
| 2304 uint64_t available_space = 0; | |
| 2305 uint64_t total_size = 0; | |
| 2306 EXPECT_TRUE(GetVolumeInfo(tmp_dir, &available_space, &total_size)); | |
| 2307 EXPECT_GT(available_space, 0u) << tmp_dir.value(); | |
| 2308 EXPECT_GT(total_size, 0u) << tmp_dir.value(); | |
| 2309 } | |
| 2310 | |
| 2311 } // namespace content | 2294 } // namespace content |
| OLD | NEW |