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

Side by Side Diff: content/browser/fileapi/blob_reader_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "storage/browser/blob/blob_reader.h" 5 #include "storage/browser/blob/blob_reader.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include "base/bind.h" 10 #include "base/bind.h"
8 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
9 #include "base/callback.h" 12 #include "base/callback.h"
10 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
11 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 18 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
16 #include "base/task_runner.h" 20 #include "base/task_runner.h"
17 #include "base/time/time.h" 21 #include "base/time/time.h"
18 #include "content/public/test/async_file_test_helper.h" 22 #include "content/public/test/async_file_test_helper.h"
19 #include "content/public/test/test_file_system_context.h" 23 #include "content/public/test/test_file_system_context.h"
20 #include "net/base/completion_callback.h" 24 #include "net/base/completion_callback.h"
21 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void Close() override { delete this; } // Note this is required by the API. 77 void Close() override { delete this; } // Note this is required by the API.
74 78
75 std::string GetKey() const override { return entry_->GetKey(); } 79 std::string GetKey() const override { return entry_->GetKey(); }
76 80
77 base::Time GetLastUsed() const override { return entry_->GetLastUsed(); } 81 base::Time GetLastUsed() const override { return entry_->GetLastUsed(); }
78 82
79 base::Time GetLastModified() const override { 83 base::Time GetLastModified() const override {
80 return entry_->GetLastModified(); 84 return entry_->GetLastModified();
81 } 85 }
82 86
83 int32 GetDataSize(int index) const override { 87 int32_t GetDataSize(int index) const override {
84 return entry_->GetDataSize(index); 88 return entry_->GetDataSize(index);
85 } 89 }
86 90
87 int ReadData(int index, 91 int ReadData(int index,
88 int offset, 92 int offset,
89 IOBuffer* buf, 93 IOBuffer* buf,
90 int buf_len, 94 int buf_len,
91 const CompletionCallback& original_callback) override { 95 const CompletionCallback& original_callback) override {
92 net::TestCompletionCallback callback; 96 net::TestCompletionCallback callback;
93 int rv = entry_->ReadData(index, offset, buf, buf_len, callback.callback()); 97 int rv = entry_->ReadData(index, offset, buf, buf_len, callback.callback());
94 DCHECK_NE(rv, net::ERR_IO_PENDING) 98 DCHECK_NE(rv, net::ERR_IO_PENDING)
95 << "Test expects to use a MEMORY_CACHE instance, which is synchronous."; 99 << "Test expects to use a MEMORY_CACHE instance, which is synchronous.";
96 pending_read_callbacks_.push_back(base::Bind(original_callback, rv)); 100 pending_read_callbacks_.push_back(base::Bind(original_callback, rv));
97 return net::ERR_IO_PENDING; 101 return net::ERR_IO_PENDING;
98 } 102 }
99 103
100 int WriteData(int index, 104 int WriteData(int index,
101 int offset, 105 int offset,
102 IOBuffer* buf, 106 IOBuffer* buf,
103 int buf_len, 107 int buf_len,
104 const CompletionCallback& callback, 108 const CompletionCallback& callback,
105 bool truncate) override { 109 bool truncate) override {
106 return entry_->WriteData(index, offset, buf, buf_len, callback, truncate); 110 return entry_->WriteData(index, offset, buf, buf_len, callback, truncate);
107 } 111 }
108 112
109 int ReadSparseData(int64 offset, 113 int ReadSparseData(int64_t offset,
110 IOBuffer* buf, 114 IOBuffer* buf,
111 int buf_len, 115 int buf_len,
112 const CompletionCallback& callback) override { 116 const CompletionCallback& callback) override {
113 return entry_->ReadSparseData(offset, buf, buf_len, callback); 117 return entry_->ReadSparseData(offset, buf, buf_len, callback);
114 } 118 }
115 119
116 int WriteSparseData(int64 offset, 120 int WriteSparseData(int64_t offset,
117 IOBuffer* buf, 121 IOBuffer* buf,
118 int buf_len, 122 int buf_len,
119 const CompletionCallback& callback) override { 123 const CompletionCallback& callback) override {
120 return entry_->WriteSparseData(offset, buf, buf_len, callback); 124 return entry_->WriteSparseData(offset, buf, buf_len, callback);
121 } 125 }
122 126
123 int GetAvailableRange(int64 offset, 127 int GetAvailableRange(int64_t offset,
124 int len, 128 int len,
125 int64* start, 129 int64_t* start,
126 const CompletionCallback& callback) override { 130 const CompletionCallback& callback) override {
127 return entry_->GetAvailableRange(offset, len, start, callback); 131 return entry_->GetAvailableRange(offset, len, start, callback);
128 } 132 }
129 133
130 bool CouldBeSparse() const override { return entry_->CouldBeSparse(); } 134 bool CouldBeSparse() const override { return entry_->CouldBeSparse(); }
131 135
132 void CancelSparseIO() override { entry_->CancelSparseIO(); } 136 void CancelSparseIO() override { entry_->CancelSparseIO(); }
133 137
134 int ReadyForSparseIO(const CompletionCallback& callback) override { 138 int ReadyForSparseIO(const CompletionCallback& callback) override {
135 return entry_->ReadyForSparseIO(callback); 139 return entry_->ReadyForSparseIO(callback);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 FROM_HERE, 222 FROM_HERE,
219 base::Bind(base::IgnoreResult(&FakeFileStreamReader::ReadImpl), 223 base::Bind(base::IgnoreResult(&FakeFileStreamReader::ReadImpl),
220 base::Unretained(this), make_scoped_refptr(buf), 224 base::Unretained(this), make_scoped_refptr(buf),
221 buf_length, done)); 225 buf_length, done));
222 } else { 226 } else {
223 async_task_runner_->PostTask(FROM_HERE, base::Bind(done, net_error_)); 227 async_task_runner_->PostTask(FROM_HERE, base::Bind(done, net_error_));
224 } 228 }
225 return net::ERR_IO_PENDING; 229 return net::ERR_IO_PENDING;
226 } 230 }
227 231
228 int64 GetLength(const net::Int64CompletionCallback& size_callback) override { 232 int64_t GetLength(
233 const net::Int64CompletionCallback& size_callback) override {
229 // When async_task_runner_ is not set, return synchronously. 234 // When async_task_runner_ is not set, return synchronously.
230 if (!async_task_runner_.get()) { 235 if (!async_task_runner_.get()) {
231 if (net_error_ == net::OK) { 236 if (net_error_ == net::OK) {
232 return size_; 237 return size_;
233 } else { 238 } else {
234 return net_error_; 239 return net_error_;
235 } 240 }
236 } 241 }
237 if (net_error_ == net::OK) { 242 if (net_error_ == net::OK) {
238 async_task_runner_->PostTask(FROM_HERE, base::Bind(size_callback, size_)); 243 async_task_runner_->PostTask(FROM_HERE, base::Bind(size_callback, size_));
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 reader_->Read(buffer.get(), kReadLength, &bytes_read, 826 reader_->Read(buffer.get(), kReadLength, &bytes_read,
822 base::Bind(&SetValue<int>, &async_bytes_read))); 827 base::Bind(&SetValue<int>, &async_bytes_read)));
823 EXPECT_EQ(net::OK, reader_->net_error()); 828 EXPECT_EQ(net::OK, reader_->net_error());
824 EXPECT_EQ(kReadLength, static_cast<size_t>(bytes_read)); 829 EXPECT_EQ(kReadLength, static_cast<size_t>(bytes_read));
825 EXPECT_EQ(0, async_bytes_read); 830 EXPECT_EQ(0, async_bytes_read);
826 EXPECT_EQ(0, memcmp(buffer->data(), "st ", kReadLength)); 831 EXPECT_EQ(0, memcmp(buffer->data(), "st ", kReadLength));
827 } 832 }
828 833
829 TEST_F(BlobReaderTest, FileSomeAsyncSegmentedOffsetsUnknownSizes) { 834 TEST_F(BlobReaderTest, FileSomeAsyncSegmentedOffsetsUnknownSizes) {
830 // This tests includes: 835 // This tests includes:
831 // * Unknown file sizes (item length of uint64::max) for every other item. 836 // * Unknown file sizes (item length of uint64_t::max) for every other item.
832 // * Offsets for every 3rd file item. 837 // * Offsets for every 3rd file item.
833 // * Non-async reader for every 4th file item. 838 // * Non-async reader for every 4th file item.
834 BlobDataBuilder b("uuid"); 839 BlobDataBuilder b("uuid");
835 const FilePath kPathBase = FilePath::FromUTF8Unsafe("/fake/file.txt"); 840 const FilePath kPathBase = FilePath::FromUTF8Unsafe("/fake/file.txt");
836 const base::Time kTime = base::Time::Now(); 841 const base::Time kTime = base::Time::Now();
837 const size_t kNumItems = 10; 842 const size_t kNumItems = 10;
838 const size_t kItemSize = 6; 843 const size_t kItemSize = 6;
839 const size_t kBufferSize = 10; 844 const size_t kBufferSize = 10;
840 const size_t kTotalSize = kNumItems * kItemSize; 845 const size_t kTotalSize = kNumItems * kItemSize;
841 char current_value = 0; 846 char current_value = 0;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 EXPECT_EQ(BlobReader::Status::DONE, 1107 EXPECT_EQ(BlobReader::Status::DONE,
1103 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result))); 1108 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1104 buffer = CreateBuffer(kDataSize + 1); 1109 buffer = CreateBuffer(kDataSize + 1);
1105 EXPECT_EQ(BlobReader::Status::NET_ERROR, 1110 EXPECT_EQ(BlobReader::Status::NET_ERROR,
1106 reader_->SetReadRange(0, kDataSize + 1)); 1111 reader_->SetReadRange(0, kDataSize + 1));
1107 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, reader_->net_error()); 1112 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, reader_->net_error());
1108 } 1113 }
1109 1114
1110 } // namespace 1115 } // namespace
1111 } // namespace storage 1116 } // namespace storage
OLDNEW
« no previous file with comments | « content/browser/file_descriptor_info_impl_unittest.cc ('k') | content/browser/fileapi/blob_storage_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698