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

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

Issue 10392111: Use ByteStream in downloads system to decouple source and sink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR. Created 8 years, 7 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 | Annotate | Revision Log
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/download/byte_stream.h"
9 #include "content/browser/download/download_create_info.h" 10 #include "content/browser/download/download_create_info.h"
10 #include "content/browser/download/download_file_impl.h" 11 #include "content/browser/download/download_file_impl.h"
11 #include "content/browser/download/download_request_handle.h" 12 #include "content/browser/download/download_request_handle.h"
12 #include "content/browser/power_save_blocker.h" 13 #include "content/browser/power_save_blocker.h"
14 #include "content/public/browser/download_interrupt_reasons.h"
13 #include "content/public/browser/download_manager.h" 15 #include "content/public/browser/download_manager.h"
14 #include "content/test/mock_download_manager.h" 16 #include "content/test/mock_download_manager.h"
15 #include "net/base/file_stream.h" 17 #include "net/base/file_stream.h"
16 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 21
19 using content::BrowserThread; 22 using content::BrowserThread;
20 using content::BrowserThreadImpl; 23 using content::BrowserThreadImpl;
21 using content::DownloadFile; 24 using content::DownloadFile;
22 using content::DownloadId; 25 using content::DownloadId;
23 using content::DownloadManager; 26 using content::DownloadManager;
24 using testing::_; 27 using ::testing::_;
25 using testing::AnyNumber; 28 using ::testing::AnyNumber;
26 using testing::StrictMock; 29 using ::testing::DoAll;
30 using ::testing::Return;
31 using ::testing::SetArgPointee;
32 using ::testing::StrictMock;
33
34 namespace {
35
36 class MockByteStreamOutput : public content::ByteStreamOutput {
37 public:
38 MockByteStreamOutput() {}
39 ~MockByteStreamOutput() {}
40
41 // ByteStream functions
42 MOCK_METHOD2(Read, content::ByteStreamOutput::StreamState(
43 scoped_refptr<net::IOBuffer>*, size_t*));
44 MOCK_CONST_METHOD0(GetStatus, content::DownloadInterruptReason());
45 MOCK_METHOD1(RegisterCallback, void(const base::Closure&));
46 };
47
48 } // namespace
27 49
28 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; 50 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain";
29 51
30 class DownloadFileTest : public testing::Test { 52 class DownloadFileTest : public testing::Test {
31 public: 53 public:
32 54
33 static const char* kTestData1; 55 static const char* kTestData1;
34 static const char* kTestData2; 56 static const char* kTestData2;
35 static const char* kTestData3; 57 static const char* kTestData3;
36 static const char* kDataHash; 58 static const char* kDataHash;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 virtual void TearDown() { 92 virtual void TearDown() {
71 // When a DownloadManager's reference count drops to 0, it is not 93 // When a DownloadManager's reference count drops to 0, it is not
72 // deleted immediately. Instead, a task is posted to the UI thread's 94 // deleted immediately. Instead, a task is posted to the UI thread's
73 // message loop to delete it. 95 // message loop to delete it.
74 // So, drop the reference count to 0 and run the message loop once 96 // So, drop the reference count to 0 and run the message loop once
75 // to ensure that all resources are cleaned up before the test exits. 97 // to ensure that all resources are cleaned up before the test exits.
76 download_manager_ = NULL; 98 download_manager_ = NULL;
77 ui_thread_.message_loop()->RunAllPending(); 99 ui_thread_.message_loop()->RunAllPending();
78 } 100 }
79 101
80 virtual void CreateDownloadFile(scoped_ptr<DownloadFile>* file, 102 // Mock calls to this function are forwarded here.
81 int offset, 103 void RegisterCallback(base::Closure sink_callback) {
82 bool calculate_hash) { 104 sink_callback_ = sink_callback;
105 }
106
107 virtual bool CreateDownloadFile(int offset, bool calculate_hash) {
108 // There can be only one.
109 DCHECK(!download_file_.get());
110
111 input_pipe_ = new StrictMock<MockByteStreamOutput>();
112
113 // TODO: Need to actually create a function that'll set the variables
114 // based on the inputs from the callback.
115 EXPECT_CALL(*input_pipe_, RegisterCallback(_))
116 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback))
117 .RetiresOnSaturation();
118
83 DownloadCreateInfo info; 119 DownloadCreateInfo info;
84 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); 120 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset);
85 // info.request_handle default constructed to null. 121 // info.request_handle default constructed to null.
86 info.save_info.file_stream = file_stream_; 122 info.save_info.file_stream = file_stream_;
87 file->reset( 123 download_file_.reset(
88 new DownloadFileImpl(&info, new DownloadRequestHandle(), 124 new DownloadFileImpl(
89 download_manager_, calculate_hash, 125 &info,
90 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), 126 scoped_ptr<content::ByteStreamOutput>(input_pipe_).Pass(),
91 net::BoundNetLog())); 127 new DownloadRequestHandle(),
128 download_manager_, calculate_hash,
129 scoped_ptr<PowerSaveBlocker>(NULL).Pass(),
130 net::BoundNetLog()));
131
132 EXPECT_CALL(*input_pipe_, Read(_, _))
133 .WillOnce(Return(content::ByteStreamOutput::STREAM_EMPTY))
134 .RetiresOnSaturation();
135 net::Error result = download_file_->Initialize();
136 ::testing::Mock::VerifyAndClearExpectations(input_pipe_);
137 return result == net::OK;
92 } 138 }
93 139
94 virtual void DestroyDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { 140 virtual void DestroyDownloadFile(int offset) {
95 EXPECT_EQ(kDummyDownloadId + offset, (*file)->Id()); 141 EXPECT_EQ(kDummyDownloadId + offset, download_file_->Id());
96 EXPECT_EQ(download_manager_, (*file)->GetDownloadManager()); 142 EXPECT_EQ(download_manager_, download_file_->GetDownloadManager());
97 EXPECT_FALSE((*file)->InProgress()); 143 EXPECT_FALSE(download_file_->InProgress());
98 EXPECT_EQ(static_cast<int64>(expected_data_.size()), 144 EXPECT_EQ(static_cast<int64>(expected_data_.size()),
99 (*file)->BytesSoFar()); 145 download_file_->BytesSoFar());
100 146
101 // Make sure the data has been properly written to disk. 147 // Make sure the data has been properly written to disk.
102 std::string disk_data; 148 std::string disk_data;
103 EXPECT_TRUE(file_util::ReadFileToString((*file)->FullPath(), 149 EXPECT_TRUE(file_util::ReadFileToString(download_file_->FullPath(),
104 &disk_data)); 150 &disk_data));
105 EXPECT_EQ(expected_data_, disk_data); 151 EXPECT_EQ(expected_data_, disk_data);
106 152
107 // Make sure the Browser and File threads outlive the DownloadFile 153 // Make sure the Browser and File threads outlive the DownloadFile
108 // to satisfy thread checks inside it. 154 // to satisfy thread checks inside it.
109 file->reset(); 155 EXPECT_CALL(*input_pipe_, RegisterCallback(_))
156 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback))
157 .RetiresOnSaturation();
158 download_file_.reset();
110 } 159 }
111 160
112 void AppendDataToFile(scoped_ptr<DownloadFile>* file, 161 // Setup the pipe to do be a data append; don't actually trigger
113 const std::string& data) { 162 // the callback or do verifications.
114 EXPECT_TRUE((*file)->InProgress()); 163 void SetupDataAppend(const char **data_chunks, size_t num_chunks,
115 (*file)->AppendDataToFile(data.data(), data.size()); 164 ::testing::Sequence s) {
116 expected_data_ += data; 165 DCHECK(input_pipe_);
117 EXPECT_EQ(static_cast<int64>(expected_data_.size()), 166 for (size_t i = 0; i < num_chunks; i++) {
118 (*file)->BytesSoFar()); 167 const char *source_data = data_chunks[i];
168 size_t length = strlen(source_data);
169 scoped_refptr<net::IOBuffer> data = new net::IOBuffer(length);
170 memcpy(data->data(), source_data, length);
171 EXPECT_CALL(*input_pipe_, Read(_, _))
172 .InSequence(s)
173 .WillOnce(DoAll(SetArgPointee<0>(data),
174 SetArgPointee<1>(length),
175 Return(content::ByteStreamOutput::STREAM_HAS_DATA)))
176 .RetiresOnSaturation();
177 expected_data_ += source_data;
178 }
179 }
180
181 void VerifyPipeAndSize() {
182 ::testing::Mock::VerifyAndClearExpectations(input_pipe_);
183 int64 size;
184 EXPECT_TRUE(file_util::GetFileSize(download_file_->FullPath(), &size));
185 EXPECT_EQ(expected_data_.size(), static_cast<size_t>(size));
186 }
187
188 // TODO(rdsmith): Manage full percentage issues properly.
189 void AppendDataToFile(const char **data_chunks, size_t num_chunks) {
190 ::testing::Sequence s1;
191 SetupDataAppend(data_chunks, num_chunks, s1);
192 EXPECT_CALL(*input_pipe_, Read(_, _))
193 .InSequence(s1)
194 .WillOnce(Return(content::ByteStreamOutput::STREAM_EMPTY))
195 .RetiresOnSaturation();
196 sink_callback_.Run();
197 VerifyPipeAndSize();
198 }
199
200 void SetupFinishPipe(content::DownloadInterruptReason interrupt_reason,
201 ::testing::Sequence s) {
202 EXPECT_CALL(*input_pipe_, Read(_, _))
203 .InSequence(s)
204 .WillOnce(Return(content::ByteStreamOutput::STREAM_COMPLETE))
205 .RetiresOnSaturation();
206 EXPECT_CALL(*input_pipe_, GetStatus())
207 .InSequence(s)
208 .WillOnce(Return(interrupt_reason))
209 .RetiresOnSaturation();
210 EXPECT_CALL(*input_pipe_, RegisterCallback(_))
211 .InSequence(s)
212 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback))
213 .RetiresOnSaturation();
214 }
215
216 void FinishPipe(content::DownloadInterruptReason interrupt_reason) {
217 ::testing::Sequence s1;
218 SetupFinishPipe(interrupt_reason, s1);
219 sink_callback_.Run();
220 VerifyPipeAndSize();
119 } 221 }
120 222
121 protected: 223 protected:
122 scoped_refptr<StrictMock<content::MockDownloadManager> > download_manager_; 224 scoped_refptr<StrictMock<content::MockDownloadManager> > download_manager_;
123 225
124 linked_ptr<net::FileStream> file_stream_; 226 linked_ptr<net::FileStream> file_stream_;
125 227
126 // DownloadFile instance we are testing. 228 // DownloadFile instance we are testing.
127 scoped_ptr<DownloadFile> download_file_; 229 scoped_ptr<DownloadFile> download_file_;
128 230
231 // Pipe for sending data into the download file.
232 // Owned by download_file_; will be alive for lifetime of download_file_.
233 StrictMock<MockByteStreamOutput>* input_pipe_;
234
235 // Sink callback data for pipe.
236 base::Closure sink_callback_;
237
129 // Latest update sent to the download manager. 238 // Latest update sent to the download manager.
130 int64 bytes_; 239 int64 bytes_;
131 int64 bytes_per_sec_; 240 int64 bytes_per_sec_;
132 std::string hash_state_; 241 std::string hash_state_;
133 242
134 MessageLoop loop_; 243 MessageLoop loop_;
135 244
136 private: 245 private:
137 // UI thread. 246 // UI thread.
138 BrowserThreadImpl ui_thread_; 247 BrowserThreadImpl ui_thread_;
(...skipping 11 matching lines...) Expand all
150 const char* DownloadFileTest::kDataHash = 259 const char* DownloadFileTest::kDataHash =
151 "CBF68BF10F8003DB86B31343AFAC8C7175BD03FB5FC905650F8C80AF087443A8"; 260 "CBF68BF10F8003DB86B31343AFAC8C7175BD03FB5FC905650F8C80AF087443A8";
152 261
153 const int32 DownloadFileTest::kDummyDownloadId = 23; 262 const int32 DownloadFileTest::kDummyDownloadId = 23;
154 const int DownloadFileTest::kDummyChildId = 3; 263 const int DownloadFileTest::kDummyChildId = 3;
155 const int DownloadFileTest::kDummyRequestId = 67; 264 const int DownloadFileTest::kDummyRequestId = 67;
156 265
157 // Rename the file before any data is downloaded, after some has, after it all 266 // Rename the file before any data is downloaded, after some has, after it all
158 // has, and after it's closed. 267 // has, and after it's closed.
159 TEST_F(DownloadFileTest, RenameFileFinal) { 268 TEST_F(DownloadFileTest, RenameFileFinal) {
160 CreateDownloadFile(&download_file_, 0, true); 269 CreateDownloadFile(0, true);
161 ASSERT_EQ(net::OK, download_file_->Initialize()); 270 ASSERT_EQ(net::OK, download_file_->Initialize());
162 FilePath initial_path(download_file_->FullPath()); 271 FilePath initial_path(download_file_->FullPath());
163 EXPECT_TRUE(file_util::PathExists(initial_path)); 272 EXPECT_TRUE(file_util::PathExists(initial_path));
164 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); 273 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1"));
165 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); 274 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2"));
166 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); 275 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3"));
167 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); 276 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4"));
168 277
169 // Rename the file before downloading any data. 278 // Rename the file before downloading any data.
170 EXPECT_EQ(net::OK, download_file_->Rename(path_1)); 279 EXPECT_EQ(net::OK, download_file_->Rename(path_1));
171 FilePath renamed_path = download_file_->FullPath(); 280 FilePath renamed_path = download_file_->FullPath();
172 EXPECT_EQ(path_1, renamed_path); 281 EXPECT_EQ(path_1, renamed_path);
173 282
174 // Check the files. 283 // Check the files.
175 EXPECT_FALSE(file_util::PathExists(initial_path)); 284 EXPECT_FALSE(file_util::PathExists(initial_path));
176 EXPECT_TRUE(file_util::PathExists(path_1)); 285 EXPECT_TRUE(file_util::PathExists(path_1));
177 286
178 // Download the data. 287 // Download the data.
179 AppendDataToFile(&download_file_, kTestData1); 288 const char* chunks1[] = { kTestData1, kTestData2 };
180 AppendDataToFile(&download_file_, kTestData2); 289 AppendDataToFile(chunks1, 2);
181 290
182 // Rename the file after downloading some data. 291 // Rename the file after downloading some data.
183 EXPECT_EQ(net::OK, download_file_->Rename(path_2)); 292 EXPECT_EQ(net::OK, download_file_->Rename(path_2));
184 renamed_path = download_file_->FullPath(); 293 renamed_path = download_file_->FullPath();
185 EXPECT_EQ(path_2, renamed_path); 294 EXPECT_EQ(path_2, renamed_path);
186 295
187 // Check the files. 296 // Check the files.
188 EXPECT_FALSE(file_util::PathExists(path_1)); 297 EXPECT_FALSE(file_util::PathExists(path_1));
189 EXPECT_TRUE(file_util::PathExists(path_2)); 298 EXPECT_TRUE(file_util::PathExists(path_2));
190 299
191 AppendDataToFile(&download_file_, kTestData3); 300 const char* chunks2[] = { kTestData3 };
301 AppendDataToFile(chunks2, 1);
192 302
193 // Rename the file after downloading all the data. 303 // Rename the file after downloading all the data.
194 EXPECT_EQ(net::OK, download_file_->Rename(path_3)); 304 EXPECT_EQ(net::OK, download_file_->Rename(path_3));
195 renamed_path = download_file_->FullPath(); 305 renamed_path = download_file_->FullPath();
196 EXPECT_EQ(path_3, renamed_path); 306 EXPECT_EQ(path_3, renamed_path);
197 307
198 // Check the files. 308 // Check the files.
199 EXPECT_FALSE(file_util::PathExists(path_2)); 309 EXPECT_FALSE(file_util::PathExists(path_2));
200 EXPECT_TRUE(file_util::PathExists(path_3)); 310 EXPECT_TRUE(file_util::PathExists(path_3));
201 311
202 // Should not be able to get the hash until the file is closed. 312 // Should not be able to get the hash until the file is closed.
203 std::string hash; 313 std::string hash;
204 EXPECT_FALSE(download_file_->GetHash(&hash)); 314 EXPECT_FALSE(download_file_->GetHash(&hash));
205 315 FinishPipe(content::DOWNLOAD_INTERRUPT_REASON_NONE);
206 download_file_->Finish();
207 316
208 // Rename the file after downloading all the data and closing the file. 317 // Rename the file after downloading all the data and closing the file.
209 EXPECT_EQ(net::OK, download_file_->Rename(path_4)); 318 EXPECT_EQ(net::OK, download_file_->Rename(path_4));
210 renamed_path = download_file_->FullPath(); 319 renamed_path = download_file_->FullPath();
211 EXPECT_EQ(path_4, renamed_path); 320 EXPECT_EQ(path_4, renamed_path);
212 321
213 // Check the files. 322 // Check the files.
214 EXPECT_FALSE(file_util::PathExists(path_3)); 323 EXPECT_FALSE(file_util::PathExists(path_3));
215 EXPECT_TRUE(file_util::PathExists(path_4)); 324 EXPECT_TRUE(file_util::PathExists(path_4));
216 325
217 // Check the hash. 326 // Check the hash.
218 EXPECT_TRUE(download_file_->GetHash(&hash)); 327 EXPECT_TRUE(download_file_->GetHash(&hash));
219 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); 328 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size()));
220 329
221 DestroyDownloadFile(&download_file_, 0); 330 DestroyDownloadFile(0);
331 }
332
333 // Various tests of the PipeActive method.
334 TEST_F(DownloadFileTest, PipeEmptySuccess) {
335 ASSERT_TRUE(CreateDownloadFile(0, true));
336 FilePath initial_path(download_file_->FullPath());
337 EXPECT_TRUE(file_util::PathExists(initial_path));
338
339 // Test that calling the sink_callback_ on an empty pipe shouldn't
340 // do anything.
341 AppendDataToFile(NULL, 0);
342 ::testing::Mock::VerifyAndClearExpectations(download_manager_.get());
343
344 // Finish the download this way and make sure we see it on the
345 // DownloadManager.
346 EXPECT_CALL(*(download_manager_.get()),
347 OnResponseCompleted(DownloadId(kValidIdDomain,
348 kDummyDownloadId + 0).local(),
349 0, _));
350 FinishPipe(content::DOWNLOAD_INTERRUPT_REASON_NONE);
351
352 DestroyDownloadFile(0);
353 }
354
355 TEST_F(DownloadFileTest, PipeEmptyError) {
356 ASSERT_TRUE(CreateDownloadFile(0, true));
357 FilePath initial_path(download_file_->FullPath());
358 EXPECT_TRUE(file_util::PathExists(initial_path));
359
360 // Finish the download in error and make sure we see it on the
361 // DownloadManager.
362 EXPECT_CALL(*(download_manager_.get()),
363 OnDownloadInterrupted(
364 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(),
365 0, _,
366 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED));
367 FinishPipe(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED);
368
369 DestroyDownloadFile(0);
370 }
371
372 TEST_F(DownloadFileTest, PipeNonEmptySuccess) {
373 ASSERT_TRUE(CreateDownloadFile(0, true));
374 FilePath initial_path(download_file_->FullPath());
375 EXPECT_TRUE(file_util::PathExists(initial_path));
376
377 const char* chunks1[] = { kTestData1, kTestData2 };
378 ::testing::Sequence s1;
379 SetupDataAppend(chunks1, 2, s1);
380 SetupFinishPipe(content::DOWNLOAD_INTERRUPT_REASON_NONE, s1);
381 EXPECT_CALL(*(download_manager_.get()),
382 OnResponseCompleted(DownloadId(kValidIdDomain,
383 kDummyDownloadId + 0).local(),
384 strlen(kTestData1) + strlen(kTestData2),
385 _));
386 sink_callback_.Run();
387 VerifyPipeAndSize();
388 DestroyDownloadFile(0);
389 }
390
391 TEST_F(DownloadFileTest, PipeNonEmptyError) {
392 ASSERT_TRUE(CreateDownloadFile(0, true));
393 FilePath initial_path(download_file_->FullPath());
394 EXPECT_TRUE(file_util::PathExists(initial_path));
395
396 const char* chunks1[] = { kTestData1, kTestData2 };
397 ::testing::Sequence s1;
398 SetupDataAppend(chunks1, 2, s1);
399 SetupFinishPipe(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, s1);
400 EXPECT_CALL(*(download_manager_.get()),
401 OnDownloadInterrupted(
402 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(),
403 strlen(kTestData1) + strlen(kTestData2), _,
404 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED));
405 sink_callback_.Run();
406 VerifyPipeAndSize();
407 DestroyDownloadFile(0);
222 } 408 }
223 409
224 // Send some data, wait 3/4s of a second, run the message loop, and 410 // Send some data, wait 3/4s of a second, run the message loop, and
225 // confirm the values the DownloadManager received are correct. 411 // confirm the values the DownloadManager received are correct.
226 TEST_F(DownloadFileTest, ConfirmUpdate) { 412 TEST_F(DownloadFileTest, ConfirmUpdate) {
227 CreateDownloadFile(&download_file_, 0, true); 413 CreateDownloadFile(0, true);
228 ASSERT_EQ(net::OK, download_file_->Initialize()); 414 ASSERT_EQ(net::OK, download_file_->Initialize());
229 415
230 AppendDataToFile(&download_file_, kTestData1); 416 const char* chunks1[] = { kTestData1, kTestData2 };
231 AppendDataToFile(&download_file_, kTestData2); 417 AppendDataToFile(chunks1, 2);
232 418
233 // Run the message loops for 750ms and check for results. 419 // Run the message loops for 750ms and check for results.
234 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 420 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
235 base::TimeDelta::FromMilliseconds(750)); 421 base::TimeDelta::FromMilliseconds(750));
236 loop_.Run(); 422 loop_.Run();
237 423
238 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), 424 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)),
239 bytes_); 425 bytes_);
240 EXPECT_EQ(download_file_->GetHashState(), hash_state_); 426 EXPECT_EQ(download_file_->GetHashState(), hash_state_);
241 427
242 download_file_->Finish(); 428 FinishPipe(content::DOWNLOAD_INTERRUPT_REASON_NONE);
243 DestroyDownloadFile(&download_file_, 0); 429 DestroyDownloadFile(0);
244 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698