Chromium Code Reviews| 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 "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/byte_stream.h" |
| 10 #include "content/browser/download/download_create_info.h" | 10 #include "content/browser/download/download_create_info.h" |
| 11 #include "content/browser/download/download_file_impl.h" | 11 #include "content/browser/download/download_file_impl.h" |
| 12 #include "content/browser/download/download_request_handle.h" | 12 #include "content/browser/download/download_request_handle.h" |
| 13 #include "content/browser/power_save_blocker.h" | 13 #include "content/browser/power_save_blocker.h" |
| 14 #include "content/public/browser/download_interrupt_reasons.h" | 14 #include "content/public/browser/download_interrupt_reasons.h" |
| 15 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
| 16 #include "content/public/test/mock_download_manager.h" | 16 #include "content/public/test/mock_download_manager.h" |
| 17 #include "net/base/file_stream.h" | 17 #include "net/base/file_stream.h" |
| 18 #include "net/base/mock_file_stream.h" | |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 using content::BrowserThreadImpl; | 24 using content::BrowserThreadImpl; |
| 24 using content::DownloadFile; | 25 using content::DownloadFile; |
| 25 using content::DownloadId; | 26 using content::DownloadId; |
| 26 using content::DownloadManager; | 27 using content::DownloadManager; |
| 27 using ::testing::_; | 28 using ::testing::_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 38 MockByteStreamReader() {} | 39 MockByteStreamReader() {} |
| 39 ~MockByteStreamReader() {} | 40 ~MockByteStreamReader() {} |
| 40 | 41 |
| 41 // ByteStream functions | 42 // ByteStream functions |
| 42 MOCK_METHOD2(Read, content::ByteStreamReader::StreamState( | 43 MOCK_METHOD2(Read, content::ByteStreamReader::StreamState( |
| 43 scoped_refptr<net::IOBuffer>*, size_t*)); | 44 scoped_refptr<net::IOBuffer>*, size_t*)); |
| 44 MOCK_CONST_METHOD0(GetStatus, content::DownloadInterruptReason()); | 45 MOCK_CONST_METHOD0(GetStatus, content::DownloadInterruptReason()); |
| 45 MOCK_METHOD1(RegisterCallback, void(const base::Closure&)); | 46 MOCK_METHOD1(RegisterCallback, void(const base::Closure&)); |
| 46 }; | 47 }; |
| 47 | 48 |
| 49 void SetRenameResult(bool* called_p, | |
| 50 content::DownloadInterruptReason* reason_p, | |
| 51 FilePath* result_path_p, | |
| 52 content::DownloadInterruptReason reason, | |
| 53 const FilePath& result_path) { | |
| 54 if (called_p) | |
| 55 *called_p = true; | |
| 56 if (reason_p) | |
| 57 *reason_p = reason; | |
| 58 if (result_path_p) | |
| 59 *result_path_p = result_path; | |
| 60 } | |
| 61 | |
| 48 } // namespace | 62 } // namespace |
| 49 | 63 |
| 50 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; | 64 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; |
| 51 | 65 |
| 52 class DownloadFileTest : public testing::Test { | 66 class DownloadFileTest : public testing::Test { |
| 53 public: | 67 public: |
| 54 | 68 |
| 55 static const char* kTestData1; | 69 static const char* kTestData1; |
| 56 static const char* kTestData2; | 70 static const char* kTestData2; |
| 57 static const char* kTestData3; | 71 static const char* kTestData3; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 124 |
| 111 input_stream_ = new StrictMock<MockByteStreamReader>(); | 125 input_stream_ = new StrictMock<MockByteStreamReader>(); |
| 112 | 126 |
| 113 // TODO: Need to actually create a function that'll set the variables | 127 // TODO: Need to actually create a function that'll set the variables |
| 114 // based on the inputs from the callback. | 128 // based on the inputs from the callback. |
| 115 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 129 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 116 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 130 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 117 .RetiresOnSaturation(); | 131 .RetiresOnSaturation(); |
| 118 | 132 |
| 119 DownloadCreateInfo info; | 133 DownloadCreateInfo info; |
| 134 // info.request_handle default constructed to null. | |
| 120 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); | 135 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); |
| 121 // info.request_handle default constructed to null. | |
| 122 info.save_info.file_stream = file_stream_; | 136 info.save_info.file_stream = file_stream_; |
| 123 download_file_.reset( | 137 download_file_.reset( |
| 124 new DownloadFileImpl( | 138 new DownloadFileImpl( |
| 125 &info, | 139 &info, |
| 126 scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(), | 140 scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(), |
| 127 new DownloadRequestHandle(), | 141 new DownloadRequestHandle(), |
| 128 download_manager_, calculate_hash, | 142 download_manager_, calculate_hash, |
| 129 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), | 143 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), |
| 130 net::BoundNetLog())); | 144 net::BoundNetLog())); |
| 131 | 145 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 EXPECT_CALL(*(download_manager_.get()), | 235 EXPECT_CALL(*(download_manager_.get()), |
| 222 UpdateDownload( | 236 UpdateDownload( |
| 223 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(), | 237 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(), |
| 224 _, _, _)) | 238 _, _, _)) |
| 225 .Times(AnyNumber()) | 239 .Times(AnyNumber()) |
| 226 .WillRepeatedly(Invoke(this, | 240 .WillRepeatedly(Invoke(this, |
| 227 &DownloadFileTest::SetUpdateDownloadInfo)); | 241 &DownloadFileTest::SetUpdateDownloadInfo)); |
| 228 } | 242 } |
| 229 } | 243 } |
| 230 | 244 |
| 245 content::DownloadInterruptReason Rename( | |
| 246 const FilePath& full_path, bool overwrite_existing_file, | |
| 247 FilePath* result_path_p) { | |
| 248 content::DownloadInterruptReason result_reason( | |
| 249 content::DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 250 bool callback_was_called(false); | |
| 251 FilePath result_path; | |
| 252 | |
| 253 download_file_->Rename(full_path, overwrite_existing_file, | |
| 254 base::Bind(&SetRenameResult, | |
| 255 &callback_was_called, | |
| 256 &result_reason, result_path_p)); | |
| 257 loop_.RunAllPending(); | |
| 258 | |
| 259 // If the callback wasn't called we've got a memory stomper waiting | |
| 260 // to happen; best to crash. | |
| 261 CHECK(callback_was_called); | |
|
asanka
2012/07/05 18:47:21
The last time came up, I ended up creating a local
Randy Smith (Not in Mondays)
2012/07/09 20:35:51
Nice. Done.
| |
| 262 return result_reason; | |
| 263 } | |
| 264 | |
| 231 protected: | 265 protected: |
| 232 scoped_refptr<StrictMock<content::MockDownloadManager> > download_manager_; | 266 scoped_refptr<StrictMock<content::MockDownloadManager> > download_manager_; |
| 233 | 267 |
| 234 linked_ptr<net::FileStream> file_stream_; | 268 linked_ptr<net::FileStream> file_stream_; |
| 235 | 269 |
| 236 // DownloadFile instance we are testing. | 270 // DownloadFile instance we are testing. |
| 237 scoped_ptr<DownloadFile> download_file_; | 271 scoped_ptr<DownloadFile> download_file_; |
| 238 | 272 |
| 239 // Stream for sending data into the download file. | 273 // Stream for sending data into the download file. |
| 240 // Owned by download_file_; will be alive for lifetime of download_file_. | 274 // Owned by download_file_; will be alive for lifetime of download_file_. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // Rename the file before any data is downloaded, after some has, after it all | 308 // Rename the file before any data is downloaded, after some has, after it all |
| 275 // has, and after it's closed. | 309 // has, and after it's closed. |
| 276 TEST_F(DownloadFileTest, RenameFileFinal) { | 310 TEST_F(DownloadFileTest, RenameFileFinal) { |
| 277 ASSERT_TRUE(CreateDownloadFile(0, true)); | 311 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 278 FilePath initial_path(download_file_->FullPath()); | 312 FilePath initial_path(download_file_->FullPath()); |
| 279 EXPECT_TRUE(file_util::PathExists(initial_path)); | 313 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 280 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); | 314 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); |
| 281 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); | 315 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); |
| 282 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); | 316 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); |
| 283 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); | 317 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); |
| 318 FilePath path_5(initial_path.InsertBeforeExtensionASCII("_5")); | |
| 319 FilePath output_path; | |
| 284 | 320 |
| 285 // Rename the file before downloading any data. | 321 // Rename the file before downloading any data. |
| 286 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | 322 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 287 download_file_->Rename(path_1)); | 323 Rename(path_1, false, &output_path)); |
| 288 FilePath renamed_path = download_file_->FullPath(); | 324 FilePath renamed_path = download_file_->FullPath(); |
| 289 EXPECT_EQ(path_1, renamed_path); | 325 EXPECT_EQ(path_1, renamed_path); |
| 326 EXPECT_EQ(path_1, output_path); | |
| 290 | 327 |
| 291 // Check the files. | 328 // Check the files. |
| 292 EXPECT_FALSE(file_util::PathExists(initial_path)); | 329 EXPECT_FALSE(file_util::PathExists(initial_path)); |
| 293 EXPECT_TRUE(file_util::PathExists(path_1)); | 330 EXPECT_TRUE(file_util::PathExists(path_1)); |
| 294 | 331 |
| 295 // Download the data. | 332 // Download the data. |
| 296 const char* chunks1[] = { kTestData1, kTestData2 }; | 333 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 297 AppendDataToFile(chunks1, 2); | 334 AppendDataToFile(chunks1, 2); |
| 298 | 335 |
| 299 // Rename the file after downloading some data. | 336 // Rename the file after downloading some data. |
| 300 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | 337 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 301 download_file_->Rename(path_2)); | 338 Rename(path_2, false, &output_path)); |
| 302 renamed_path = download_file_->FullPath(); | 339 renamed_path = download_file_->FullPath(); |
| 303 EXPECT_EQ(path_2, renamed_path); | 340 EXPECT_EQ(path_2, renamed_path); |
| 341 EXPECT_EQ(path_2, output_path); | |
| 304 | 342 |
| 305 // Check the files. | 343 // Check the files. |
| 306 EXPECT_FALSE(file_util::PathExists(path_1)); | 344 EXPECT_FALSE(file_util::PathExists(path_1)); |
| 307 EXPECT_TRUE(file_util::PathExists(path_2)); | 345 EXPECT_TRUE(file_util::PathExists(path_2)); |
| 308 | 346 |
| 309 const char* chunks2[] = { kTestData3 }; | 347 const char* chunks2[] = { kTestData3 }; |
| 310 AppendDataToFile(chunks2, 1); | 348 AppendDataToFile(chunks2, 1); |
| 311 | 349 |
| 312 // Rename the file after downloading all the data. | 350 // Rename the file after downloading all the data. |
| 313 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | 351 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 314 download_file_->Rename(path_3)); | 352 Rename(path_3, false, &output_path)); |
| 315 renamed_path = download_file_->FullPath(); | 353 renamed_path = download_file_->FullPath(); |
| 316 EXPECT_EQ(path_3, renamed_path); | 354 EXPECT_EQ(path_3, renamed_path); |
| 355 EXPECT_EQ(path_3, output_path); | |
| 317 | 356 |
| 318 // Check the files. | 357 // Check the files. |
| 319 EXPECT_FALSE(file_util::PathExists(path_2)); | 358 EXPECT_FALSE(file_util::PathExists(path_2)); |
| 320 EXPECT_TRUE(file_util::PathExists(path_3)); | 359 EXPECT_TRUE(file_util::PathExists(path_3)); |
| 321 | 360 |
| 322 // Should not be able to get the hash until the file is closed. | 361 // Should not be able to get the hash until the file is closed. |
| 323 std::string hash; | 362 std::string hash; |
| 324 EXPECT_FALSE(download_file_->GetHash(&hash)); | 363 EXPECT_FALSE(download_file_->GetHash(&hash)); |
| 325 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); | 364 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 326 loop_.RunAllPending(); | 365 loop_.RunAllPending(); |
| 327 | 366 |
| 328 // Rename the file after downloading all the data and closing the file. | 367 // Rename the file after downloading all the data and closing the file. |
| 329 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | 368 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, |
| 330 download_file_->Rename(path_4)); | 369 Rename(path_4, false, &output_path)); |
| 331 renamed_path = download_file_->FullPath(); | 370 renamed_path = download_file_->FullPath(); |
| 332 EXPECT_EQ(path_4, renamed_path); | 371 EXPECT_EQ(path_4, renamed_path); |
| 372 EXPECT_EQ(path_4, output_path); | |
| 333 | 373 |
| 334 // Check the files. | 374 // Check the files. |
| 335 EXPECT_FALSE(file_util::PathExists(path_3)); | 375 EXPECT_FALSE(file_util::PathExists(path_3)); |
| 336 EXPECT_TRUE(file_util::PathExists(path_4)); | 376 EXPECT_TRUE(file_util::PathExists(path_4)); |
| 337 | 377 |
| 338 // Check the hash. | 378 // Check the hash. |
| 339 EXPECT_TRUE(download_file_->GetHash(&hash)); | 379 EXPECT_TRUE(download_file_->GetHash(&hash)); |
| 340 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); | 380 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); |
| 341 | 381 |
| 382 // Check that a rename with overwrite to an existing file succeeds. | |
| 383 std::string file_contents; | |
| 384 ASSERT_FALSE(file_util::PathExists(path_5)); | |
| 385 static const char file_data[] = "xyzzy"; | |
| 386 ASSERT_EQ(static_cast<int>(sizeof(file_data) - 1), | |
| 387 file_util::WriteFile(path_5, file_data, sizeof(file_data) - 1)); | |
| 388 ASSERT_TRUE(file_util::PathExists(path_5)); | |
| 389 EXPECT_TRUE(file_util::ReadFileToString(path_5, &file_contents)); | |
| 390 EXPECT_EQ(std::string(file_data), file_contents); | |
| 391 | |
| 392 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | |
| 393 Rename(path_5, true, &output_path)); | |
| 394 EXPECT_EQ(path_5, output_path); | |
| 395 | |
| 396 file_contents = ""; | |
| 397 EXPECT_TRUE(file_util::ReadFileToString(path_5, &file_contents)); | |
| 398 EXPECT_NE(std::string(file_data), file_contents); | |
| 399 | |
| 342 DestroyDownloadFile(0); | 400 DestroyDownloadFile(0); |
| 343 } | 401 } |
| 344 | 402 |
|
asanka
2012/07/05 18:47:21
Also throw in a RenameError test now that error re
Randy Smith (Not in Mondays)
2012/07/09 20:35:51
Good thought! I didn't know about MakeFileUnwrita
| |
| 403 // Test to make sure the rename uniquifies if we aren't overwriting | |
| 404 // and there's a file where we're aiming. | |
| 405 TEST_F(DownloadFileTest, RenameOverwrite) { | |
| 406 ASSERT_TRUE(CreateDownloadFile(0, true)); | |
| 407 FilePath initial_path(download_file_->FullPath()); | |
| 408 EXPECT_TRUE(file_util::PathExists(initial_path)); | |
| 409 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); | |
| 410 FilePath path_1_suffixed(path_1.InsertBeforeExtensionASCII(" (1)")); | |
| 411 | |
| 412 ASSERT_FALSE(file_util::PathExists(path_1)); | |
| 413 static const char file_data[] = "xyzzy"; | |
| 414 ASSERT_EQ(static_cast<int>(sizeof(file_data)), | |
| 415 file_util::WriteFile(path_1, file_data, sizeof(file_data))); | |
| 416 ASSERT_TRUE(file_util::PathExists(path_1)); | |
| 417 | |
| 418 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | |
| 419 Rename(path_1, false, NULL)); | |
| 420 EXPECT_TRUE(file_util::PathExists(path_1_suffixed)); | |
| 421 | |
| 422 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); | |
| 423 loop_.RunAllPending(); | |
| 424 DestroyDownloadFile(0); | |
| 425 } | |
| 426 | |
| 427 // TODO(rdsmith): Test proper behavior of DownloadFile in the case of | |
| 428 // errors on the rename (including writing to the file after rename error). | |
| 429 | |
| 345 // Various tests of the StreamActive method. | 430 // Various tests of the StreamActive method. |
| 346 TEST_F(DownloadFileTest, StreamEmptySuccess) { | 431 TEST_F(DownloadFileTest, StreamEmptySuccess) { |
| 347 ASSERT_TRUE(CreateDownloadFile(0, true)); | 432 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 348 FilePath initial_path(download_file_->FullPath()); | 433 FilePath initial_path(download_file_->FullPath()); |
| 349 EXPECT_TRUE(file_util::PathExists(initial_path)); | 434 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 350 | 435 |
| 351 // Test that calling the sink_callback_ on an empty stream shouldn't | 436 // Test that calling the sink_callback_ on an empty stream shouldn't |
| 352 // do anything. | 437 // do anything. |
| 353 AppendDataToFile(NULL, 0); | 438 AppendDataToFile(NULL, 0); |
| 354 ::testing::Mock::VerifyAndClearExpectations(download_manager_.get()); | 439 ::testing::Mock::VerifyAndClearExpectations(download_manager_.get()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 370 DestroyDownloadFile(0); | 455 DestroyDownloadFile(0); |
| 371 } | 456 } |
| 372 | 457 |
| 373 TEST_F(DownloadFileTest, StreamEmptyError) { | 458 TEST_F(DownloadFileTest, StreamEmptyError) { |
| 374 ASSERT_TRUE(CreateDownloadFile(0, true)); | 459 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 375 FilePath initial_path(download_file_->FullPath()); | 460 FilePath initial_path(download_file_->FullPath()); |
| 376 EXPECT_TRUE(file_util::PathExists(initial_path)); | 461 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 377 | 462 |
| 378 // Finish the download in error and make sure we see it on the | 463 // Finish the download in error and make sure we see it on the |
| 379 // DownloadManager. | 464 // DownloadManager. |
| 380 EXPECT_CALL(*(download_manager_.get()), | 465 EXPECT_CALL(*(download_manager_.get()), |
|
asanka
2012/07/05 18:47:21
Expect a sequence restricted UpdateDownload() call
Randy Smith (Not in Mondays)
2012/07/09 20:35:51
So the tricky thing here is that we're going to ha
| |
| 381 OnDownloadInterrupted( | 466 OnDownloadInterrupted( |
| 382 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(), | 467 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(), |
| 383 0, _, | |
| 384 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)); | 468 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)); |
| 385 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, false); | 469 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, false); |
| 386 | 470 |
| 387 DestroyDownloadFile(0); | 471 DestroyDownloadFile(0); |
| 388 } | 472 } |
| 389 | 473 |
| 390 TEST_F(DownloadFileTest, StreamNonEmptySuccess) { | 474 TEST_F(DownloadFileTest, StreamNonEmptySuccess) { |
| 391 ASSERT_TRUE(CreateDownloadFile(0, true)); | 475 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 392 FilePath initial_path(download_file_->FullPath()); | 476 FilePath initial_path(download_file_->FullPath()); |
| 393 EXPECT_TRUE(file_util::PathExists(initial_path)); | 477 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 412 EXPECT_TRUE(file_util::PathExists(initial_path)); | 496 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 413 | 497 |
| 414 const char* chunks1[] = { kTestData1, kTestData2 }; | 498 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 415 ::testing::Sequence s1; | 499 ::testing::Sequence s1; |
| 416 SetupDataAppend(chunks1, 2, s1); | 500 SetupDataAppend(chunks1, 2, s1); |
| 417 SetupFinishStream(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, | 501 SetupFinishStream(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, |
| 418 s1); | 502 s1); |
| 419 EXPECT_CALL(*(download_manager_.get()), | 503 EXPECT_CALL(*(download_manager_.get()), |
| 420 OnDownloadInterrupted( | 504 OnDownloadInterrupted( |
| 421 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(), | 505 DownloadId(kValidIdDomain, kDummyDownloadId + 0).local(), |
| 422 strlen(kTestData1) + strlen(kTestData2), _, | |
| 423 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)); | 506 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)); |
| 424 sink_callback_.Run(); | 507 sink_callback_.Run(); |
| 508 loop_.RunAllPending(); | |
| 509 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), | |
| 510 bytes_); | |
| 425 VerifyStreamAndSize(); | 511 VerifyStreamAndSize(); |
| 426 DestroyDownloadFile(0); | 512 DestroyDownloadFile(0); |
| 427 } | 513 } |
| 428 | 514 |
| 429 // Send some data, wait 3/4s of a second, run the message loop, and | 515 // Send some data, wait 3/4s of a second, run the message loop, and |
| 430 // confirm the values the DownloadManager received are correct. | 516 // confirm the values the DownloadManager received are correct. |
| 431 TEST_F(DownloadFileTest, ConfirmUpdate) { | 517 TEST_F(DownloadFileTest, ConfirmUpdate) { |
| 432 CreateDownloadFile(0, true); | 518 CreateDownloadFile(0, true); |
| 433 | 519 |
| 434 const char* chunks1[] = { kTestData1, kTestData2 }; | 520 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 435 AppendDataToFile(chunks1, 2); | 521 AppendDataToFile(chunks1, 2); |
| 436 | 522 |
| 437 // Run the message loops for 750ms and check for results. | 523 // Run the message loops for 750ms and check for results. |
| 438 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 524 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 439 base::TimeDelta::FromMilliseconds(750)); | 525 base::TimeDelta::FromMilliseconds(750)); |
| 440 loop_.Run(); | 526 loop_.Run(); |
| 441 | 527 |
| 442 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), | 528 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), |
| 443 bytes_); | 529 bytes_); |
| 444 EXPECT_EQ(download_file_->GetHashState(), hash_state_); | 530 EXPECT_EQ(download_file_->GetHashState(), hash_state_); |
| 445 | 531 |
| 446 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); | 532 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 447 DestroyDownloadFile(0); | 533 DestroyDownloadFile(0); |
| 448 } | 534 } |
| OLD | NEW |