| 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 "base/test/test_file_util.h" | 8 #include "base/test/test_file_util.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/download/byte_stream.h" | 10 #include "content/browser/download/byte_stream.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // TODO: Need to actually create a function that'll set the variables | 126 // TODO: Need to actually create a function that'll set the variables |
| 127 // based on the inputs from the callback. | 127 // based on the inputs from the callback. |
| 128 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 128 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 129 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 129 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 130 .RetiresOnSaturation(); | 130 .RetiresOnSaturation(); |
| 131 | 131 |
| 132 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 132 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 133 download_file_.reset( | 133 download_file_.reset( |
| 134 new DownloadFileImpl( | 134 new DownloadFileImpl( |
| 135 save_info.Pass(), | 135 save_info.Pass(), |
| 136 FilePath(), | 136 base::FilePath(), |
| 137 GURL(), // Source | 137 GURL(), // Source |
| 138 GURL(), // Referrer | 138 GURL(), // Referrer |
| 139 calculate_hash, | 139 calculate_hash, |
| 140 scoped_ptr<ByteStreamReader>(input_stream_), | 140 scoped_ptr<ByteStreamReader>(input_stream_), |
| 141 net::BoundNetLog(), | 141 net::BoundNetLog(), |
| 142 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), | 142 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), |
| 143 observer_factory_.GetWeakPtr())); | 143 observer_factory_.GetWeakPtr())); |
| 144 | 144 |
| 145 EXPECT_CALL(*input_stream_, Read(_, _)) | 145 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 146 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) | 146 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 loop_.RunUntilIdle(); | 239 loop_.RunUntilIdle(); |
| 240 ::testing::Mock::VerifyAndClearExpectations(observer_.get()); | 240 ::testing::Mock::VerifyAndClearExpectations(observer_.get()); |
| 241 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _)) | 241 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _)) |
| 242 .Times(AnyNumber()) | 242 .Times(AnyNumber()) |
| 243 .WillRepeatedly(Invoke(this, | 243 .WillRepeatedly(Invoke(this, |
| 244 &DownloadFileTest::SetUpdateDownloadInfo)); | 244 &DownloadFileTest::SetUpdateDownloadInfo)); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 DownloadInterruptReason RenameAndUniquify( | 248 DownloadInterruptReason RenameAndUniquify( |
| 249 const FilePath& full_path, | 249 const base::FilePath& full_path, |
| 250 FilePath* result_path_p) { | 250 base::FilePath* result_path_p) { |
| 251 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 251 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
| 252 DownloadInterruptReason result_reason(DOWNLOAD_INTERRUPT_REASON_NONE); | 252 DownloadInterruptReason result_reason(DOWNLOAD_INTERRUPT_REASON_NONE); |
| 253 bool callback_was_called(false); | 253 bool callback_was_called(false); |
| 254 FilePath result_path; | 254 base::FilePath result_path; |
| 255 | 255 |
| 256 download_file_->RenameAndUniquify( | 256 download_file_->RenameAndUniquify( |
| 257 full_path, base::Bind(&DownloadFileTest::SetRenameResult, | 257 full_path, base::Bind(&DownloadFileTest::SetRenameResult, |
| 258 weak_ptr_factory.GetWeakPtr(), | 258 weak_ptr_factory.GetWeakPtr(), |
| 259 &callback_was_called, | 259 &callback_was_called, |
| 260 &result_reason, result_path_p)); | 260 &result_reason, result_path_p)); |
| 261 loop_.RunUntilIdle(); | 261 loop_.RunUntilIdle(); |
| 262 | 262 |
| 263 EXPECT_TRUE(callback_was_called); | 263 EXPECT_TRUE(callback_was_called); |
| 264 return result_reason; | 264 return result_reason; |
| 265 } | 265 } |
| 266 | 266 |
| 267 DownloadInterruptReason RenameAndAnnotate( | 267 DownloadInterruptReason RenameAndAnnotate( |
| 268 const FilePath& full_path, | 268 const base::FilePath& full_path, |
| 269 FilePath* result_path_p) { | 269 base::FilePath* result_path_p) { |
| 270 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 270 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
| 271 DownloadInterruptReason result_reason(DOWNLOAD_INTERRUPT_REASON_NONE); | 271 DownloadInterruptReason result_reason(DOWNLOAD_INTERRUPT_REASON_NONE); |
| 272 bool callback_was_called(false); | 272 bool callback_was_called(false); |
| 273 FilePath result_path; | 273 base::FilePath result_path; |
| 274 | 274 |
| 275 download_file_->RenameAndAnnotate( | 275 download_file_->RenameAndAnnotate( |
| 276 full_path, base::Bind(&DownloadFileTest::SetRenameResult, | 276 full_path, base::Bind(&DownloadFileTest::SetRenameResult, |
| 277 weak_ptr_factory.GetWeakPtr(), | 277 weak_ptr_factory.GetWeakPtr(), |
| 278 &callback_was_called, | 278 &callback_was_called, |
| 279 &result_reason, result_path_p)); | 279 &result_reason, result_path_p)); |
| 280 loop_.RunUntilIdle(); | 280 loop_.RunUntilIdle(); |
| 281 | 281 |
| 282 EXPECT_TRUE(callback_was_called); | 282 EXPECT_TRUE(callback_was_called); |
| 283 return result_reason; | 283 return result_reason; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 300 // Latest update sent to the observer. | 300 // Latest update sent to the observer. |
| 301 int64 bytes_; | 301 int64 bytes_; |
| 302 int64 bytes_per_sec_; | 302 int64 bytes_per_sec_; |
| 303 std::string hash_state_; | 303 std::string hash_state_; |
| 304 | 304 |
| 305 MessageLoop loop_; | 305 MessageLoop loop_; |
| 306 | 306 |
| 307 private: | 307 private: |
| 308 void SetRenameResult(bool* called_p, | 308 void SetRenameResult(bool* called_p, |
| 309 DownloadInterruptReason* reason_p, | 309 DownloadInterruptReason* reason_p, |
| 310 FilePath* result_path_p, | 310 base::FilePath* result_path_p, |
| 311 DownloadInterruptReason reason, | 311 DownloadInterruptReason reason, |
| 312 const FilePath& result_path) { | 312 const base::FilePath& result_path) { |
| 313 if (called_p) | 313 if (called_p) |
| 314 *called_p = true; | 314 *called_p = true; |
| 315 if (reason_p) | 315 if (reason_p) |
| 316 *reason_p = reason; | 316 *reason_p = reason; |
| 317 if (result_path_p) | 317 if (result_path_p) |
| 318 *result_path_p = result_path; | 318 *result_path_p = result_path; |
| 319 } | 319 } |
| 320 | 320 |
| 321 // UI thread. | 321 // UI thread. |
| 322 BrowserThreadImpl ui_thread_; | 322 BrowserThreadImpl ui_thread_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 335 "CBF68BF10F8003DB86B31343AFAC8C7175BD03FB5FC905650F8C80AF087443A8"; | 335 "CBF68BF10F8003DB86B31343AFAC8C7175BD03FB5FC905650F8C80AF087443A8"; |
| 336 | 336 |
| 337 const int32 DownloadFileTest::kDummyDownloadId = 23; | 337 const int32 DownloadFileTest::kDummyDownloadId = 23; |
| 338 const int DownloadFileTest::kDummyChildId = 3; | 338 const int DownloadFileTest::kDummyChildId = 3; |
| 339 const int DownloadFileTest::kDummyRequestId = 67; | 339 const int DownloadFileTest::kDummyRequestId = 67; |
| 340 | 340 |
| 341 // Rename the file before any data is downloaded, after some has, after it all | 341 // Rename the file before any data is downloaded, after some has, after it all |
| 342 // has, and after it's closed. | 342 // has, and after it's closed. |
| 343 TEST_F(DownloadFileTest, RenameFileFinal) { | 343 TEST_F(DownloadFileTest, RenameFileFinal) { |
| 344 ASSERT_TRUE(CreateDownloadFile(0, true)); | 344 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 345 FilePath initial_path(download_file_->FullPath()); | 345 base::FilePath initial_path(download_file_->FullPath()); |
| 346 EXPECT_TRUE(file_util::PathExists(initial_path)); | 346 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 347 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); | 347 base::FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); |
| 348 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); | 348 base::FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); |
| 349 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); | 349 base::FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); |
| 350 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); | 350 base::FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); |
| 351 FilePath path_5(initial_path.InsertBeforeExtensionASCII("_5")); | 351 base::FilePath path_5(initial_path.InsertBeforeExtensionASCII("_5")); |
| 352 FilePath output_path; | 352 base::FilePath output_path; |
| 353 | 353 |
| 354 // Rename the file before downloading any data. | 354 // Rename the file before downloading any data. |
| 355 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, | 355 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 356 RenameAndUniquify(path_1, &output_path)); | 356 RenameAndUniquify(path_1, &output_path)); |
| 357 FilePath renamed_path = download_file_->FullPath(); | 357 base::FilePath renamed_path = download_file_->FullPath(); |
| 358 EXPECT_EQ(path_1, renamed_path); | 358 EXPECT_EQ(path_1, renamed_path); |
| 359 EXPECT_EQ(path_1, output_path); | 359 EXPECT_EQ(path_1, output_path); |
| 360 | 360 |
| 361 // Check the files. | 361 // Check the files. |
| 362 EXPECT_FALSE(file_util::PathExists(initial_path)); | 362 EXPECT_FALSE(file_util::PathExists(initial_path)); |
| 363 EXPECT_TRUE(file_util::PathExists(path_1)); | 363 EXPECT_TRUE(file_util::PathExists(path_1)); |
| 364 | 364 |
| 365 // Download the data. | 365 // Download the data. |
| 366 const char* chunks1[] = { kTestData1, kTestData2 }; | 366 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 367 AppendDataToFile(chunks1, 2); | 367 AppendDataToFile(chunks1, 2); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 EXPECT_TRUE(file_util::ReadFileToString(path_5, &file_contents)); | 430 EXPECT_TRUE(file_util::ReadFileToString(path_5, &file_contents)); |
| 431 EXPECT_NE(std::string(file_data), file_contents); | 431 EXPECT_NE(std::string(file_data), file_contents); |
| 432 | 432 |
| 433 DestroyDownloadFile(0); | 433 DestroyDownloadFile(0); |
| 434 } | 434 } |
| 435 | 435 |
| 436 // Test to make sure the rename uniquifies if we aren't overwriting | 436 // Test to make sure the rename uniquifies if we aren't overwriting |
| 437 // and there's a file where we're aiming. | 437 // and there's a file where we're aiming. |
| 438 TEST_F(DownloadFileTest, RenameUniquifies) { | 438 TEST_F(DownloadFileTest, RenameUniquifies) { |
| 439 ASSERT_TRUE(CreateDownloadFile(0, true)); | 439 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 440 FilePath initial_path(download_file_->FullPath()); | 440 base::FilePath initial_path(download_file_->FullPath()); |
| 441 EXPECT_TRUE(file_util::PathExists(initial_path)); | 441 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 442 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); | 442 base::FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); |
| 443 FilePath path_1_suffixed(path_1.InsertBeforeExtensionASCII(" (1)")); | 443 base::FilePath path_1_suffixed(path_1.InsertBeforeExtensionASCII(" (1)")); |
| 444 | 444 |
| 445 ASSERT_FALSE(file_util::PathExists(path_1)); | 445 ASSERT_FALSE(file_util::PathExists(path_1)); |
| 446 static const char file_data[] = "xyzzy"; | 446 static const char file_data[] = "xyzzy"; |
| 447 ASSERT_EQ(static_cast<int>(sizeof(file_data)), | 447 ASSERT_EQ(static_cast<int>(sizeof(file_data)), |
| 448 file_util::WriteFile(path_1, file_data, sizeof(file_data))); | 448 file_util::WriteFile(path_1, file_data, sizeof(file_data))); |
| 449 ASSERT_TRUE(file_util::PathExists(path_1)); | 449 ASSERT_TRUE(file_util::PathExists(path_1)); |
| 450 | 450 |
| 451 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, RenameAndUniquify(path_1, NULL)); | 451 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, RenameAndUniquify(path_1, NULL)); |
| 452 EXPECT_TRUE(file_util::PathExists(path_1_suffixed)); | 452 EXPECT_TRUE(file_util::PathExists(path_1_suffixed)); |
| 453 | 453 |
| 454 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 454 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 455 loop_.RunUntilIdle(); | 455 loop_.RunUntilIdle(); |
| 456 DestroyDownloadFile(0); | 456 DestroyDownloadFile(0); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Test to make sure we get the proper error on failure. | 459 // Test to make sure we get the proper error on failure. |
| 460 TEST_F(DownloadFileTest, RenameError) { | 460 TEST_F(DownloadFileTest, RenameError) { |
| 461 ASSERT_TRUE(CreateDownloadFile(0, true)); | 461 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 462 FilePath initial_path(download_file_->FullPath()); | 462 base::FilePath initial_path(download_file_->FullPath()); |
| 463 | 463 |
| 464 // Create a subdirectory. | 464 // Create a subdirectory. |
| 465 FilePath tempdir(initial_path.DirName().Append(FILE_PATH_LITERAL("tempdir"))); | 465 base::FilePath tempdir( |
| 466 initial_path.DirName().Append(FILE_PATH_LITERAL("tempdir"))); |
| 466 ASSERT_TRUE(file_util::CreateDirectory(tempdir)); | 467 ASSERT_TRUE(file_util::CreateDirectory(tempdir)); |
| 467 FilePath target_path(tempdir.Append(initial_path.BaseName())); | 468 base::FilePath target_path(tempdir.Append(initial_path.BaseName())); |
| 468 | 469 |
| 469 // Targets | 470 // Targets |
| 470 FilePath target_path_suffixed(target_path.InsertBeforeExtensionASCII(" (1)")); | 471 base::FilePath target_path_suffixed( |
| 472 target_path.InsertBeforeExtensionASCII(" (1)")); |
| 471 ASSERT_FALSE(file_util::PathExists(target_path)); | 473 ASSERT_FALSE(file_util::PathExists(target_path)); |
| 472 ASSERT_FALSE(file_util::PathExists(target_path_suffixed)); | 474 ASSERT_FALSE(file_util::PathExists(target_path_suffixed)); |
| 473 | 475 |
| 474 // Make the directory unwritable and try to rename within it. | 476 // Make the directory unwritable and try to rename within it. |
| 475 { | 477 { |
| 476 file_util::PermissionRestorer restorer(tempdir); | 478 file_util::PermissionRestorer restorer(tempdir); |
| 477 ASSERT_TRUE(file_util::MakeFileUnwritable(tempdir)); | 479 ASSERT_TRUE(file_util::MakeFileUnwritable(tempdir)); |
| 478 | 480 |
| 479 // Expect nulling out of further processing. | 481 // Expect nulling out of further processing. |
| 480 EXPECT_CALL(*input_stream_, RegisterCallback(IsNullCallback())); | 482 EXPECT_CALL(*input_stream_, RegisterCallback(IsNullCallback())); |
| 481 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, | 483 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, |
| 482 RenameAndAnnotate(target_path, NULL)); | 484 RenameAndAnnotate(target_path, NULL)); |
| 483 EXPECT_FALSE(file_util::PathExists(target_path_suffixed)); | 485 EXPECT_FALSE(file_util::PathExists(target_path_suffixed)); |
| 484 } | 486 } |
| 485 | 487 |
| 486 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 488 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 487 loop_.RunUntilIdle(); | 489 loop_.RunUntilIdle(); |
| 488 DestroyDownloadFile(0); | 490 DestroyDownloadFile(0); |
| 489 } | 491 } |
| 490 | 492 |
| 491 // Various tests of the StreamActive method. | 493 // Various tests of the StreamActive method. |
| 492 TEST_F(DownloadFileTest, StreamEmptySuccess) { | 494 TEST_F(DownloadFileTest, StreamEmptySuccess) { |
| 493 ASSERT_TRUE(CreateDownloadFile(0, true)); | 495 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 494 FilePath initial_path(download_file_->FullPath()); | 496 base::FilePath initial_path(download_file_->FullPath()); |
| 495 EXPECT_TRUE(file_util::PathExists(initial_path)); | 497 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 496 | 498 |
| 497 // Test that calling the sink_callback_ on an empty stream shouldn't | 499 // Test that calling the sink_callback_ on an empty stream shouldn't |
| 498 // do anything. | 500 // do anything. |
| 499 AppendDataToFile(NULL, 0); | 501 AppendDataToFile(NULL, 0); |
| 500 | 502 |
| 501 // Finish the download this way and make sure we see it on the | 503 // Finish the download this way and make sure we see it on the |
| 502 // observer. | 504 // observer. |
| 503 EXPECT_CALL(*(observer_.get()), DestinationCompleted(_)); | 505 EXPECT_CALL(*(observer_.get()), DestinationCompleted(_)); |
| 504 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, false); | 506 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, false); |
| 505 loop_.RunUntilIdle(); | 507 loop_.RunUntilIdle(); |
| 506 | 508 |
| 507 DestroyDownloadFile(0); | 509 DestroyDownloadFile(0); |
| 508 } | 510 } |
| 509 | 511 |
| 510 TEST_F(DownloadFileTest, StreamEmptyError) { | 512 TEST_F(DownloadFileTest, StreamEmptyError) { |
| 511 ASSERT_TRUE(CreateDownloadFile(0, true)); | 513 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 512 FilePath initial_path(download_file_->FullPath()); | 514 base::FilePath initial_path(download_file_->FullPath()); |
| 513 EXPECT_TRUE(file_util::PathExists(initial_path)); | 515 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 514 | 516 |
| 515 // Finish the download in error and make sure we see it on the | 517 // Finish the download in error and make sure we see it on the |
| 516 // observer. | 518 // observer. |
| 517 EXPECT_CALL(*(observer_.get()), | 519 EXPECT_CALL(*(observer_.get()), |
| 518 DestinationError( | 520 DestinationError( |
| 519 DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)) | 521 DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)) |
| 520 .WillOnce(InvokeWithoutArgs( | 522 .WillOnce(InvokeWithoutArgs( |
| 521 this, &DownloadFileTest::ConfirmUpdateDownloadInfo)); | 523 this, &DownloadFileTest::ConfirmUpdateDownloadInfo)); |
| 522 | 524 |
| 523 // If this next EXPECT_CALL fails flakily, it's probably a real failure. | 525 // If this next EXPECT_CALL fails flakily, it's probably a real failure. |
| 524 // We'll be getting a stream of UpdateDownload calls from the timer, and | 526 // We'll be getting a stream of UpdateDownload calls from the timer, and |
| 525 // the last one may have the correct information even if the failure | 527 // the last one may have the correct information even if the failure |
| 526 // doesn't produce an update, as the timer update may have triggered at the | 528 // doesn't produce an update, as the timer update may have triggered at the |
| 527 // same time. | 529 // same time. |
| 528 EXPECT_CALL(*(observer_.get()), CurrentUpdateStatus(0, _, _)); | 530 EXPECT_CALL(*(observer_.get()), CurrentUpdateStatus(0, _, _)); |
| 529 | 531 |
| 530 FinishStream(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, false); | 532 FinishStream(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, false); |
| 531 | 533 |
| 532 loop_.RunUntilIdle(); | 534 loop_.RunUntilIdle(); |
| 533 | 535 |
| 534 DestroyDownloadFile(0); | 536 DestroyDownloadFile(0); |
| 535 } | 537 } |
| 536 | 538 |
| 537 TEST_F(DownloadFileTest, StreamNonEmptySuccess) { | 539 TEST_F(DownloadFileTest, StreamNonEmptySuccess) { |
| 538 ASSERT_TRUE(CreateDownloadFile(0, true)); | 540 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 539 FilePath initial_path(download_file_->FullPath()); | 541 base::FilePath initial_path(download_file_->FullPath()); |
| 540 EXPECT_TRUE(file_util::PathExists(initial_path)); | 542 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 541 | 543 |
| 542 const char* chunks1[] = { kTestData1, kTestData2 }; | 544 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 543 ::testing::Sequence s1; | 545 ::testing::Sequence s1; |
| 544 SetupDataAppend(chunks1, 2, s1); | 546 SetupDataAppend(chunks1, 2, s1); |
| 545 SetupFinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, s1); | 547 SetupFinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, s1); |
| 546 EXPECT_CALL(*(observer_.get()), DestinationCompleted(_)); | 548 EXPECT_CALL(*(observer_.get()), DestinationCompleted(_)); |
| 547 sink_callback_.Run(); | 549 sink_callback_.Run(); |
| 548 VerifyStreamAndSize(); | 550 VerifyStreamAndSize(); |
| 549 loop_.RunUntilIdle(); | 551 loop_.RunUntilIdle(); |
| 550 DestroyDownloadFile(0); | 552 DestroyDownloadFile(0); |
| 551 } | 553 } |
| 552 | 554 |
| 553 TEST_F(DownloadFileTest, StreamNonEmptyError) { | 555 TEST_F(DownloadFileTest, StreamNonEmptyError) { |
| 554 ASSERT_TRUE(CreateDownloadFile(0, true)); | 556 ASSERT_TRUE(CreateDownloadFile(0, true)); |
| 555 FilePath initial_path(download_file_->FullPath()); | 557 base::FilePath initial_path(download_file_->FullPath()); |
| 556 EXPECT_TRUE(file_util::PathExists(initial_path)); | 558 EXPECT_TRUE(file_util::PathExists(initial_path)); |
| 557 | 559 |
| 558 const char* chunks1[] = { kTestData1, kTestData2 }; | 560 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 559 ::testing::Sequence s1; | 561 ::testing::Sequence s1; |
| 560 SetupDataAppend(chunks1, 2, s1); | 562 SetupDataAppend(chunks1, 2, s1); |
| 561 SetupFinishStream(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, s1); | 563 SetupFinishStream(DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, s1); |
| 562 | 564 |
| 563 EXPECT_CALL(*(observer_.get()), | 565 EXPECT_CALL(*(observer_.get()), |
| 564 DestinationError( | 566 DestinationError( |
| 565 DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)) | 567 DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 596 | 598 |
| 597 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), | 599 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), |
| 598 bytes_); | 600 bytes_); |
| 599 EXPECT_EQ(download_file_->GetHashState(), hash_state_); | 601 EXPECT_EQ(download_file_->GetHashState(), hash_state_); |
| 600 | 602 |
| 601 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 603 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 602 DestroyDownloadFile(0); | 604 DestroyDownloadFile(0); |
| 603 } | 605 } |
| 604 | 606 |
| 605 } // namespace content | 607 } // namespace content |
| OLD | NEW |