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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 VerifySourceStreamsStates(stream_data_1); | 982 VerifySourceStreamsStates(stream_data_1); |
983 VerifySourceStreamsStates(stream_data_2); | 983 VerifySourceStreamsStates(stream_data_2); |
984 | 984 |
985 EXPECT_EQ(stream_0_length + stream_1_length + stream_2_length, | 985 EXPECT_EQ(stream_0_length + stream_1_length + stream_2_length, |
986 TotalBytesReceived()); | 986 TotalBytesReceived()); |
987 | 987 |
988 download_file_->Cancel(); | 988 download_file_->Cancel(); |
989 DestroyDownloadFile(0, false); | 989 DestroyDownloadFile(0, false); |
990 } | 990 } |
991 | 991 |
992 // Activate and deplete one stream, later add the second stream. | 992 // Activate and deplete one stream, later add the second stream. |
993 TEST_F(DownloadFileTest, MutipleStreamsFirstStreamWriteAllData) { | 993 TEST_F(DownloadFileTest, MutipleStreamsFirstStreamWriteAllData) { |
994 int64_t stream_0_length = GetBuffersLength(kTestData8, 4); | 994 int64_t stream_0_length = GetBuffersLength(kTestData8, 4); |
995 | 995 |
996 ASSERT_TRUE(CreateDownloadFile(0, DownloadSaveInfo::kLengthFullContent, true, | 996 ASSERT_TRUE(CreateDownloadFile(0, DownloadSaveInfo::kLengthFullContent, true, |
997 DownloadItem::ReceivedSlices())); | 997 DownloadItem::ReceivedSlices())); |
998 | 998 |
999 PrepareStream(&input_stream_, 0, false, true, kTestData8, 4); | 999 PrepareStream(&input_stream_, 0, false, true, kTestData8, 4); |
1000 | 1000 |
1001 EXPECT_CALL(*(observer_.get()), MockDestinationCompleted(_, _)); | 1001 EXPECT_CALL(*(observer_.get()), MockDestinationCompleted(_, _)); |
1002 | 1002 |
(...skipping 12 matching lines...) Expand all Loading... |
1015 | 1015 |
1016 SourceStreamTestData stream_data_0(0, stream_0_length, true); | 1016 SourceStreamTestData stream_data_0(0, stream_0_length, true); |
1017 SourceStreamTestData stream_data_1(stream_0_length - 1, 0, false); | 1017 SourceStreamTestData stream_data_1(stream_0_length - 1, 0, false); |
1018 VerifySourceStreamsStates(stream_data_0); | 1018 VerifySourceStreamsStates(stream_data_0); |
1019 VerifySourceStreamsStates(stream_data_1); | 1019 VerifySourceStreamsStates(stream_data_1); |
1020 EXPECT_EQ(stream_0_length, TotalBytesReceived()); | 1020 EXPECT_EQ(stream_0_length, TotalBytesReceived()); |
1021 | 1021 |
1022 DestroyDownloadFile(0); | 1022 DestroyDownloadFile(0); |
1023 } | 1023 } |
1024 | 1024 |
| 1025 // While one stream is writing, kick off another stream with an offset that has |
| 1026 // been written by the first one. |
| 1027 TEST_F(DownloadFileTest, SecondStreamStartingOffsetAlreadyWritten) { |
| 1028 int64_t stream_0_length = GetBuffersLength(kTestData6, 2); |
| 1029 |
| 1030 ASSERT_TRUE(CreateDownloadFile(0, stream_0_length, true, |
| 1031 DownloadItem::ReceivedSlices())); |
| 1032 |
| 1033 Sequence seq; |
| 1034 SetupDataAppend(kTestData6, 2, input_stream_, seq, 0); |
| 1035 |
| 1036 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 1037 .InSequence(seq) |
| 1038 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| 1039 .RetiresOnSaturation(); |
| 1040 sink_callback_.Run(); |
| 1041 base::RunLoop().RunUntilIdle(); |
| 1042 |
| 1043 additional_streams_[0] = new StrictMock<MockByteStreamReader>(); |
| 1044 EXPECT_CALL(*additional_streams_[0], RegisterCallback(_)) |
| 1045 .WillRepeatedly(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 1046 .RetiresOnSaturation(); |
| 1047 EXPECT_CALL(*additional_streams_[0], Read(_, _)) |
| 1048 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| 1049 .RetiresOnSaturation(); |
| 1050 |
| 1051 download_file_->AddByteStream( |
| 1052 std::unique_ptr<MockByteStreamReader>(additional_streams_[0]), 0, |
| 1053 DownloadSaveInfo::kLengthFullContent); |
| 1054 |
| 1055 // The stream should get terminated and reset the callback. |
| 1056 EXPECT_TRUE(sink_callback_.is_null()); |
| 1057 download_file_->Cancel(); |
| 1058 DestroyDownloadFile(0, false); |
| 1059 } |
| 1060 |
1025 } // namespace content | 1061 } // namespace content |
OLD | NEW |