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

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: added shared memory test, and fixed memory leak Created 4 years, 10 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 const std::string kData("Hello!!!");
1116
1117 BlobDataBuilder b(kUuid);
1118 b.AppendData(kData);
1119 context_.CreatePendingBlob(kUuid, "", "");
1120 blob_handle_ = context_.GetBlobDataFromUUID(kUuid);
1121 provider_ = new MockFileStreamReaderProvider();
1122 reader_.reset(new BlobReader(blob_handle_.get(), make_scoped_ptr(provider_),
1123 message_loop_.task_runner().get()));
1124 int size_result = -1;
1125 EXPECT_EQ(BlobReader::Status::IO_PENDING,
1126 reader_->CalculateSize(base::Bind(&SetValue<int>, &size_result)));
1127 context_.CancelPendingBlob(kUuid, IPCBlobCreationCancelCode::UNKNOWN);
1128 message_loop_.RunUntilIdle();
1129 EXPECT_EQ(net::ERR_FAILED, size_result);
1130 }
1131
1117 } // namespace storage 1132 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698