Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage_manager_unittest.cc |
| diff --git a/content/browser/cache_storage/cache_storage_manager_unittest.cc b/content/browser/cache_storage/cache_storage_manager_unittest.cc |
| index fd6ffccb68deef4b88d5ad67d8167ba8040758b0..81f9d6e5d8dec3c92c16cd55e49fe03163f68af0 100644 |
| --- a/content/browser/cache_storage/cache_storage_manager_unittest.cc |
| +++ b/content/browser/cache_storage/cache_storage_manager_unittest.cc |
| @@ -14,6 +14,7 @@ |
| #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| #include "content/browser/quota/mock_quota_manager_proxy.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/cache_storage_usage_info.h" |
| #include "content/public/test/test_browser_context.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "net/url_request/url_request_context_getter.h" |
| @@ -224,6 +225,37 @@ class CacheStorageManagerTest : public testing::Test { |
| return cache_manager_->FindOrCreateCacheStorage(origin); |
| } |
| + int64 GetOriginUsage(const GURL& origin) { |
| + scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
|
Bernhard Bauer
2015/08/20 11:18:53
Just allocate the RunLoop directly on the stack.
jsbell
2015/08/20 19:04:51
Done. (Here and elsewhere.)
|
| + cache_manager_->GetOriginUsage( |
| + origin, |
| + base::Bind(&CacheStorageManagerTest::UsageCallback, |
| + base::Unretained(this), base::Unretained(loop.get()))); |
| + loop->Run(); |
| + return callback_usage_; |
| + } |
| + |
| + void UsageCallback(base::RunLoop* run_loop, int64 usage) { |
| + callback_usage_ = usage; |
| + run_loop->Quit(); |
| + } |
| + |
| + std::vector<CacheStorageUsageInfo> GetAllOriginsUsage() { |
| + scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
| + cache_manager_->GetAllOriginsUsage( |
| + base::Bind(&CacheStorageManagerTest::AllOriginsUsageCallback, |
| + base::Unretained(this), base::Unretained(loop.get()))); |
| + loop->Run(); |
| + return callback_all_origins_usage_; |
| + } |
| + |
| + void AllOriginsUsageCallback( |
| + base::RunLoop* run_loop, |
| + const std::vector<CacheStorageUsageInfo>& usage) { |
| + callback_all_origins_usage_ = usage; |
| + run_loop->Quit(); |
| + } |
| + |
| protected: |
| TestBrowserContext browser_context_; |
| TestBrowserThreadBundle browser_thread_bundle_; |
| @@ -241,16 +273,21 @@ class CacheStorageManagerTest : public testing::Test { |
| const GURL origin1_; |
| const GURL origin2_; |
| + int64 callback_usage_; |
| + std::vector<CacheStorageUsageInfo> callback_all_origins_usage_; |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(CacheStorageManagerTest); |
| }; |
| class CacheStorageManagerMemoryOnlyTest : public CacheStorageManagerTest { |
| + public: |
| bool MemoryOnly() override { return true; } |
| }; |
| class CacheStorageManagerTestP : public CacheStorageManagerTest, |
| public testing::WithParamInterface<bool> { |
| + public: |
| bool MemoryOnly() override { return !GetParam(); } |
| }; |
| @@ -512,6 +549,29 @@ TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { |
| EXPECT_TRUE(callback_cache_); |
| } |
| +TEST_P(CacheStorageManagerTestP, GetOriginUsage) { |
| + EXPECT_EQ(0, GetOriginUsage(origin1_)); |
| + EXPECT_TRUE(Open(origin1_, "foo")); |
| + EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); |
| + EXPECT_LT(0, GetOriginUsage(origin1_)); |
| + EXPECT_EQ(0, GetOriginUsage(origin2_)); |
| +} |
| + |
| +TEST_P(CacheStorageManagerTestP, GetAllOriginsUsage) { |
| + EXPECT_EQ(0ULL, GetAllOriginsUsage().size()); |
| + EXPECT_TRUE(Open(origin1_, "foo")); |
| + EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); |
| + std::vector<CacheStorageUsageInfo> usage = GetAllOriginsUsage(); |
| + EXPECT_EQ(1ULL, usage.size()); |
| + const CacheStorageUsageInfo& info = usage[0]; |
| + EXPECT_EQ(origin1_, info.origin); |
| + EXPECT_LT(0, info.total_size_bytes); |
| + if (MemoryOnly()) |
| + EXPECT_TRUE(info.last_modified.is_null()); |
| + else |
| + EXPECT_FALSE(info.last_modified.is_null()); |
| +} |
| + |
| TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryBackedSize) { |
| CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); |
| EXPECT_EQ(0, cache_storage->MemoryBackedSize()); |
| @@ -568,29 +628,12 @@ class CacheStorageMigrationTest : public CacheStorageManagerTest { |
| ASSERT_FALSE(base::DirectoryExists(new_path_)); |
| } |
| - int64 GetOriginUsage(const GURL& origin) { |
| - scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
| - cache_manager_->GetOriginUsage( |
| - origin, |
| - base::Bind(&CacheStorageMigrationTest::UsageCallback, |
| - base::Unretained(this), base::Unretained(loop.get()))); |
| - loop->Run(); |
| - return callback_usage_; |
| - } |
| - |
| - void UsageCallback(base::RunLoop* run_loop, int64 usage) { |
| - callback_usage_ = usage; |
| - run_loop->Quit(); |
| - } |
| - |
| base::FilePath legacy_path_; |
| base::FilePath new_path_; |
| const std::string cache1_; |
| const std::string cache2_; |
| - int64 callback_usage_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(CacheStorageMigrationTest); |
| }; |
| @@ -655,8 +698,8 @@ class CacheStorageQuotaClientTest : public CacheStorageManagerTest { |
| new CacheStorageQuotaClient(cache_manager_->AsWeakPtr())); |
| } |
| - void UsageCallback(base::RunLoop* run_loop, int64 usage) { |
| - callback_usage_ = usage; |
| + void QuotaUsageCallback(base::RunLoop* run_loop, int64 usage) { |
| + callback_quota_usage_ = usage; |
| run_loop->Quit(); |
| } |
| @@ -675,10 +718,10 @@ class CacheStorageQuotaClientTest : public CacheStorageManagerTest { |
| scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
| quota_client_->GetOriginUsage( |
| origin, storage::kStorageTypeTemporary, |
| - base::Bind(&CacheStorageQuotaClientTest::UsageCallback, |
| + base::Bind(&CacheStorageQuotaClientTest::QuotaUsageCallback, |
| base::Unretained(this), base::Unretained(loop.get()))); |
| loop->Run(); |
| - return callback_usage_; |
| + return callback_quota_usage_; |
| } |
| size_t QuotaGetOriginsForType() { |
| @@ -718,7 +761,7 @@ class CacheStorageQuotaClientTest : public CacheStorageManagerTest { |
| scoped_ptr<CacheStorageQuotaClient> quota_client_; |
| storage::QuotaStatusCode callback_status_; |
| - int64 callback_usage_; |
| + int64 callback_quota_usage_ = 0; |
| std::set<GURL> callback_origins_; |
| DISALLOW_COPY_AND_ASSIGN(CacheStorageQuotaClientTest); |