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

Side by Side Diff: content/browser/cache_storage/cache_storage_cache_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_cache.h" 5 #include "content/browser/cache_storage/cache_storage_cache.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/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
11 #include "base/run_loop.h" 15 #include "base/run_loop.h"
12 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
13 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
14 #include "content/browser/fileapi/chrome_blob_storage_context.h" 18 #include "content/browser/fileapi/chrome_blob_storage_context.h"
15 #include "content/browser/fileapi/mock_url_request_delegate.h" 19 #include "content/browser/fileapi/mock_url_request_delegate.h"
16 #include "content/browser/quota/mock_quota_manager_proxy.h" 20 #include "content/browser/quota/mock_quota_manager_proxy.h"
17 #include "content/common/cache_storage/cache_storage_types.h" 21 #include "content/common/cache_storage/cache_storage_types.h"
18 #include "content/common/service_worker/service_worker_types.h" 22 #include "content/common/service_worker/service_worker_types.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // A disk_cache::Backend wrapper that can delay operations. 54 // A disk_cache::Backend wrapper that can delay operations.
51 class DelayableBackend : public disk_cache::Backend { 55 class DelayableBackend : public disk_cache::Backend {
52 public: 56 public:
53 DelayableBackend(scoped_ptr<disk_cache::Backend> backend) 57 DelayableBackend(scoped_ptr<disk_cache::Backend> backend)
54 : backend_(backend.Pass()), delay_open_(false) {} 58 : backend_(backend.Pass()), delay_open_(false) {}
55 59
56 // disk_cache::Backend overrides 60 // disk_cache::Backend overrides
57 net::CacheType GetCacheType() const override { 61 net::CacheType GetCacheType() const override {
58 return backend_->GetCacheType(); 62 return backend_->GetCacheType();
59 } 63 }
60 int32 GetEntryCount() const override { return backend_->GetEntryCount(); } 64 int32_t GetEntryCount() const override { return backend_->GetEntryCount(); }
61 int OpenEntry(const std::string& key, 65 int OpenEntry(const std::string& key,
62 disk_cache::Entry** entry, 66 disk_cache::Entry** entry,
63 const CompletionCallback& callback) override { 67 const CompletionCallback& callback) override {
64 if (delay_open_) { 68 if (delay_open_) {
65 open_entry_callback_ = 69 open_entry_callback_ =
66 base::Bind(&DelayableBackend::OpenEntryDelayedImpl, 70 base::Bind(&DelayableBackend::OpenEntryDelayedImpl,
67 base::Unretained(this), key, entry, callback); 71 base::Unretained(this), key, entry, callback);
68 return net::ERR_IO_PENDING; 72 return net::ERR_IO_PENDING;
69 } 73 }
70 74
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 scoped_ptr<storage::BlobDataSnapshot> data = blob_handle.CreateSnapshot(); 136 scoped_ptr<storage::BlobDataSnapshot> data = blob_handle.CreateSnapshot();
133 const auto& items = data->items(); 137 const auto& items = data->items();
134 for (const auto& item : items) { 138 for (const auto& item : items) {
135 switch (item->type()) { 139 switch (item->type()) {
136 case storage::DataElement::TYPE_BYTES: { 140 case storage::DataElement::TYPE_BYTES: {
137 output->append(item->bytes(), item->length()); 141 output->append(item->bytes(), item->length());
138 break; 142 break;
139 } 143 }
140 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { 144 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
141 disk_cache::Entry* entry = item->disk_cache_entry(); 145 disk_cache::Entry* entry = item->disk_cache_entry();
142 int32 body_size = entry->GetDataSize(item->disk_cache_stream_index()); 146 int32_t body_size = entry->GetDataSize(item->disk_cache_stream_index());
143 147
144 scoped_refptr<net::IOBuffer> io_buffer = new net::IOBuffer(body_size); 148 scoped_refptr<net::IOBuffer> io_buffer = new net::IOBuffer(body_size);
145 net::TestCompletionCallback callback; 149 net::TestCompletionCallback callback;
146 int rv = 150 int rv =
147 entry->ReadData(item->disk_cache_stream_index(), 0, io_buffer.get(), 151 entry->ReadData(item->disk_cache_stream_index(), 0, io_buffer.get(),
148 body_size, callback.callback()); 152 body_size, callback.callback());
149 if (rv == net::ERR_IO_PENDING) 153 if (rv == net::ERR_IO_PENDING)
150 rv = callback.WaitForResult(); 154 rv = callback.WaitForResult();
151 EXPECT_EQ(body_size, rv); 155 EXPECT_EQ(body_size, rv);
152 if (rv > 0) 156 if (rv > 0)
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 request.headers["Content-Type"] = "bar"; 909 request.headers["Content-Type"] = "bar";
906 EXPECT_EQ("bar", request.headers["content-type"]); 910 EXPECT_EQ("bar", request.headers["content-type"]);
907 } 911 }
908 912
909 TEST_P(CacheStorageCacheTestP, QuotaManagerModified) { 913 TEST_P(CacheStorageCacheTestP, QuotaManagerModified) {
910 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_modified_count()); 914 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_modified_count());
911 915
912 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 916 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
913 EXPECT_EQ(1, quota_manager_proxy_->notify_storage_modified_count()); 917 EXPECT_EQ(1, quota_manager_proxy_->notify_storage_modified_count());
914 EXPECT_LT(0, quota_manager_proxy_->last_notified_delta()); 918 EXPECT_LT(0, quota_manager_proxy_->last_notified_delta());
915 int64 sum_delta = quota_manager_proxy_->last_notified_delta(); 919 int64_t sum_delta = quota_manager_proxy_->last_notified_delta();
916 920
917 EXPECT_TRUE(Put(body_request_, body_response_)); 921 EXPECT_TRUE(Put(body_request_, body_response_));
918 EXPECT_EQ(2, quota_manager_proxy_->notify_storage_modified_count()); 922 EXPECT_EQ(2, quota_manager_proxy_->notify_storage_modified_count());
919 EXPECT_LT(sum_delta, quota_manager_proxy_->last_notified_delta()); 923 EXPECT_LT(sum_delta, quota_manager_proxy_->last_notified_delta());
920 sum_delta += quota_manager_proxy_->last_notified_delta(); 924 sum_delta += quota_manager_proxy_->last_notified_delta();
921 925
922 EXPECT_TRUE(Delete(body_request_)); 926 EXPECT_TRUE(Delete(body_request_));
923 EXPECT_EQ(3, quota_manager_proxy_->notify_storage_modified_count()); 927 EXPECT_EQ(3, quota_manager_proxy_->notify_storage_modified_count());
924 sum_delta += quota_manager_proxy_->last_notified_delta(); 928 sum_delta += quota_manager_proxy_->last_notified_delta();
925 929
926 EXPECT_TRUE(Delete(no_body_request_)); 930 EXPECT_TRUE(Delete(no_body_request_));
927 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); 931 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count());
928 sum_delta += quota_manager_proxy_->last_notified_delta(); 932 sum_delta += quota_manager_proxy_->last_notified_delta();
929 933
930 EXPECT_EQ(0, sum_delta); 934 EXPECT_EQ(0, sum_delta);
931 } 935 }
932 936
933 TEST_F(CacheStorageCacheMemoryOnlyTest, MemoryBackedSize) { 937 TEST_F(CacheStorageCacheMemoryOnlyTest, MemoryBackedSize) {
934 EXPECT_EQ(0, cache_->MemoryBackedSize()); 938 EXPECT_EQ(0, cache_->MemoryBackedSize());
935 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 939 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
936 EXPECT_LT(0, cache_->MemoryBackedSize()); 940 EXPECT_LT(0, cache_->MemoryBackedSize());
937 int64 no_body_size = cache_->MemoryBackedSize(); 941 int64_t no_body_size = cache_->MemoryBackedSize();
938 942
939 EXPECT_TRUE(Delete(no_body_request_)); 943 EXPECT_TRUE(Delete(no_body_request_));
940 EXPECT_EQ(0, cache_->MemoryBackedSize()); 944 EXPECT_EQ(0, cache_->MemoryBackedSize());
941 945
942 EXPECT_TRUE(Put(body_request_, body_response_)); 946 EXPECT_TRUE(Put(body_request_, body_response_));
943 EXPECT_LT(no_body_size, cache_->MemoryBackedSize()); 947 EXPECT_LT(no_body_size, cache_->MemoryBackedSize());
944 948
945 EXPECT_TRUE(Delete(body_request_)); 949 EXPECT_TRUE(Delete(body_request_));
946 EXPECT_EQ(0, cache_->MemoryBackedSize()); 950 EXPECT_EQ(0, cache_->MemoryBackedSize());
947 } 951 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 EXPECT_EQ(1, sequence_out); 1014 EXPECT_EQ(1, sequence_out);
1011 close_loop2->Run(); 1015 close_loop2->Run();
1012 EXPECT_EQ(2, sequence_out); 1016 EXPECT_EQ(2, sequence_out);
1013 } 1017 }
1014 1018
1015 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 1019 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
1016 CacheStorageCacheTestP, 1020 CacheStorageCacheTestP,
1017 ::testing::Values(false, true)); 1021 ::testing::Values(false, true));
1018 1022
1019 } // namespace content 1023 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.cc ('k') | content/browser/cache_storage/cache_storage_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698