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

Side by Side Diff: content/browser/download/download_file_unittest.cc

Issue 2738063002: Verify that all slice are downloaded when a stream complete (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « content/browser/download/download_file_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 TEST_F(DownloadFileTest, MutipleStreamsLimitedLength) { 974 TEST_F(DownloadFileTest, MutipleStreamsLimitedLength) {
975 // The second stream has two buffers, kTestData4 and kTestData5. 975 // The second stream has two buffers, kTestData4 and kTestData5.
976 // The length limit is set to less than the length of kTestData4. 976 // The length limit is set to less than the length of kTestData4.
977 // kTestData4 should be partially written to disk, where kTestData5 should be 977 // kTestData4 should be partially written to disk, where kTestData5 should be
978 // ignored. 978 // ignored.
979 int64_t stream_0_length = 979 int64_t stream_0_length =
980 static_cast<int64_t>(strlen(kTestData1) + strlen(kTestData2)); 980 static_cast<int64_t>(strlen(kTestData1) + strlen(kTestData2));
981 int64_t stream_1_length = static_cast<int64_t>(strlen(kTestData4)) - 1; 981 int64_t stream_1_length = static_cast<int64_t>(strlen(kTestData4)) - 1;
982 PrepareMultipleStreams(false, stream_1_length); 982 PrepareMultipleStreams(false, stream_1_length);
983 983
984 EXPECT_CALL(*(observer_.get()), MockDestinationCompleted(_, _));
985
986 download_file_->AddByteStream( 984 download_file_->AddByteStream(
987 std::unique_ptr<MockByteStreamReader>(input_stream_1_), stream_0_length); 985 std::unique_ptr<MockByteStreamReader>(input_stream_1_), stream_0_length);
988 sink_callback_.Run(); 986 sink_callback_.Run();
989 base::RunLoop().RunUntilIdle(); 987 base::RunLoop().RunUntilIdle();
990 988
991 SourceStreamTestData stream_data_0(0, stream_0_length, true); 989 SourceStreamTestData stream_data_0(0, stream_0_length, true);
992 SourceStreamTestData stream_data_1(stream_0_length, stream_1_length, true); 990 SourceStreamTestData stream_data_1(stream_0_length, stream_1_length, true);
993 VerifySourceStreamsStates(stream_data_0); 991 VerifySourceStreamsStates(stream_data_0);
994 VerifySourceStreamsStates(stream_data_1); 992 VerifySourceStreamsStates(stream_data_1);
995 EXPECT_EQ(stream_0_length + stream_1_length, TotalBytesReceived()); 993 EXPECT_EQ(stream_0_length + stream_1_length, TotalBytesReceived());
996 994
997 std::string disk_data, expected_data; 995 std::string disk_data, expected_data;
998 EXPECT_TRUE(base::ReadFileToString(download_file_->FullPath(), &disk_data)); 996 EXPECT_TRUE(base::ReadFileToString(download_file_->FullPath(), &disk_data));
999 expected_data.append(kTestData1).append(kTestData2).append(kTestData4); 997 expected_data.append(kTestData1).append(kTestData2).append(kTestData4);
1000 expected_data = expected_data.substr(0, stream_0_length + stream_1_length); 998 expected_data = expected_data.substr(0, stream_0_length + stream_1_length);
1001 EXPECT_EQ(expected_data, disk_data); 999 EXPECT_EQ(expected_data, disk_data);
1002 1000
1003 // Finish the second stream. 1001 // Finish the second stream.
1004 // TODO(xingliu): Refactor test code to deal with unfinished streams. 1002 // TODO(xingliu): Refactor test code to deal with unfinished streams.
1005 scoped_refptr<net::IOBuffer> data = new net::IOBuffer(strlen(kTestData5)); 1003 scoped_refptr<net::IOBuffer> data = new net::IOBuffer(strlen(kTestData5));
1006 size_t size; 1004 size_t size;
1007 input_stream_1_->Read(&data, &size); 1005 input_stream_1_->Read(&data, &size);
1008 1006
1007 download_file_->Cancel();
1009 DestroyDownloadFile(0, false); 1008 DestroyDownloadFile(0, false);
1010 } 1009 }
1011 1010
1012 } // namespace content 1011 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_file_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698