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

Side by Side Diff: content/browser/blob_storage/blob_reader_unittest.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added back transport controller test, small cleanups Created 4 years, 5 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 EXPECT_EQ(BlobReader::Status::DONE, 1167 EXPECT_EQ(BlobReader::Status::DONE,
1168 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result))); 1168 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1169 buffer = CreateBuffer(kDataSize + 1); 1169 buffer = CreateBuffer(kDataSize + 1);
1170 EXPECT_EQ(BlobReader::Status::NET_ERROR, 1170 EXPECT_EQ(BlobReader::Status::NET_ERROR,
1171 reader_->SetReadRange(0, kDataSize + 1)); 1171 reader_->SetReadRange(0, kDataSize + 1));
1172 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, reader_->net_error()); 1172 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, reader_->net_error());
1173 } 1173 }
1174 1174
1175 TEST_F(BlobReaderTest, HandleBeforeAsyncCancel) { 1175 TEST_F(BlobReaderTest, HandleBeforeAsyncCancel) {
1176 const std::string kUuid("uuid1"); 1176 const std::string kUuid("uuid1");
1177 const std::string kData("Hello!!!");
1178 const size_t kDataSize = 8ul;
1177 1179
1178 context_.CreatePendingBlob(kUuid, "", ""); 1180 BlobDataBuilder b(kUuid);
1179 blob_handle_ = context_.GetBlobDataFromUUID(kUuid); 1181 b.AppendFutureData(kDataSize);
1182 blob_handle_ = context_.BuildBlob(b, true);
1180 provider_ = new MockFileStreamReaderProvider(); 1183 provider_ = new MockFileStreamReaderProvider();
1181 reader_.reset(new BlobReader(blob_handle_.get(), base::WrapUnique(provider_), 1184 reader_.reset(new BlobReader(blob_handle_.get(), base::WrapUnique(provider_),
1182 message_loop_.task_runner().get())); 1185 message_loop_.task_runner().get()));
1183 int size_result = -1; 1186 int size_result = -1;
1184 EXPECT_EQ(BlobReader::Status::IO_PENDING, 1187 EXPECT_EQ(BlobReader::Status::IO_PENDING,
1185 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result))); 1188 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1186 EXPECT_FALSE(reader_->IsInMemory()); 1189 EXPECT_FALSE(reader_->IsInMemory());
1187 context_.CancelPendingBlob(kUuid, IPCBlobCreationCancelCode::UNKNOWN); 1190 context_.BreakAndFinishBlob(kUuid, IPCBlobCreationCancelCode::UNKNOWN);
1188 message_loop_.RunUntilIdle(); 1191 message_loop_.RunUntilIdle();
1189 EXPECT_EQ(net::ERR_FAILED, size_result); 1192 EXPECT_EQ(net::ERR_FAILED, size_result);
1190 } 1193 }
1191 1194
1192 TEST_F(BlobReaderTest, ReadFromIncompleteBlob) { 1195 TEST_F(BlobReaderTest, ReadFromIncompleteBlob) {
1193 const std::string kUuid("uuid1"); 1196 const std::string kUuid("uuid1");
1194 const std::string kData("Hello!!!"); 1197 const std::string kData("Hello!!!");
1195 const size_t kDataSize = 8ul; 1198 const size_t kDataSize = 8ul;
1196 1199
1197 BlobDataBuilder b(kUuid); 1200 BlobDataBuilder b(kUuid);
1198 b.AppendData(kData); 1201 b.AppendFutureData(kDataSize);
1199 context_.CreatePendingBlob(kUuid, "", ""); 1202 blob_handle_ = context_.BuildBlob(b, true);
1200 blob_handle_ = context_.GetBlobDataFromUUID(kUuid);
1201 provider_ = new MockFileStreamReaderProvider(); 1203 provider_ = new MockFileStreamReaderProvider();
1202 reader_.reset(new BlobReader(blob_handle_.get(), base::WrapUnique(provider_), 1204 reader_.reset(new BlobReader(blob_handle_.get(), base::WrapUnique(provider_),
1203 message_loop_.task_runner().get())); 1205 message_loop_.task_runner().get()));
1204 int size_result = -1; 1206 int size_result = -1;
1205 EXPECT_EQ(BlobReader::Status::IO_PENDING, 1207 EXPECT_EQ(BlobReader::Status::IO_PENDING,
1206 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result))); 1208 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1207 EXPECT_FALSE(reader_->IsInMemory()); 1209 EXPECT_FALSE(reader_->IsInMemory());
1208 context_.CompletePendingBlob(b); 1210 b.PopulateFutureData(0, kData.data(), 0, kDataSize);
1211 context_.FinishedPopulatingBlob(kUuid);
1209 message_loop_.RunUntilIdle(); 1212 message_loop_.RunUntilIdle();
1210 CheckSizeCalculatedAsynchronously(kDataSize, size_result); 1213 CheckSizeCalculatedAsynchronously(kDataSize, size_result);
1211 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kDataSize)); 1214 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kDataSize));
1212 1215
1213 int bytes_read = 0; 1216 int bytes_read = 0;
1214 int async_bytes_read = 0; 1217 int async_bytes_read = 0;
1215 EXPECT_EQ(BlobReader::Status::DONE, 1218 EXPECT_EQ(BlobReader::Status::DONE,
1216 reader_->Read(buffer.get(), kDataSize, &bytes_read, 1219 reader_->Read(buffer.get(), kDataSize, &bytes_read,
1217 base::Bind(&SetValue<int>, &async_bytes_read))); 1220 base::Bind(&SetValue<int>, &async_bytes_read)));
1218 EXPECT_EQ(net::OK, reader_->net_error()); 1221 EXPECT_EQ(net::OK, reader_->net_error());
1219 EXPECT_EQ(kDataSize, static_cast<size_t>(bytes_read)); 1222 EXPECT_EQ(kDataSize, static_cast<size_t>(bytes_read));
1220 EXPECT_EQ(0, async_bytes_read); 1223 EXPECT_EQ(0, async_bytes_read);
1221 EXPECT_EQ(kData, std::string(buffer->data(), kDataSize)); 1224 EXPECT_EQ(kData, std::string(buffer->data(), kDataSize));
1222 EXPECT_EQ(net::OK, size_result); 1225 EXPECT_EQ(net::OK, size_result);
1223 } 1226 }
1224 1227
1225 } // namespace storage 1228 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698