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/upload_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 167 } |
168 EXPECT_EQ(kTestDataSize, stream.position()); | 168 EXPECT_EQ(kTestDataSize, stream.position()); |
169 ASSERT_TRUE(stream.IsEOF()); | 169 ASSERT_TRUE(stream.IsEOF()); |
170 } | 170 } |
171 | 171 |
172 TEST_F(UploadDataStreamTest, File) { | 172 TEST_F(UploadDataStreamTest, File) { |
173 base::FilePath temp_file_path; | 173 base::FilePath temp_file_path; |
174 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 174 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
175 &temp_file_path)); | 175 &temp_file_path)); |
176 ASSERT_EQ(static_cast<int>(kTestDataSize), | 176 ASSERT_EQ(static_cast<int>(kTestDataSize), |
177 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 177 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
178 | 178 |
179 element_readers_.push_back( | 179 element_readers_.push_back( |
180 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 180 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
181 temp_file_path, | 181 temp_file_path, |
182 0, | 182 0, |
183 kuint64max, | 183 kuint64max, |
184 base::Time())); | 184 base::Time())); |
185 | 185 |
186 TestCompletionCallback init_callback; | 186 TestCompletionCallback init_callback; |
187 UploadDataStream stream(element_readers_.Pass(), 0); | 187 UploadDataStream stream(element_readers_.Pass(), 0); |
(...skipping 13 matching lines...) Expand all Loading... |
201 } | 201 } |
202 EXPECT_EQ(kTestDataSize, stream.position()); | 202 EXPECT_EQ(kTestDataSize, stream.position()); |
203 ASSERT_TRUE(stream.IsEOF()); | 203 ASSERT_TRUE(stream.IsEOF()); |
204 } | 204 } |
205 | 205 |
206 TEST_F(UploadDataStreamTest, FileSmallerThanLength) { | 206 TEST_F(UploadDataStreamTest, FileSmallerThanLength) { |
207 base::FilePath temp_file_path; | 207 base::FilePath temp_file_path; |
208 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 208 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
209 &temp_file_path)); | 209 &temp_file_path)); |
210 ASSERT_EQ(static_cast<int>(kTestDataSize), | 210 ASSERT_EQ(static_cast<int>(kTestDataSize), |
211 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 211 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
212 const uint64 kFakeSize = kTestDataSize*2; | 212 const uint64 kFakeSize = kTestDataSize*2; |
213 | 213 |
214 UploadFileElementReader::ScopedOverridingContentLengthForTests | 214 UploadFileElementReader::ScopedOverridingContentLengthForTests |
215 overriding_content_length(kFakeSize); | 215 overriding_content_length(kFakeSize); |
216 | 216 |
217 element_readers_.push_back( | 217 element_readers_.push_back( |
218 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 218 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
219 temp_file_path, | 219 temp_file_path, |
220 0, | 220 0, |
221 kuint64max, | 221 kuint64max, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 // The buffer is filled with zero. | 319 // The buffer is filled with zero. |
320 EXPECT_EQ(static_cast<int>(kTestDataSize*2), | 320 EXPECT_EQ(static_cast<int>(kTestDataSize*2), |
321 std::count(buf->data(), buf->data() + kTestBufferSize, 0)); | 321 std::count(buf->data(), buf->data() + kTestBufferSize, 0)); |
322 } | 322 } |
323 | 323 |
324 TEST_F(UploadDataStreamTest, FileAndBytes) { | 324 TEST_F(UploadDataStreamTest, FileAndBytes) { |
325 base::FilePath temp_file_path; | 325 base::FilePath temp_file_path; |
326 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 326 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
327 &temp_file_path)); | 327 &temp_file_path)); |
328 ASSERT_EQ(static_cast<int>(kTestDataSize), | 328 ASSERT_EQ(static_cast<int>(kTestDataSize), |
329 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 329 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
330 | 330 |
331 const uint64 kFileRangeOffset = 1; | 331 const uint64 kFileRangeOffset = 1; |
332 const uint64 kFileRangeLength = 4; | 332 const uint64 kFileRangeLength = 4; |
333 element_readers_.push_back( | 333 element_readers_.push_back( |
334 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 334 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
335 temp_file_path, | 335 temp_file_path, |
336 kFileRangeOffset, | 336 kFileRangeOffset, |
337 kFileRangeLength, | 337 kFileRangeLength, |
338 base::Time())); | 338 base::Time())); |
339 | 339 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 ASSERT_EQ(ERR_UPLOAD_FILE_CHANGED, error_code); | 545 ASSERT_EQ(ERR_UPLOAD_FILE_CHANGED, error_code); |
546 else | 546 else |
547 ASSERT_EQ(OK, error_code); | 547 ASSERT_EQ(OK, error_code); |
548 } | 548 } |
549 | 549 |
550 TEST_F(UploadDataStreamTest, FileChanged) { | 550 TEST_F(UploadDataStreamTest, FileChanged) { |
551 base::FilePath temp_file_path; | 551 base::FilePath temp_file_path; |
552 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 552 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
553 &temp_file_path)); | 553 &temp_file_path)); |
554 ASSERT_EQ(static_cast<int>(kTestDataSize), | 554 ASSERT_EQ(static_cast<int>(kTestDataSize), |
555 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 555 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
556 | 556 |
557 base::File::Info file_info; | 557 base::File::Info file_info; |
558 ASSERT_TRUE(base::GetFileInfo(temp_file_path, &file_info)); | 558 ASSERT_TRUE(base::GetFileInfo(temp_file_path, &file_info)); |
559 | 559 |
560 // Test file not changed. | 560 // Test file not changed. |
561 FileChangedHelper(temp_file_path, file_info.last_modified, false); | 561 FileChangedHelper(temp_file_path, file_info.last_modified, false); |
562 | 562 |
563 // Test file changed. | 563 // Test file changed. |
564 FileChangedHelper(temp_file_path, | 564 FileChangedHelper(temp_file_path, |
565 file_info.last_modified - base::TimeDelta::FromSeconds(1), | 565 file_info.last_modified - base::TimeDelta::FromSeconds(1), |
566 true); | 566 true); |
567 } | 567 } |
568 | 568 |
569 TEST_F(UploadDataStreamTest, MultipleInit) { | 569 TEST_F(UploadDataStreamTest, MultipleInit) { |
570 base::FilePath temp_file_path; | 570 base::FilePath temp_file_path; |
571 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 571 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
572 &temp_file_path)); | 572 &temp_file_path)); |
573 ASSERT_EQ(static_cast<int>(kTestDataSize), | 573 ASSERT_EQ(static_cast<int>(kTestDataSize), |
574 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 574 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
575 | 575 |
576 // Prepare data. | 576 // Prepare data. |
577 element_readers_.push_back(new UploadBytesElementReader( | 577 element_readers_.push_back(new UploadBytesElementReader( |
578 kTestData, kTestDataSize)); | 578 kTestData, kTestDataSize)); |
579 element_readers_.push_back( | 579 element_readers_.push_back( |
580 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 580 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
581 temp_file_path, | 581 temp_file_path, |
582 0, | 582 0, |
583 kuint64max, | 583 kuint64max, |
584 base::Time())); | 584 base::Time())); |
(...skipping 23 matching lines...) Expand all Loading... |
608 // Read again. | 608 // Read again. |
609 EXPECT_EQ(expected_data, ReadFromUploadDataStream(&stream)); | 609 EXPECT_EQ(expected_data, ReadFromUploadDataStream(&stream)); |
610 EXPECT_TRUE(stream.IsEOF()); | 610 EXPECT_TRUE(stream.IsEOF()); |
611 } | 611 } |
612 | 612 |
613 TEST_F(UploadDataStreamTest, MultipleInitAsync) { | 613 TEST_F(UploadDataStreamTest, MultipleInitAsync) { |
614 base::FilePath temp_file_path; | 614 base::FilePath temp_file_path; |
615 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 615 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
616 &temp_file_path)); | 616 &temp_file_path)); |
617 ASSERT_EQ(static_cast<int>(kTestDataSize), | 617 ASSERT_EQ(static_cast<int>(kTestDataSize), |
618 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 618 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
619 TestCompletionCallback test_callback; | 619 TestCompletionCallback test_callback; |
620 | 620 |
621 // Prepare data. | 621 // Prepare data. |
622 element_readers_.push_back(new UploadBytesElementReader( | 622 element_readers_.push_back(new UploadBytesElementReader( |
623 kTestData, kTestDataSize)); | 623 kTestData, kTestDataSize)); |
624 element_readers_.push_back( | 624 element_readers_.push_back( |
625 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 625 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
626 temp_file_path, | 626 temp_file_path, |
627 0, | 627 0, |
628 kuint64max, | 628 kuint64max, |
(...skipping 22 matching lines...) Expand all Loading... |
651 // Read again. | 651 // Read again. |
652 EXPECT_EQ(expected_data, ReadFromUploadDataStream(&stream)); | 652 EXPECT_EQ(expected_data, ReadFromUploadDataStream(&stream)); |
653 EXPECT_TRUE(stream.IsEOF()); | 653 EXPECT_TRUE(stream.IsEOF()); |
654 } | 654 } |
655 | 655 |
656 TEST_F(UploadDataStreamTest, InitToReset) { | 656 TEST_F(UploadDataStreamTest, InitToReset) { |
657 base::FilePath temp_file_path; | 657 base::FilePath temp_file_path; |
658 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 658 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
659 &temp_file_path)); | 659 &temp_file_path)); |
660 ASSERT_EQ(static_cast<int>(kTestDataSize), | 660 ASSERT_EQ(static_cast<int>(kTestDataSize), |
661 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 661 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
662 | 662 |
663 // Prepare data. | 663 // Prepare data. |
664 element_readers_.push_back(new UploadBytesElementReader( | 664 element_readers_.push_back(new UploadBytesElementReader( |
665 kTestData, kTestDataSize)); | 665 kTestData, kTestDataSize)); |
666 element_readers_.push_back( | 666 element_readers_.push_back( |
667 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 667 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
668 temp_file_path, | 668 temp_file_path, |
669 0, | 669 0, |
670 kuint64max, | 670 kuint64max, |
671 base::Time())); | 671 base::Time())); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); | 708 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); |
709 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); | 709 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); |
710 EXPECT_EQ(expected_data, buf2); | 710 EXPECT_EQ(expected_data, buf2); |
711 } | 711 } |
712 | 712 |
713 TEST_F(UploadDataStreamTest, InitDuringAsyncInit) { | 713 TEST_F(UploadDataStreamTest, InitDuringAsyncInit) { |
714 base::FilePath temp_file_path; | 714 base::FilePath temp_file_path; |
715 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 715 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
716 &temp_file_path)); | 716 &temp_file_path)); |
717 ASSERT_EQ(static_cast<int>(kTestDataSize), | 717 ASSERT_EQ(static_cast<int>(kTestDataSize), |
718 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 718 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
719 | 719 |
720 // Prepare data. | 720 // Prepare data. |
721 element_readers_.push_back(new UploadBytesElementReader( | 721 element_readers_.push_back(new UploadBytesElementReader( |
722 kTestData, kTestDataSize)); | 722 kTestData, kTestDataSize)); |
723 element_readers_.push_back( | 723 element_readers_.push_back( |
724 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 724 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
725 temp_file_path, | 725 temp_file_path, |
726 0, | 726 0, |
727 kuint64max, | 727 kuint64max, |
728 base::Time())); | 728 base::Time())); |
(...skipping 27 matching lines...) Expand all Loading... |
756 | 756 |
757 // Make sure callbacks are not called for cancelled operations. | 757 // Make sure callbacks are not called for cancelled operations. |
758 EXPECT_FALSE(init_callback1.have_result()); | 758 EXPECT_FALSE(init_callback1.have_result()); |
759 } | 759 } |
760 | 760 |
761 TEST_F(UploadDataStreamTest, InitDuringAsyncRead) { | 761 TEST_F(UploadDataStreamTest, InitDuringAsyncRead) { |
762 base::FilePath temp_file_path; | 762 base::FilePath temp_file_path; |
763 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 763 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
764 &temp_file_path)); | 764 &temp_file_path)); |
765 ASSERT_EQ(static_cast<int>(kTestDataSize), | 765 ASSERT_EQ(static_cast<int>(kTestDataSize), |
766 file_util::WriteFile(temp_file_path, kTestData, kTestDataSize)); | 766 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); |
767 | 767 |
768 // Prepare data. | 768 // Prepare data. |
769 element_readers_.push_back(new UploadBytesElementReader( | 769 element_readers_.push_back(new UploadBytesElementReader( |
770 kTestData, kTestDataSize)); | 770 kTestData, kTestDataSize)); |
771 element_readers_.push_back( | 771 element_readers_.push_back( |
772 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 772 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
773 temp_file_path, | 773 temp_file_path, |
774 0, | 774 0, |
775 kuint64max, | 775 kuint64max, |
776 base::Time())); | 776 base::Time())); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); | 811 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); |
812 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); | 812 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); |
813 EXPECT_EQ(expected_data, buf2); | 813 EXPECT_EQ(expected_data, buf2); |
814 EXPECT_TRUE(stream.IsEOF()); | 814 EXPECT_TRUE(stream.IsEOF()); |
815 | 815 |
816 // Make sure callbacks are not called for cancelled operations. | 816 // Make sure callbacks are not called for cancelled operations. |
817 EXPECT_FALSE(read_callback1.have_result()); | 817 EXPECT_FALSE(read_callback1.have_result()); |
818 } | 818 } |
819 | 819 |
820 } // namespace net | 820 } // namespace net |
OLD | NEW |