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

Side by Side Diff: content/browser/cache_storage/cache_storage_manager_unittest.cc

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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 "content/browser/cache_storage/cache_storage_manager.h" 5 #include "content/browser/cache_storage/cache_storage_manager.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
10 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/macros.h"
11 #include "base/run_loop.h" 15 #include "base/run_loop.h"
12 #include "base/sha1.h" 16 #include "base/sha1.h"
13 #include "base/stl_util.h" 17 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
15 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
16 #include "content/browser/cache_storage/cache_storage.pb.h" 20 #include "content/browser/cache_storage/cache_storage.pb.h"
17 #include "content/browser/cache_storage/cache_storage_quota_client.h" 21 #include "content/browser/cache_storage/cache_storage_quota_client.h"
18 #include "content/browser/fileapi/chrome_blob_storage_context.h" 22 #include "content/browser/fileapi/chrome_blob_storage_context.h"
19 #include "content/browser/quota/mock_quota_manager_proxy.h" 23 #include "content/browser/quota/mock_quota_manager_proxy.h"
20 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 base::Unretained(this), base::Unretained(&loop))); 260 base::Unretained(this), base::Unretained(&loop)));
257 loop.Run(); 261 loop.Run();
258 262
259 return callback_error_ == CACHE_STORAGE_OK; 263 return callback_error_ == CACHE_STORAGE_OK;
260 } 264 }
261 265
262 CacheStorage* CacheStorageForOrigin(const GURL& origin) { 266 CacheStorage* CacheStorageForOrigin(const GURL& origin) {
263 return cache_manager_->FindOrCreateCacheStorage(origin); 267 return cache_manager_->FindOrCreateCacheStorage(origin);
264 } 268 }
265 269
266 int64 GetOriginUsage(const GURL& origin) { 270 int64_t GetOriginUsage(const GURL& origin) {
267 base::RunLoop loop; 271 base::RunLoop loop;
268 cache_manager_->GetOriginUsage( 272 cache_manager_->GetOriginUsage(
269 origin, base::Bind(&CacheStorageManagerTest::UsageCallback, 273 origin, base::Bind(&CacheStorageManagerTest::UsageCallback,
270 base::Unretained(this), base::Unretained(&loop))); 274 base::Unretained(this), base::Unretained(&loop)));
271 loop.Run(); 275 loop.Run();
272 return callback_usage_; 276 return callback_usage_;
273 } 277 }
274 278
275 void UsageCallback(base::RunLoop* run_loop, int64 usage) { 279 void UsageCallback(base::RunLoop* run_loop, int64_t usage) {
276 callback_usage_ = usage; 280 callback_usage_ = usage;
277 run_loop->Quit(); 281 run_loop->Quit();
278 } 282 }
279 283
280 std::vector<CacheStorageUsageInfo> GetAllOriginsUsage() { 284 std::vector<CacheStorageUsageInfo> GetAllOriginsUsage() {
281 base::RunLoop loop; 285 base::RunLoop loop;
282 cache_manager_->GetAllOriginsUsage( 286 cache_manager_->GetAllOriginsUsage(
283 base::Bind(&CacheStorageManagerTest::AllOriginsUsageCallback, 287 base::Bind(&CacheStorageManagerTest::AllOriginsUsageCallback,
284 base::Unretained(this), base::Unretained(&loop))); 288 base::Unretained(this), base::Unretained(&loop)));
285 loop.Run(); 289 loop.Run();
(...skipping 22 matching lines...) Expand all
308 scoped_refptr<CacheStorageCache> callback_cache_; 312 scoped_refptr<CacheStorageCache> callback_cache_;
309 int callback_bool_; 313 int callback_bool_;
310 CacheStorageError callback_error_; 314 CacheStorageError callback_error_;
311 scoped_ptr<ServiceWorkerResponse> callback_cache_response_; 315 scoped_ptr<ServiceWorkerResponse> callback_cache_response_;
312 scoped_ptr<storage::BlobDataHandle> callback_data_handle_; 316 scoped_ptr<storage::BlobDataHandle> callback_data_handle_;
313 std::vector<std::string> callback_strings_; 317 std::vector<std::string> callback_strings_;
314 318
315 const GURL origin1_; 319 const GURL origin1_;
316 const GURL origin2_; 320 const GURL origin2_;
317 321
318 int64 callback_usage_; 322 int64_t callback_usage_;
319 std::vector<CacheStorageUsageInfo> callback_all_origins_usage_; 323 std::vector<CacheStorageUsageInfo> callback_all_origins_usage_;
320 324
321 private: 325 private:
322 DISALLOW_COPY_AND_ASSIGN(CacheStorageManagerTest); 326 DISALLOW_COPY_AND_ASSIGN(CacheStorageManagerTest);
323 }; 327 };
324 328
325 class CacheStorageManagerMemoryOnlyTest : public CacheStorageManagerTest { 329 class CacheStorageManagerMemoryOnlyTest : public CacheStorageManagerTest {
326 public: 330 public:
327 bool MemoryOnly() override { return true; } 331 bool MemoryOnly() override { return true; }
328 }; 332 };
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 619 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
616 620
617 EXPECT_TRUE(Open(origin1_, "foo")); 621 EXPECT_TRUE(Open(origin1_, "foo"));
618 scoped_refptr<CacheStorageCache> foo_cache = callback_cache_; 622 scoped_refptr<CacheStorageCache> foo_cache = callback_cache_;
619 EXPECT_TRUE(Open(origin1_, "bar")); 623 EXPECT_TRUE(Open(origin1_, "bar"));
620 scoped_refptr<CacheStorageCache> bar_cache = callback_cache_; 624 scoped_refptr<CacheStorageCache> bar_cache = callback_cache_;
621 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 625 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
622 626
623 EXPECT_TRUE(CachePut(foo_cache, GURL("http://example.com/foo"))); 627 EXPECT_TRUE(CachePut(foo_cache, GURL("http://example.com/foo")));
624 EXPECT_LT(0, cache_storage->MemoryBackedSize()); 628 EXPECT_LT(0, cache_storage->MemoryBackedSize());
625 int64 foo_size = cache_storage->MemoryBackedSize(); 629 int64_t foo_size = cache_storage->MemoryBackedSize();
626 630
627 EXPECT_TRUE(CachePut(bar_cache, GURL("http://example.com/foo"))); 631 EXPECT_TRUE(CachePut(bar_cache, GURL("http://example.com/foo")));
628 EXPECT_EQ(foo_size * 2, cache_storage->MemoryBackedSize()); 632 EXPECT_EQ(foo_size * 2, cache_storage->MemoryBackedSize());
629 } 633 }
630 634
631 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) { 635 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) {
632 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); 636 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_);
633 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 637 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
634 EXPECT_TRUE(Open(origin1_, "foo")); 638 EXPECT_TRUE(Open(origin1_, "foo"));
635 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 639 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 class CacheStorageQuotaClientTest : public CacheStorageManagerTest { 852 class CacheStorageQuotaClientTest : public CacheStorageManagerTest {
849 protected: 853 protected:
850 CacheStorageQuotaClientTest() {} 854 CacheStorageQuotaClientTest() {}
851 855
852 void SetUp() override { 856 void SetUp() override {
853 CacheStorageManagerTest::SetUp(); 857 CacheStorageManagerTest::SetUp();
854 quota_client_.reset( 858 quota_client_.reset(
855 new CacheStorageQuotaClient(cache_manager_->AsWeakPtr())); 859 new CacheStorageQuotaClient(cache_manager_->AsWeakPtr()));
856 } 860 }
857 861
858 void QuotaUsageCallback(base::RunLoop* run_loop, int64 usage) { 862 void QuotaUsageCallback(base::RunLoop* run_loop, int64_t usage) {
859 callback_quota_usage_ = usage; 863 callback_quota_usage_ = usage;
860 run_loop->Quit(); 864 run_loop->Quit();
861 } 865 }
862 866
863 void OriginsCallback(base::RunLoop* run_loop, const std::set<GURL>& origins) { 867 void OriginsCallback(base::RunLoop* run_loop, const std::set<GURL>& origins) {
864 callback_origins_ = origins; 868 callback_origins_ = origins;
865 run_loop->Quit(); 869 run_loop->Quit();
866 } 870 }
867 871
868 void DeleteOriginCallback(base::RunLoop* run_loop, 872 void DeleteOriginCallback(base::RunLoop* run_loop,
869 storage::QuotaStatusCode status) { 873 storage::QuotaStatusCode status) {
870 callback_status_ = status; 874 callback_status_ = status;
871 run_loop->Quit(); 875 run_loop->Quit();
872 } 876 }
873 877
874 int64 QuotaGetOriginUsage(const GURL& origin) { 878 int64_t QuotaGetOriginUsage(const GURL& origin) {
875 base::RunLoop loop; 879 base::RunLoop loop;
876 quota_client_->GetOriginUsage( 880 quota_client_->GetOriginUsage(
877 origin, storage::kStorageTypeTemporary, 881 origin, storage::kStorageTypeTemporary,
878 base::Bind(&CacheStorageQuotaClientTest::QuotaUsageCallback, 882 base::Bind(&CacheStorageQuotaClientTest::QuotaUsageCallback,
879 base::Unretained(this), base::Unretained(&loop))); 883 base::Unretained(this), base::Unretained(&loop)));
880 loop.Run(); 884 loop.Run();
881 return callback_quota_usage_; 885 return callback_quota_usage_;
882 } 886 }
883 887
884 size_t QuotaGetOriginsForType() { 888 size_t QuotaGetOriginsForType() {
(...skipping 26 matching lines...) Expand all
911 return callback_status_ == storage::kQuotaStatusOk; 915 return callback_status_ == storage::kQuotaStatusOk;
912 } 916 }
913 917
914 bool QuotaDoesSupport(storage::StorageType type) { 918 bool QuotaDoesSupport(storage::StorageType type) {
915 return quota_client_->DoesSupport(type); 919 return quota_client_->DoesSupport(type);
916 } 920 }
917 921
918 scoped_ptr<CacheStorageQuotaClient> quota_client_; 922 scoped_ptr<CacheStorageQuotaClient> quota_client_;
919 923
920 storage::QuotaStatusCode callback_status_; 924 storage::QuotaStatusCode callback_status_;
921 int64 callback_quota_usage_ = 0; 925 int64_t callback_quota_usage_ = 0;
922 std::set<GURL> callback_origins_; 926 std::set<GURL> callback_origins_;
923 927
924 DISALLOW_COPY_AND_ASSIGN(CacheStorageQuotaClientTest); 928 DISALLOW_COPY_AND_ASSIGN(CacheStorageQuotaClientTest);
925 }; 929 };
926 930
927 class CacheStorageQuotaClientTestP : public CacheStorageQuotaClientTest, 931 class CacheStorageQuotaClientTestP : public CacheStorageQuotaClientTest,
928 public testing::WithParamInterface<bool> { 932 public testing::WithParamInterface<bool> {
929 bool MemoryOnly() override { return !GetParam(); } 933 bool MemoryOnly() override { return !GetParam(); }
930 }; 934 };
931 935
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 994
991 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 995 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
992 CacheStorageManagerTestP, 996 CacheStorageManagerTestP,
993 ::testing::Values(false, true)); 997 ::testing::Values(false, true));
994 998
995 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 999 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
996 CacheStorageQuotaClientTestP, 1000 CacheStorageQuotaClientTestP,
997 ::testing::Values(false, true)); 1001 ::testing::Values(false, true));
998 1002
999 } // namespace content 1003 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_manager.cc ('k') | content/browser/cache_storage/cache_storage_quota_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698