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

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

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: Comments Created 4 years, 9 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 reader_.reset(); 320 reader_.reset();
321 blob_handle_.reset(); 321 blob_handle_.reset();
322 message_loop_.RunUntilIdle(); 322 message_loop_.RunUntilIdle();
323 base::RunLoop().RunUntilIdle(); 323 base::RunLoop().RunUntilIdle();
324 } 324 }
325 325
326 protected: 326 protected:
327 void InitializeReader(BlobDataBuilder* builder) { 327 void InitializeReader(BlobDataBuilder* builder) {
328 blob_handle_ = builder ? context_.AddFinishedBlob(builder) : nullptr; 328 blob_handle_ = builder ? context_.AddFinishedBlob(builder) : nullptr;
329 provider_ = new MockFileStreamReaderProvider(); 329 provider_ = new MockFileStreamReaderProvider();
330 scoped_ptr<BlobReader::FileStreamReaderProvider> temp_ptr(provider_); 330 reader_.reset(new BlobReader(blob_handle_.get(), make_scoped_ptr(provider_),
331 reader_.reset(new BlobReader(blob_handle_.get(), std::move(temp_ptr),
332 message_loop_.task_runner().get())); 331 message_loop_.task_runner().get()));
333 } 332 }
334 333
335 // Takes ownership of the file reader (the blob reader takes ownership). 334 // Takes ownership of the file reader (the blob reader takes ownership).
336 void ExpectLocalFileCall(const FilePath& file_path, 335 void ExpectLocalFileCall(const FilePath& file_path,
337 base::Time modification_time, 336 base::Time modification_time,
338 uint64_t initial_offset, 337 uint64_t initial_offset,
339 FakeFileStreamReader* reader) { 338 FakeFileStreamReader* reader) {
340 EXPECT_CALL(*provider_, CreateForLocalFileMock( 339 EXPECT_CALL(*provider_, CreateForLocalFileMock(
341 message_loop_.task_runner().get(), file_path, 340 message_loop_.task_runner().get(), file_path,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 BlobStorageContext context_; 387 BlobStorageContext context_;
389 scoped_ptr<BlobDataHandle> blob_handle_; 388 scoped_ptr<BlobDataHandle> blob_handle_;
390 MockFileStreamReaderProvider* provider_ = nullptr; 389 MockFileStreamReaderProvider* provider_ = nullptr;
391 base::MessageLoop message_loop_; 390 base::MessageLoop message_loop_;
392 scoped_ptr<BlobReader> reader_; 391 scoped_ptr<BlobReader> reader_;
393 392
394 private: 393 private:
395 DISALLOW_COPY_AND_ASSIGN(BlobReaderTest); 394 DISALLOW_COPY_AND_ASSIGN(BlobReaderTest);
396 }; 395 };
397 396
398 namespace {
399
400 TEST_F(BlobReaderTest, BasicMemory) { 397 TEST_F(BlobReaderTest, BasicMemory) {
401 BlobDataBuilder b("uuid"); 398 BlobDataBuilder b("uuid");
402 const std::string kData("Hello!!!"); 399 const std::string kData("Hello!!!");
403 const size_t kDataSize = 8ul; 400 const size_t kDataSize = 8ul;
404 b.AppendData(kData); 401 b.AppendData(kData);
405 this->InitializeReader(&b); 402 this->InitializeReader(&b);
406 403
407 int size_result = -1; 404 int size_result = -1;
408 EXPECT_FALSE(IsReaderTotalSizeCalculated()); 405 EXPECT_FALSE(IsReaderTotalSizeCalculated());
409 EXPECT_EQ(BlobReader::Status::DONE, 406 EXPECT_EQ(BlobReader::Status::DONE,
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 this->InitializeReader(&b2); 1103 this->InitializeReader(&b2);
1107 size_result = -1; 1104 size_result = -1;
1108 EXPECT_EQ(BlobReader::Status::DONE, 1105 EXPECT_EQ(BlobReader::Status::DONE,
1109 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result))); 1106 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1110 buffer = CreateBuffer(kDataSize + 1); 1107 buffer = CreateBuffer(kDataSize + 1);
1111 EXPECT_EQ(BlobReader::Status::NET_ERROR, 1108 EXPECT_EQ(BlobReader::Status::NET_ERROR,
1112 reader_->SetReadRange(0, kDataSize + 1)); 1109 reader_->SetReadRange(0, kDataSize + 1));
1113 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, reader_->net_error()); 1110 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, reader_->net_error());
1114 } 1111 }
1115 1112
1116 } // namespace 1113 TEST_F(BlobReaderTest, HandleBeforeAsyncCancel) {
1114 const std::string kUuid("uuid1");
1115
1116 context_.CreatePendingBlob(kUuid, "", "");
1117 blob_handle_ = context_.GetBlobDataFromUUID(kUuid);
1118 provider_ = new MockFileStreamReaderProvider();
1119 reader_.reset(new BlobReader(blob_handle_.get(), make_scoped_ptr(provider_),
1120 message_loop_.task_runner().get()));
1121 int size_result = -1;
1122 EXPECT_EQ(BlobReader::Status::IO_PENDING,
1123 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1124 context_.CancelPendingBlob(kUuid, IPCBlobCreationCancelCode::UNKNOWN);
1125 message_loop_.RunUntilIdle();
1126 EXPECT_EQ(net::ERR_FAILED, size_result);
1127 }
1128
1129 TEST_F(BlobReaderTest, ReadFromIncompleteBlob) {
1130 const std::string kUuid("uuid1");
1131 const std::string kData("Hello!!!");
1132 const size_t kDataSize = 8ul;
1133
1134 BlobDataBuilder b(kUuid);
1135 b.AppendData(kData);
1136 context_.CreatePendingBlob(kUuid, "", "");
1137 blob_handle_ = context_.GetBlobDataFromUUID(kUuid);
1138 provider_ = new MockFileStreamReaderProvider();
1139 reader_.reset(new BlobReader(blob_handle_.get(), make_scoped_ptr(provider_),
1140 message_loop_.task_runner().get()));
1141 int size_result = -1;
1142 EXPECT_EQ(BlobReader::Status::IO_PENDING,
1143 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1144 context_.CompletePendingBlob(b);
1145 message_loop_.RunUntilIdle();
1146 CheckSizeCalculatedAsynchronously(kDataSize, size_result);
1147 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kDataSize));
1148
1149 int bytes_read = 0;
1150 int async_bytes_read = 0;
1151 EXPECT_EQ(BlobReader::Status::DONE,
1152 reader_->Read(buffer.get(), kDataSize, &bytes_read,
1153 base::Bind(&SetValue<int>, &async_bytes_read)));
1154 EXPECT_EQ(net::OK, reader_->net_error());
1155 EXPECT_EQ(kDataSize, static_cast<size_t>(bytes_read));
1156 EXPECT_EQ(0, async_bytes_read);
1157 EXPECT_EQ(kData, std::string(buffer->data(), kDataSize));
1158 EXPECT_EQ(net::OK, size_result);
1159 }
1160
1117 } // namespace storage 1161 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698