| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/elements_upload_data_stream.h" | 5 #include "net/base/elements_upload_data_stream.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 const base::Time& time, | 147 const base::Time& time, |
| 148 bool error_expected); | 148 bool error_expected); |
| 149 | 149 |
| 150 base::ScopedTempDir temp_dir_; | 150 base::ScopedTempDir temp_dir_; |
| 151 std::vector<std::unique_ptr<UploadElementReader>> element_readers_; | 151 std::vector<std::unique_ptr<UploadElementReader>> element_readers_; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 TEST_F(ElementsUploadDataStreamTest, EmptyUploadData) { | 154 TEST_F(ElementsUploadDataStreamTest, EmptyUploadData) { |
| 155 std::unique_ptr<UploadDataStream> stream( | 155 std::unique_ptr<UploadDataStream> stream( |
| 156 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 156 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 157 ASSERT_THAT(stream->Init(CompletionCallback(), BoundNetLog()), IsOk()); | 157 ASSERT_THAT(stream->Init(CompletionCallback(), NetLogWithSource()), IsOk()); |
| 158 EXPECT_TRUE(stream->IsInMemory()); | 158 EXPECT_TRUE(stream->IsInMemory()); |
| 159 EXPECT_EQ(0U, stream->size()); | 159 EXPECT_EQ(0U, stream->size()); |
| 160 EXPECT_EQ(0U, stream->position()); | 160 EXPECT_EQ(0U, stream->position()); |
| 161 EXPECT_TRUE(stream->IsEOF()); | 161 EXPECT_TRUE(stream->IsEOF()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 TEST_F(ElementsUploadDataStreamTest, ConsumeAllBytes) { | 164 TEST_F(ElementsUploadDataStreamTest, ConsumeAllBytes) { |
| 165 element_readers_.push_back( | 165 element_readers_.push_back( |
| 166 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); | 166 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); |
| 167 std::unique_ptr<UploadDataStream> stream( | 167 std::unique_ptr<UploadDataStream> stream( |
| 168 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 168 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 169 ASSERT_THAT(stream->Init(CompletionCallback(), BoundNetLog()), IsOk()); | 169 ASSERT_THAT(stream->Init(CompletionCallback(), NetLogWithSource()), IsOk()); |
| 170 EXPECT_TRUE(stream->IsInMemory()); | 170 EXPECT_TRUE(stream->IsInMemory()); |
| 171 EXPECT_EQ(kTestDataSize, stream->size()); | 171 EXPECT_EQ(kTestDataSize, stream->size()); |
| 172 EXPECT_EQ(0U, stream->position()); | 172 EXPECT_EQ(0U, stream->position()); |
| 173 EXPECT_FALSE(stream->IsEOF()); | 173 EXPECT_FALSE(stream->IsEOF()); |
| 174 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 174 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 175 while (!stream->IsEOF()) { | 175 while (!stream->IsEOF()) { |
| 176 int bytes_read = | 176 int bytes_read = |
| 177 stream->Read(buf.get(), kTestBufferSize, CompletionCallback()); | 177 stream->Read(buf.get(), kTestBufferSize, CompletionCallback()); |
| 178 ASSERT_LE(0, bytes_read); // Not an error. | 178 ASSERT_LE(0, bytes_read); // Not an error. |
| 179 } | 179 } |
| 180 EXPECT_EQ(kTestDataSize, stream->position()); | 180 EXPECT_EQ(kTestDataSize, stream->position()); |
| 181 ASSERT_TRUE(stream->IsEOF()); | 181 ASSERT_TRUE(stream->IsEOF()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 TEST_F(ElementsUploadDataStreamTest, File) { | 184 TEST_F(ElementsUploadDataStreamTest, File) { |
| 185 base::FilePath temp_file_path; | 185 base::FilePath temp_file_path; |
| 186 ASSERT_TRUE( | 186 ASSERT_TRUE( |
| 187 base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path)); | 187 base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &temp_file_path)); |
| 188 ASSERT_EQ(static_cast<int>(kTestDataSize), | 188 ASSERT_EQ(static_cast<int>(kTestDataSize), |
| 189 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 189 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
| 190 | 190 |
| 191 element_readers_.push_back(base::MakeUnique<UploadFileElementReader>( | 191 element_readers_.push_back(base::MakeUnique<UploadFileElementReader>( |
| 192 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, | 192 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 193 std::numeric_limits<uint64_t>::max(), base::Time())); | 193 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 194 | 194 |
| 195 TestCompletionCallback init_callback; | 195 TestCompletionCallback init_callback; |
| 196 std::unique_ptr<UploadDataStream> stream( | 196 std::unique_ptr<UploadDataStream> stream( |
| 197 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 197 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 198 ASSERT_THAT(stream->Init(init_callback.callback(), BoundNetLog()), | 198 ASSERT_THAT(stream->Init(init_callback.callback(), NetLogWithSource()), |
| 199 IsError(ERR_IO_PENDING)); | 199 IsError(ERR_IO_PENDING)); |
| 200 ASSERT_THAT(init_callback.WaitForResult(), IsOk()); | 200 ASSERT_THAT(init_callback.WaitForResult(), IsOk()); |
| 201 EXPECT_FALSE(stream->IsInMemory()); | 201 EXPECT_FALSE(stream->IsInMemory()); |
| 202 EXPECT_EQ(kTestDataSize, stream->size()); | 202 EXPECT_EQ(kTestDataSize, stream->size()); |
| 203 EXPECT_EQ(0U, stream->position()); | 203 EXPECT_EQ(0U, stream->position()); |
| 204 EXPECT_FALSE(stream->IsEOF()); | 204 EXPECT_FALSE(stream->IsEOF()); |
| 205 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 205 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 206 while (!stream->IsEOF()) { | 206 while (!stream->IsEOF()) { |
| 207 TestCompletionCallback read_callback; | 207 TestCompletionCallback read_callback; |
| 208 ASSERT_EQ( | 208 ASSERT_EQ( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 225 UploadFileElementReader::ScopedOverridingContentLengthForTests | 225 UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 226 overriding_content_length(kFakeSize); | 226 overriding_content_length(kFakeSize); |
| 227 | 227 |
| 228 element_readers_.push_back(base::MakeUnique<UploadFileElementReader>( | 228 element_readers_.push_back(base::MakeUnique<UploadFileElementReader>( |
| 229 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, | 229 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 230 std::numeric_limits<uint64_t>::max(), base::Time())); | 230 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 231 | 231 |
| 232 TestCompletionCallback init_callback; | 232 TestCompletionCallback init_callback; |
| 233 std::unique_ptr<UploadDataStream> stream( | 233 std::unique_ptr<UploadDataStream> stream( |
| 234 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 234 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 235 ASSERT_THAT(stream->Init(init_callback.callback(), BoundNetLog()), | 235 ASSERT_THAT(stream->Init(init_callback.callback(), NetLogWithSource()), |
| 236 IsError(ERR_IO_PENDING)); | 236 IsError(ERR_IO_PENDING)); |
| 237 ASSERT_THAT(init_callback.WaitForResult(), IsOk()); | 237 ASSERT_THAT(init_callback.WaitForResult(), IsOk()); |
| 238 EXPECT_FALSE(stream->IsInMemory()); | 238 EXPECT_FALSE(stream->IsInMemory()); |
| 239 EXPECT_EQ(kFakeSize, stream->size()); | 239 EXPECT_EQ(kFakeSize, stream->size()); |
| 240 EXPECT_EQ(0U, stream->position()); | 240 EXPECT_EQ(0U, stream->position()); |
| 241 | 241 |
| 242 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 242 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 243 EXPECT_FALSE(stream->IsEOF()); | 243 EXPECT_FALSE(stream->IsEOF()); |
| 244 | 244 |
| 245 TestCompletionCallback read_callback; | 245 TestCompletionCallback read_callback; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 267 element_readers_.push_back(std::move(reader)); | 267 element_readers_.push_back(std::move(reader)); |
| 268 | 268 |
| 269 // This element is ignored because of the error from the previous reader. | 269 // This element is ignored because of the error from the previous reader. |
| 270 element_readers_.push_back( | 270 element_readers_.push_back( |
| 271 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); | 271 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); |
| 272 | 272 |
| 273 std::unique_ptr<UploadDataStream> stream( | 273 std::unique_ptr<UploadDataStream> stream( |
| 274 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 274 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 275 | 275 |
| 276 // Run Init(). | 276 // Run Init(). |
| 277 ASSERT_THAT(stream->Init(CompletionCallback(), BoundNetLog()), IsOk()); | 277 ASSERT_THAT(stream->Init(CompletionCallback(), NetLogWithSource()), IsOk()); |
| 278 EXPECT_EQ(kTestDataSize*2, stream->size()); | 278 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 279 EXPECT_EQ(0U, stream->position()); | 279 EXPECT_EQ(0U, stream->position()); |
| 280 EXPECT_FALSE(stream->IsEOF()); | 280 EXPECT_FALSE(stream->IsEOF()); |
| 281 | 281 |
| 282 // Prepare a buffer filled with non-zero data. | 282 // Prepare a buffer filled with non-zero data. |
| 283 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 283 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 284 std::fill_n(buf->data(), kTestBufferSize, -1); | 284 std::fill_n(buf->data(), kTestBufferSize, -1); |
| 285 | 285 |
| 286 // Read() results in success even when the reader returns error. | 286 // Read() results in success even when the reader returns error. |
| 287 EXPECT_EQ(ERR_FAILED, | 287 EXPECT_EQ(ERR_FAILED, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 303 | 303 |
| 304 // This element is ignored because of the error from the previous reader. | 304 // This element is ignored because of the error from the previous reader. |
| 305 element_readers_.push_back( | 305 element_readers_.push_back( |
| 306 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); | 306 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); |
| 307 | 307 |
| 308 std::unique_ptr<UploadDataStream> stream( | 308 std::unique_ptr<UploadDataStream> stream( |
| 309 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 309 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 310 | 310 |
| 311 // Run Init(). | 311 // Run Init(). |
| 312 TestCompletionCallback init_callback; | 312 TestCompletionCallback init_callback; |
| 313 ASSERT_THAT(stream->Init(init_callback.callback(), BoundNetLog()), | 313 ASSERT_THAT(stream->Init(init_callback.callback(), NetLogWithSource()), |
| 314 IsError(ERR_IO_PENDING)); | 314 IsError(ERR_IO_PENDING)); |
| 315 EXPECT_THAT(init_callback.WaitForResult(), IsOk()); | 315 EXPECT_THAT(init_callback.WaitForResult(), IsOk()); |
| 316 EXPECT_EQ(kTestDataSize*2, stream->size()); | 316 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 317 EXPECT_EQ(0U, stream->position()); | 317 EXPECT_EQ(0U, stream->position()); |
| 318 EXPECT_FALSE(stream->IsEOF()); | 318 EXPECT_FALSE(stream->IsEOF()); |
| 319 | 319 |
| 320 // Prepare a buffer filled with non-zero data. | 320 // Prepare a buffer filled with non-zero data. |
| 321 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 321 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 322 std::fill_n(buf->data(), kTestBufferSize, -1); | 322 std::fill_n(buf->data(), kTestBufferSize, -1); |
| 323 | 323 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 346 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, | 346 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, |
| 347 kFileRangeOffset, kFileRangeLength, base::Time())); | 347 kFileRangeOffset, kFileRangeLength, base::Time())); |
| 348 | 348 |
| 349 element_readers_.push_back( | 349 element_readers_.push_back( |
| 350 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); | 350 base::MakeUnique<UploadBytesElementReader>(kTestData, kTestDataSize)); |
| 351 | 351 |
| 352 const uint64_t kStreamSize = kTestDataSize + kFileRangeLength; | 352 const uint64_t kStreamSize = kTestDataSize + kFileRangeLength; |
| 353 TestCompletionCallback init_callback; | 353 TestCompletionCallback init_callback; |
| 354 std::unique_ptr<UploadDataStream> stream( | 354 std::unique_ptr<UploadDataStream> stream( |
| 355 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 355 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 356 ASSERT_THAT(stream->Init(init_callback.callback(), BoundNetLog()), | 356 ASSERT_THAT(stream->Init(init_callback.callback(), NetLogWithSource()), |
| 357 IsError(ERR_IO_PENDING)); | 357 IsError(ERR_IO_PENDING)); |
| 358 ASSERT_THAT(init_callback.WaitForResult(), IsOk()); | 358 ASSERT_THAT(init_callback.WaitForResult(), IsOk()); |
| 359 EXPECT_FALSE(stream->IsInMemory()); | 359 EXPECT_FALSE(stream->IsInMemory()); |
| 360 EXPECT_EQ(kStreamSize, stream->size()); | 360 EXPECT_EQ(kStreamSize, stream->size()); |
| 361 EXPECT_EQ(0U, stream->position()); | 361 EXPECT_EQ(0U, stream->position()); |
| 362 EXPECT_FALSE(stream->IsEOF()); | 362 EXPECT_FALSE(stream->IsEOF()); |
| 363 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 363 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 364 while (!stream->IsEOF()) { | 364 while (!stream->IsEOF()) { |
| 365 TestCompletionCallback read_callback; | 365 TestCompletionCallback read_callback; |
| 366 const int result = | 366 const int result = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 std::unique_ptr<MockUploadElementReader> reader5( | 399 std::unique_ptr<MockUploadElementReader> reader5( |
| 400 new MockUploadElementReader(kTestDataSize, true)); | 400 new MockUploadElementReader(kTestDataSize, true)); |
| 401 EXPECT_CALL(*reader5, Init(_)).WillOnce(Return(OK)); | 401 EXPECT_CALL(*reader5, Init(_)).WillOnce(Return(OK)); |
| 402 element_readers_.push_back(std::move(reader5)); | 402 element_readers_.push_back(std::move(reader5)); |
| 403 | 403 |
| 404 std::unique_ptr<UploadDataStream> stream( | 404 std::unique_ptr<UploadDataStream> stream( |
| 405 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 405 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 406 | 406 |
| 407 // Run Init(). | 407 // Run Init(). |
| 408 TestCompletionCallback callback; | 408 TestCompletionCallback callback; |
| 409 ASSERT_THAT(stream->Init(callback.callback(), BoundNetLog()), | 409 ASSERT_THAT(stream->Init(callback.callback(), NetLogWithSource()), |
| 410 IsError(ERR_IO_PENDING)); | 410 IsError(ERR_IO_PENDING)); |
| 411 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 411 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 412 } | 412 } |
| 413 | 413 |
| 414 // Init() of a reader fails asynchronously. | 414 // Init() of a reader fails asynchronously. |
| 415 TEST_F(ElementsUploadDataStreamTest, InitAsyncFailureAsync) { | 415 TEST_F(ElementsUploadDataStreamTest, InitAsyncFailureAsync) { |
| 416 // Create UploadDataStream with a mock reader. | 416 // Create UploadDataStream with a mock reader. |
| 417 std::unique_ptr<MockUploadElementReader> reader( | 417 std::unique_ptr<MockUploadElementReader> reader( |
| 418 new MockUploadElementReader(kTestDataSize, false)); | 418 new MockUploadElementReader(kTestDataSize, false)); |
| 419 reader->SetAsyncInitExpectation(ERR_FAILED); | 419 reader->SetAsyncInitExpectation(ERR_FAILED); |
| 420 element_readers_.push_back(std::move(reader)); | 420 element_readers_.push_back(std::move(reader)); |
| 421 | 421 |
| 422 std::unique_ptr<UploadDataStream> stream( | 422 std::unique_ptr<UploadDataStream> stream( |
| 423 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 423 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 424 | 424 |
| 425 // Run Init(). | 425 // Run Init(). |
| 426 TestCompletionCallback callback; | 426 TestCompletionCallback callback; |
| 427 ASSERT_THAT(stream->Init(callback.callback(), BoundNetLog()), | 427 ASSERT_THAT(stream->Init(callback.callback(), NetLogWithSource()), |
| 428 IsError(ERR_IO_PENDING)); | 428 IsError(ERR_IO_PENDING)); |
| 429 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_FAILED)); | 429 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_FAILED)); |
| 430 } | 430 } |
| 431 | 431 |
| 432 // Init() of a reader fails synchronously. | 432 // Init() of a reader fails synchronously. |
| 433 TEST_F(ElementsUploadDataStreamTest, InitAsyncFailureSync) { | 433 TEST_F(ElementsUploadDataStreamTest, InitAsyncFailureSync) { |
| 434 // Create UploadDataStream with mock readers. | 434 // Create UploadDataStream with mock readers. |
| 435 std::unique_ptr<MockUploadElementReader> reader( | 435 std::unique_ptr<MockUploadElementReader> reader( |
| 436 new MockUploadElementReader(kTestDataSize, false)); | 436 new MockUploadElementReader(kTestDataSize, false)); |
| 437 reader->SetAsyncInitExpectation(OK); | 437 reader->SetAsyncInitExpectation(OK); |
| 438 element_readers_.push_back(std::move(reader)); | 438 element_readers_.push_back(std::move(reader)); |
| 439 | 439 |
| 440 std::unique_ptr<MockUploadElementReader> reader2( | 440 std::unique_ptr<MockUploadElementReader> reader2( |
| 441 new MockUploadElementReader(kTestDataSize, true)); | 441 new MockUploadElementReader(kTestDataSize, true)); |
| 442 EXPECT_CALL(*reader2, Init(_)).WillOnce(Return(ERR_FAILED)); | 442 EXPECT_CALL(*reader2, Init(_)).WillOnce(Return(ERR_FAILED)); |
| 443 element_readers_.push_back(std::move(reader2)); | 443 element_readers_.push_back(std::move(reader2)); |
| 444 | 444 |
| 445 std::unique_ptr<UploadDataStream> stream( | 445 std::unique_ptr<UploadDataStream> stream( |
| 446 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 446 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 447 | 447 |
| 448 // Run Init(). | 448 // Run Init(). |
| 449 TestCompletionCallback callback; | 449 TestCompletionCallback callback; |
| 450 ASSERT_THAT(stream->Init(callback.callback(), BoundNetLog()), | 450 ASSERT_THAT(stream->Init(callback.callback(), NetLogWithSource()), |
| 451 IsError(ERR_IO_PENDING)); | 451 IsError(ERR_IO_PENDING)); |
| 452 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_FAILED)); | 452 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_FAILED)); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // Read with a buffer whose size is same as the data. | 455 // Read with a buffer whose size is same as the data. |
| 456 TEST_F(ElementsUploadDataStreamTest, ReadAsyncWithExactSizeBuffer) { | 456 TEST_F(ElementsUploadDataStreamTest, ReadAsyncWithExactSizeBuffer) { |
| 457 element_readers_.push_back( | 457 element_readers_.push_back( |
| 458 base::WrapUnique(new UploadBytesElementReader(kTestData, kTestDataSize))); | 458 base::WrapUnique(new UploadBytesElementReader(kTestData, kTestDataSize))); |
| 459 std::unique_ptr<UploadDataStream> stream( | 459 std::unique_ptr<UploadDataStream> stream( |
| 460 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 460 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 461 | 461 |
| 462 ASSERT_THAT(stream->Init(CompletionCallback(), BoundNetLog()), IsOk()); | 462 ASSERT_THAT(stream->Init(CompletionCallback(), NetLogWithSource()), IsOk()); |
| 463 EXPECT_TRUE(stream->IsInMemory()); | 463 EXPECT_TRUE(stream->IsInMemory()); |
| 464 EXPECT_EQ(kTestDataSize, stream->size()); | 464 EXPECT_EQ(kTestDataSize, stream->size()); |
| 465 EXPECT_EQ(0U, stream->position()); | 465 EXPECT_EQ(0U, stream->position()); |
| 466 EXPECT_FALSE(stream->IsEOF()); | 466 EXPECT_FALSE(stream->IsEOF()); |
| 467 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestDataSize); | 467 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestDataSize); |
| 468 int bytes_read = stream->Read(buf.get(), kTestDataSize, CompletionCallback()); | 468 int bytes_read = stream->Read(buf.get(), kTestDataSize, CompletionCallback()); |
| 469 ASSERT_EQ(static_cast<int>(kTestDataSize), bytes_read); // Not an error. | 469 ASSERT_EQ(static_cast<int>(kTestDataSize), bytes_read); // Not an error. |
| 470 EXPECT_EQ(kTestDataSize, stream->position()); | 470 EXPECT_EQ(kTestDataSize, stream->position()); |
| 471 ASSERT_TRUE(stream->IsEOF()); | 471 ASSERT_TRUE(stream->IsEOF()); |
| 472 } | 472 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 496 new MockUploadElementReader(kTestDataSize, false)); | 496 new MockUploadElementReader(kTestDataSize, false)); |
| 497 reader4->SetAsyncInitExpectation(OK); | 497 reader4->SetAsyncInitExpectation(OK); |
| 498 reader4->SetReadExpectation(kTestDataSize); | 498 reader4->SetReadExpectation(kTestDataSize); |
| 499 element_readers_.push_back(std::move(reader4)); | 499 element_readers_.push_back(std::move(reader4)); |
| 500 | 500 |
| 501 std::unique_ptr<UploadDataStream> stream( | 501 std::unique_ptr<UploadDataStream> stream( |
| 502 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 502 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 503 | 503 |
| 504 // Run Init(). | 504 // Run Init(). |
| 505 TestCompletionCallback init_callback; | 505 TestCompletionCallback init_callback; |
| 506 EXPECT_THAT(stream->Init(init_callback.callback(), BoundNetLog()), | 506 EXPECT_THAT(stream->Init(init_callback.callback(), NetLogWithSource()), |
| 507 IsError(ERR_IO_PENDING)); | 507 IsError(ERR_IO_PENDING)); |
| 508 EXPECT_THAT(init_callback.WaitForResult(), IsOk()); | 508 EXPECT_THAT(init_callback.WaitForResult(), IsOk()); |
| 509 | 509 |
| 510 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); | 510 scoped_refptr<IOBuffer> buf = new IOBuffer(kTestBufferSize); |
| 511 | 511 |
| 512 // Consume the first element. | 512 // Consume the first element. |
| 513 TestCompletionCallback read_callback1; | 513 TestCompletionCallback read_callback1; |
| 514 EXPECT_EQ(static_cast<int>(kTestDataSize), | 514 EXPECT_EQ(static_cast<int>(kTestDataSize), |
| 515 stream->Read(buf.get(), kTestDataSize, read_callback1.callback())); | 515 stream->Read(buf.get(), kTestDataSize, read_callback1.callback())); |
| 516 base::RunLoop().RunUntilIdle(); | 516 base::RunLoop().RunUntilIdle(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 537 bool error_expected) { | 537 bool error_expected) { |
| 538 // Don't use element_readers_ here, as this function is called twice, and | 538 // Don't use element_readers_ here, as this function is called twice, and |
| 539 // reusing element_readers_ is wrong. | 539 // reusing element_readers_ is wrong. |
| 540 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 540 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 541 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( | 541 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
| 542 base::ThreadTaskRunnerHandle::Get().get(), file_path, 1, 2, time)); | 542 base::ThreadTaskRunnerHandle::Get().get(), file_path, 1, 2, time)); |
| 543 | 543 |
| 544 TestCompletionCallback init_callback; | 544 TestCompletionCallback init_callback; |
| 545 std::unique_ptr<UploadDataStream> stream( | 545 std::unique_ptr<UploadDataStream> stream( |
| 546 new ElementsUploadDataStream(std::move(element_readers), 0)); | 546 new ElementsUploadDataStream(std::move(element_readers), 0)); |
| 547 ASSERT_THAT(stream->Init(init_callback.callback(), BoundNetLog()), | 547 ASSERT_THAT(stream->Init(init_callback.callback(), NetLogWithSource()), |
| 548 IsError(ERR_IO_PENDING)); | 548 IsError(ERR_IO_PENDING)); |
| 549 int error_code = init_callback.WaitForResult(); | 549 int error_code = init_callback.WaitForResult(); |
| 550 if (error_expected) | 550 if (error_expected) |
| 551 ASSERT_THAT(error_code, IsError(ERR_UPLOAD_FILE_CHANGED)); | 551 ASSERT_THAT(error_code, IsError(ERR_UPLOAD_FILE_CHANGED)); |
| 552 else | 552 else |
| 553 ASSERT_THAT(error_code, IsOk()); | 553 ASSERT_THAT(error_code, IsOk()); |
| 554 } | 554 } |
| 555 | 555 |
| 556 TEST_F(ElementsUploadDataStreamTest, FileChanged) { | 556 TEST_F(ElementsUploadDataStreamTest, FileChanged) { |
| 557 base::FilePath temp_file_path; | 557 base::FilePath temp_file_path; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 586 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, | 586 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 587 std::numeric_limits<uint64_t>::max(), base::Time())); | 587 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 588 std::unique_ptr<UploadDataStream> stream( | 588 std::unique_ptr<UploadDataStream> stream( |
| 589 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 589 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 590 | 590 |
| 591 std::string expected_data(kTestData, kTestData + kTestDataSize); | 591 std::string expected_data(kTestData, kTestData + kTestDataSize); |
| 592 expected_data += expected_data; | 592 expected_data += expected_data; |
| 593 | 593 |
| 594 // Call Init(). | 594 // Call Init(). |
| 595 TestCompletionCallback init_callback1; | 595 TestCompletionCallback init_callback1; |
| 596 ASSERT_THAT(stream->Init(init_callback1.callback(), BoundNetLog()), | 596 ASSERT_THAT(stream->Init(init_callback1.callback(), NetLogWithSource()), |
| 597 IsError(ERR_IO_PENDING)); | 597 IsError(ERR_IO_PENDING)); |
| 598 ASSERT_THAT(init_callback1.WaitForResult(), IsOk()); | 598 ASSERT_THAT(init_callback1.WaitForResult(), IsOk()); |
| 599 EXPECT_FALSE(stream->IsEOF()); | 599 EXPECT_FALSE(stream->IsEOF()); |
| 600 EXPECT_EQ(kTestDataSize*2, stream->size()); | 600 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 601 | 601 |
| 602 // Read. | 602 // Read. |
| 603 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); | 603 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); |
| 604 EXPECT_TRUE(stream->IsEOF()); | 604 EXPECT_TRUE(stream->IsEOF()); |
| 605 | 605 |
| 606 // Call Init() again to reset. | 606 // Call Init() again to reset. |
| 607 TestCompletionCallback init_callback2; | 607 TestCompletionCallback init_callback2; |
| 608 ASSERT_THAT(stream->Init(init_callback2.callback(), BoundNetLog()), | 608 ASSERT_THAT(stream->Init(init_callback2.callback(), NetLogWithSource()), |
| 609 IsError(ERR_IO_PENDING)); | 609 IsError(ERR_IO_PENDING)); |
| 610 ASSERT_THAT(init_callback2.WaitForResult(), IsOk()); | 610 ASSERT_THAT(init_callback2.WaitForResult(), IsOk()); |
| 611 EXPECT_FALSE(stream->IsEOF()); | 611 EXPECT_FALSE(stream->IsEOF()); |
| 612 EXPECT_EQ(kTestDataSize*2, stream->size()); | 612 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 613 | 613 |
| 614 // Read again. | 614 // Read again. |
| 615 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); | 615 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); |
| 616 EXPECT_TRUE(stream->IsEOF()); | 616 EXPECT_TRUE(stream->IsEOF()); |
| 617 } | 617 } |
| 618 | 618 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 630 element_readers_.push_back(base::MakeUnique<UploadFileElementReader>( | 630 element_readers_.push_back(base::MakeUnique<UploadFileElementReader>( |
| 631 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, | 631 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 632 std::numeric_limits<uint64_t>::max(), base::Time())); | 632 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 633 std::unique_ptr<UploadDataStream> stream( | 633 std::unique_ptr<UploadDataStream> stream( |
| 634 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 634 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 635 | 635 |
| 636 std::string expected_data(kTestData, kTestData + kTestDataSize); | 636 std::string expected_data(kTestData, kTestData + kTestDataSize); |
| 637 expected_data += expected_data; | 637 expected_data += expected_data; |
| 638 | 638 |
| 639 // Call Init(). | 639 // Call Init(). |
| 640 ASSERT_THAT(stream->Init(test_callback.callback(), BoundNetLog()), | 640 ASSERT_THAT(stream->Init(test_callback.callback(), NetLogWithSource()), |
| 641 IsError(ERR_IO_PENDING)); | 641 IsError(ERR_IO_PENDING)); |
| 642 EXPECT_THAT(test_callback.WaitForResult(), IsOk()); | 642 EXPECT_THAT(test_callback.WaitForResult(), IsOk()); |
| 643 EXPECT_FALSE(stream->IsEOF()); | 643 EXPECT_FALSE(stream->IsEOF()); |
| 644 EXPECT_EQ(kTestDataSize*2, stream->size()); | 644 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 645 | 645 |
| 646 // Read. | 646 // Read. |
| 647 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); | 647 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); |
| 648 EXPECT_TRUE(stream->IsEOF()); | 648 EXPECT_TRUE(stream->IsEOF()); |
| 649 | 649 |
| 650 // Call Init() again to reset. | 650 // Call Init() again to reset. |
| 651 ASSERT_THAT(stream->Init(test_callback.callback(), BoundNetLog()), | 651 ASSERT_THAT(stream->Init(test_callback.callback(), NetLogWithSource()), |
| 652 IsError(ERR_IO_PENDING)); | 652 IsError(ERR_IO_PENDING)); |
| 653 EXPECT_THAT(test_callback.WaitForResult(), IsOk()); | 653 EXPECT_THAT(test_callback.WaitForResult(), IsOk()); |
| 654 EXPECT_FALSE(stream->IsEOF()); | 654 EXPECT_FALSE(stream->IsEOF()); |
| 655 EXPECT_EQ(kTestDataSize*2, stream->size()); | 655 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 656 | 656 |
| 657 // Read again. | 657 // Read again. |
| 658 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); | 658 EXPECT_EQ(expected_data, ReadFromUploadDataStream(stream.get())); |
| 659 EXPECT_TRUE(stream->IsEOF()); | 659 EXPECT_TRUE(stream->IsEOF()); |
| 660 } | 660 } |
| 661 | 661 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 674 std::numeric_limits<uint64_t>::max(), base::Time())); | 674 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 675 std::unique_ptr<UploadDataStream> stream( | 675 std::unique_ptr<UploadDataStream> stream( |
| 676 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 676 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 677 | 677 |
| 678 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); | 678 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); |
| 679 expected_data.insert(expected_data.end(), kTestData, | 679 expected_data.insert(expected_data.end(), kTestData, |
| 680 kTestData + kTestDataSize); | 680 kTestData + kTestDataSize); |
| 681 | 681 |
| 682 // Call Init(). | 682 // Call Init(). |
| 683 TestCompletionCallback init_callback1; | 683 TestCompletionCallback init_callback1; |
| 684 ASSERT_THAT(stream->Init(init_callback1.callback(), BoundNetLog()), | 684 ASSERT_THAT(stream->Init(init_callback1.callback(), NetLogWithSource()), |
| 685 IsError(ERR_IO_PENDING)); | 685 IsError(ERR_IO_PENDING)); |
| 686 EXPECT_THAT(init_callback1.WaitForResult(), IsOk()); | 686 EXPECT_THAT(init_callback1.WaitForResult(), IsOk()); |
| 687 EXPECT_FALSE(stream->IsEOF()); | 687 EXPECT_FALSE(stream->IsEOF()); |
| 688 EXPECT_EQ(kTestDataSize*2, stream->size()); | 688 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 689 | 689 |
| 690 // Read some. | 690 // Read some. |
| 691 TestCompletionCallback read_callback1; | 691 TestCompletionCallback read_callback1; |
| 692 std::vector<char> buf(kTestDataSize + kTestDataSize/2); | 692 std::vector<char> buf(kTestDataSize + kTestDataSize/2); |
| 693 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); | 693 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); |
| 694 EXPECT_EQ( | 694 EXPECT_EQ( |
| 695 ERR_IO_PENDING, | 695 ERR_IO_PENDING, |
| 696 stream->Read(wrapped_buffer.get(), buf.size(), | 696 stream->Read(wrapped_buffer.get(), buf.size(), |
| 697 read_callback1.callback())); | 697 read_callback1.callback())); |
| 698 EXPECT_EQ(static_cast<int>(buf.size()), read_callback1.WaitForResult()); | 698 EXPECT_EQ(static_cast<int>(buf.size()), read_callback1.WaitForResult()); |
| 699 EXPECT_EQ(buf.size(), stream->position()); | 699 EXPECT_EQ(buf.size(), stream->position()); |
| 700 | 700 |
| 701 // Call Init to reset the state. | 701 // Call Init to reset the state. |
| 702 TestCompletionCallback init_callback2; | 702 TestCompletionCallback init_callback2; |
| 703 ASSERT_THAT(stream->Init(init_callback2.callback(), BoundNetLog()), | 703 ASSERT_THAT(stream->Init(init_callback2.callback(), NetLogWithSource()), |
| 704 IsError(ERR_IO_PENDING)); | 704 IsError(ERR_IO_PENDING)); |
| 705 EXPECT_THAT(init_callback2.WaitForResult(), IsOk()); | 705 EXPECT_THAT(init_callback2.WaitForResult(), IsOk()); |
| 706 EXPECT_FALSE(stream->IsEOF()); | 706 EXPECT_FALSE(stream->IsEOF()); |
| 707 EXPECT_EQ(kTestDataSize*2, stream->size()); | 707 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 708 | 708 |
| 709 // Read. | 709 // Read. |
| 710 TestCompletionCallback read_callback2; | 710 TestCompletionCallback read_callback2; |
| 711 std::vector<char> buf2(kTestDataSize*2); | 711 std::vector<char> buf2(kTestDataSize*2); |
| 712 scoped_refptr<IOBuffer> wrapped_buffer2 = new WrappedIOBuffer(&buf2[0]); | 712 scoped_refptr<IOBuffer> wrapped_buffer2 = new WrappedIOBuffer(&buf2[0]); |
| 713 EXPECT_EQ(ERR_IO_PENDING, | 713 EXPECT_EQ(ERR_IO_PENDING, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 732 std::numeric_limits<uint64_t>::max(), base::Time())); | 732 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 733 std::unique_ptr<UploadDataStream> stream( | 733 std::unique_ptr<UploadDataStream> stream( |
| 734 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 734 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 735 | 735 |
| 736 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); | 736 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); |
| 737 expected_data.insert(expected_data.end(), kTestData, | 737 expected_data.insert(expected_data.end(), kTestData, |
| 738 kTestData + kTestDataSize); | 738 kTestData + kTestDataSize); |
| 739 | 739 |
| 740 // Start Init. | 740 // Start Init. |
| 741 TestCompletionCallback init_callback1; | 741 TestCompletionCallback init_callback1; |
| 742 EXPECT_THAT(stream->Init(init_callback1.callback(), BoundNetLog()), | 742 EXPECT_THAT(stream->Init(init_callback1.callback(), NetLogWithSource()), |
| 743 IsError(ERR_IO_PENDING)); | 743 IsError(ERR_IO_PENDING)); |
| 744 | 744 |
| 745 // Call Init again to cancel the previous init. | 745 // Call Init again to cancel the previous init. |
| 746 TestCompletionCallback init_callback2; | 746 TestCompletionCallback init_callback2; |
| 747 EXPECT_THAT(stream->Init(init_callback2.callback(), BoundNetLog()), | 747 EXPECT_THAT(stream->Init(init_callback2.callback(), NetLogWithSource()), |
| 748 IsError(ERR_IO_PENDING)); | 748 IsError(ERR_IO_PENDING)); |
| 749 EXPECT_THAT(init_callback2.WaitForResult(), IsOk()); | 749 EXPECT_THAT(init_callback2.WaitForResult(), IsOk()); |
| 750 EXPECT_FALSE(stream->IsEOF()); | 750 EXPECT_FALSE(stream->IsEOF()); |
| 751 EXPECT_EQ(kTestDataSize*2, stream->size()); | 751 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 752 | 752 |
| 753 // Read. | 753 // Read. |
| 754 TestCompletionCallback read_callback2; | 754 TestCompletionCallback read_callback2; |
| 755 std::vector<char> buf2(kTestDataSize*2); | 755 std::vector<char> buf2(kTestDataSize*2); |
| 756 scoped_refptr<IOBuffer> wrapped_buffer2 = new WrappedIOBuffer(&buf2[0]); | 756 scoped_refptr<IOBuffer> wrapped_buffer2 = new WrappedIOBuffer(&buf2[0]); |
| 757 EXPECT_EQ(ERR_IO_PENDING, | 757 EXPECT_EQ(ERR_IO_PENDING, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 780 std::numeric_limits<uint64_t>::max(), base::Time())); | 780 std::numeric_limits<uint64_t>::max(), base::Time())); |
| 781 std::unique_ptr<UploadDataStream> stream( | 781 std::unique_ptr<UploadDataStream> stream( |
| 782 new ElementsUploadDataStream(std::move(element_readers_), 0)); | 782 new ElementsUploadDataStream(std::move(element_readers_), 0)); |
| 783 | 783 |
| 784 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); | 784 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); |
| 785 expected_data.insert(expected_data.end(), kTestData, | 785 expected_data.insert(expected_data.end(), kTestData, |
| 786 kTestData + kTestDataSize); | 786 kTestData + kTestDataSize); |
| 787 | 787 |
| 788 // Call Init(). | 788 // Call Init(). |
| 789 TestCompletionCallback init_callback1; | 789 TestCompletionCallback init_callback1; |
| 790 ASSERT_THAT(stream->Init(init_callback1.callback(), BoundNetLog()), | 790 ASSERT_THAT(stream->Init(init_callback1.callback(), NetLogWithSource()), |
| 791 IsError(ERR_IO_PENDING)); | 791 IsError(ERR_IO_PENDING)); |
| 792 EXPECT_THAT(init_callback1.WaitForResult(), IsOk()); | 792 EXPECT_THAT(init_callback1.WaitForResult(), IsOk()); |
| 793 EXPECT_FALSE(stream->IsEOF()); | 793 EXPECT_FALSE(stream->IsEOF()); |
| 794 EXPECT_EQ(kTestDataSize*2, stream->size()); | 794 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 795 | 795 |
| 796 // Start reading. | 796 // Start reading. |
| 797 TestCompletionCallback read_callback1; | 797 TestCompletionCallback read_callback1; |
| 798 std::vector<char> buf(kTestDataSize*2); | 798 std::vector<char> buf(kTestDataSize*2); |
| 799 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); | 799 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); |
| 800 EXPECT_EQ( | 800 EXPECT_EQ( |
| 801 ERR_IO_PENDING, | 801 ERR_IO_PENDING, |
| 802 stream->Read(wrapped_buffer.get(), buf.size(), | 802 stream->Read(wrapped_buffer.get(), buf.size(), |
| 803 read_callback1.callback())); | 803 read_callback1.callback())); |
| 804 | 804 |
| 805 // Call Init to cancel the previous read. | 805 // Call Init to cancel the previous read. |
| 806 TestCompletionCallback init_callback2; | 806 TestCompletionCallback init_callback2; |
| 807 EXPECT_THAT(stream->Init(init_callback2.callback(), BoundNetLog()), | 807 EXPECT_THAT(stream->Init(init_callback2.callback(), NetLogWithSource()), |
| 808 IsError(ERR_IO_PENDING)); | 808 IsError(ERR_IO_PENDING)); |
| 809 EXPECT_THAT(init_callback2.WaitForResult(), IsOk()); | 809 EXPECT_THAT(init_callback2.WaitForResult(), IsOk()); |
| 810 EXPECT_FALSE(stream->IsEOF()); | 810 EXPECT_FALSE(stream->IsEOF()); |
| 811 EXPECT_EQ(kTestDataSize*2, stream->size()); | 811 EXPECT_EQ(kTestDataSize*2, stream->size()); |
| 812 | 812 |
| 813 // Read. | 813 // Read. |
| 814 TestCompletionCallback read_callback2; | 814 TestCompletionCallback read_callback2; |
| 815 std::vector<char> buf2(kTestDataSize*2); | 815 std::vector<char> buf2(kTestDataSize*2); |
| 816 scoped_refptr<IOBuffer> wrapped_buffer2 = new WrappedIOBuffer(&buf2[0]); | 816 scoped_refptr<IOBuffer> wrapped_buffer2 = new WrappedIOBuffer(&buf2[0]); |
| 817 EXPECT_EQ(ERR_IO_PENDING, | 817 EXPECT_EQ(ERR_IO_PENDING, |
| 818 stream->Read( | 818 stream->Read( |
| 819 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); | 819 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); |
| 820 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); | 820 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); |
| 821 EXPECT_EQ(expected_data, buf2); | 821 EXPECT_EQ(expected_data, buf2); |
| 822 EXPECT_TRUE(stream->IsEOF()); | 822 EXPECT_TRUE(stream->IsEOF()); |
| 823 | 823 |
| 824 // Make sure callbacks are not called for cancelled operations. | 824 // Make sure callbacks are not called for cancelled operations. |
| 825 EXPECT_FALSE(read_callback1.have_result()); | 825 EXPECT_FALSE(read_callback1.have_result()); |
| 826 } | 826 } |
| 827 | 827 |
| 828 } // namespace net | 828 } // namespace net |
| OLD | NEW |