| 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "base/threading/thread.h" | 7 #include "base/threading/thread.h" |
| 8 #include "content/browser/download/byte_stream.h" | 8 #include "content/browser/download/byte_stream.h" |
| 9 #include "content/browser/download/download_create_info.h" | 9 #include "content/browser/download/download_create_info.h" |
| 10 #include "content/browser/download/download_file_manager.h" | 10 #include "content/browser/download/download_file_manager.h" |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 401 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 402 intermediate_path); | 402 intermediate_path); |
| 403 RunAllPendingInMessageLoops(); | 403 RunAllPendingInMessageLoops(); |
| 404 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), | 404 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), |
| 405 item->GetFileNameToReportUser().value()); | 405 item->GetFileNameToReportUser().value()); |
| 406 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); | 406 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); |
| 407 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), | 407 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), |
| 408 item->GetFileNameToReportUser().value()); | 408 item->GetFileNameToReportUser().value()); |
| 409 } | 409 } |
| 410 | 410 |
| 411 static char external_data_test_string[] = "External data test"; | |
| 412 static int destructor_called = 0; | |
| 413 | |
| 414 class TestExternalData : public DownloadItem::ExternalData { | |
| 415 public: | |
| 416 int value; | |
| 417 virtual ~TestExternalData() { | |
| 418 destructor_called++; | |
| 419 } | |
| 420 }; | |
| 421 | |
| 422 TEST_F(DownloadItemTest, ExternalData) { | |
| 423 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | |
| 424 const DownloadItemImpl* const_item = item; | |
| 425 | |
| 426 // Shouldn't be anything there before set. | |
| 427 EXPECT_EQ(NULL, item->GetExternalData(&external_data_test_string)); | |
| 428 EXPECT_EQ(NULL, const_item->GetExternalData(&external_data_test_string)); | |
| 429 | |
| 430 TestExternalData* test1(new TestExternalData()); | |
| 431 test1->value = 2; | |
| 432 | |
| 433 // Should be able to get back what you set. | |
| 434 item->SetExternalData(&external_data_test_string, test1); | |
| 435 TestExternalData* test_result = | |
| 436 static_cast<TestExternalData*>( | |
| 437 item->GetExternalData(&external_data_test_string)); | |
| 438 EXPECT_EQ(test1, test_result); | |
| 439 | |
| 440 // Ditto for const lookup. | |
| 441 const TestExternalData* test_const_result = | |
| 442 static_cast<const TestExternalData*>( | |
| 443 const_item->GetExternalData(&external_data_test_string)); | |
| 444 EXPECT_EQ(static_cast<const TestExternalData*>(test1), | |
| 445 test_const_result); | |
| 446 | |
| 447 // Destructor should be called if value overwritten. New value | |
| 448 // should then be retrievable. | |
| 449 TestExternalData* test2(new TestExternalData()); | |
| 450 test2->value = 3; | |
| 451 EXPECT_EQ(0, destructor_called); | |
| 452 item->SetExternalData(&external_data_test_string, test2); | |
| 453 EXPECT_EQ(1, destructor_called); | |
| 454 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test2), | |
| 455 item->GetExternalData(&external_data_test_string)); | |
| 456 | |
| 457 // Overwriting with the same value shouldn't do anything. | |
| 458 EXPECT_EQ(1, destructor_called); | |
| 459 item->SetExternalData(&external_data_test_string, test2); | |
| 460 EXPECT_EQ(1, destructor_called); | |
| 461 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test2), | |
| 462 item->GetExternalData(&external_data_test_string)); | |
| 463 | |
| 464 // Overwriting with NULL should result in destruction. | |
| 465 item->SetExternalData(&external_data_test_string, NULL); | |
| 466 EXPECT_EQ(2, destructor_called); | |
| 467 | |
| 468 // Destroying the download item should destroy the external data. | |
| 469 | |
| 470 TestExternalData* test3(new TestExternalData()); | |
| 471 item->SetExternalData(&external_data_test_string, test3); | |
| 472 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test3), | |
| 473 item->GetExternalData(&external_data_test_string)); | |
| 474 DestroyDownloadItem(item); | |
| 475 EXPECT_EQ(3, destructor_called); | |
| 476 } | |
| 477 | |
| 478 // Test that the delegate is invoked after the download file is renamed. | 411 // Test that the delegate is invoked after the download file is renamed. |
| 479 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the | 412 // Delegate::DownloadRenamedToIntermediateName() should be invoked when the |
| 480 // download is renamed to the intermediate name. | 413 // download is renamed to the intermediate name. |
| 481 // Delegate::DownloadRenamedToFinalName() should be invoked after the final | 414 // Delegate::DownloadRenamedToFinalName() should be invoked after the final |
| 482 // rename. | 415 // rename. |
| 483 TEST_F(DownloadItemTest, CallbackAfterRename) { | 416 TEST_F(DownloadItemTest, CallbackAfterRename) { |
| 484 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 417 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 485 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); | 418 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); |
| 486 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 419 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 487 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); | 420 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 496 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 564 | 497 |
| 565 EXPECT_FALSE(item->GetFileExternallyRemoved()); | 498 EXPECT_FALSE(item->GetFileExternallyRemoved()); |
| 566 item->OnDownloadedFileRemoved(); | 499 item->OnDownloadedFileRemoved(); |
| 567 EXPECT_TRUE(item->GetFileExternallyRemoved()); | 500 EXPECT_TRUE(item->GetFileExternallyRemoved()); |
| 568 } | 501 } |
| 569 | 502 |
| 570 TEST(MockDownloadItem, Compiles) { | 503 TEST(MockDownloadItem, Compiles) { |
| 571 MockDownloadItem mock_item; | 504 MockDownloadItem mock_item; |
| 572 } | 505 } |
| OLD | NEW |