| 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/files/file.h" | 5 #include "base/files/file.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/location.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/test/test_file_util.h" | 10 #include "base/test/test_file_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | |
| 13 #include "content/browser/browser_thread_impl.h" | 11 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/byte_stream.h" | 12 #include "content/browser/byte_stream.h" |
| 15 #include "content/browser/download/download_create_info.h" | 13 #include "content/browser/download/download_create_info.h" |
| 16 #include "content/browser/download/download_file_impl.h" | 14 #include "content/browser/download/download_file_impl.h" |
| 17 #include "content/browser/download/download_request_handle.h" | 15 #include "content/browser/download/download_request_handle.h" |
| 18 #include "content/public/browser/download_destination_observer.h" | 16 #include "content/public/browser/download_destination_observer.h" |
| 19 #include "content/public/browser/download_interrupt_reasons.h" | 17 #include "content/public/browser/download_interrupt_reasons.h" |
| 20 #include "content/public/browser/download_manager.h" | 18 #include "content/public/browser/download_manager.h" |
| 21 #include "content/public/test/mock_download_manager.h" | 19 #include "content/public/test/mock_download_manager.h" |
| 22 #include "net/base/file_stream.h" | 20 #include "net/base/file_stream.h" |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 base::Bind(&TestRenameCompletionCallback, | 643 base::Bind(&TestRenameCompletionCallback, |
| 646 succeeding_run.QuitClosure(), | 644 succeeding_run.QuitClosure(), |
| 647 &did_run_callback)); | 645 &did_run_callback)); |
| 648 EXPECT_FALSE(did_run_callback); | 646 EXPECT_FALSE(did_run_callback); |
| 649 | 647 |
| 650 base::RunLoop first_failing_run; | 648 base::RunLoop first_failing_run; |
| 651 // Queue the QuitClosure() on the MessageLoop now. Any tasks queued by the | 649 // Queue the QuitClosure() on the MessageLoop now. Any tasks queued by the |
| 652 // Rename() will be in front of the QuitClosure(). Running the message loop | 650 // Rename() will be in front of the QuitClosure(). Running the message loop |
| 653 // now causes the just the first retry task to be run. The rename still | 651 // now causes the just the first retry task to be run. The rename still |
| 654 // fails, so another retry task would get queued behind the QuitClosure(). | 652 // fails, so another retry task would get queued behind the QuitClosure(). |
| 655 base::ThreadTaskRunnerHandle::Get()->PostTask( | 653 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 656 FROM_HERE, first_failing_run.QuitClosure()); | 654 first_failing_run.QuitClosure()); |
| 657 first_failing_run.Run(); | 655 first_failing_run.Run(); |
| 658 EXPECT_FALSE(did_run_callback); | 656 EXPECT_FALSE(did_run_callback); |
| 659 | 657 |
| 660 // Running another loop should have the same effect as the above as long as | 658 // Running another loop should have the same effect as the above as long as |
| 661 // kMaxRenameRetries is greater than 2. | 659 // kMaxRenameRetries is greater than 2. |
| 662 base::RunLoop second_failing_run; | 660 base::RunLoop second_failing_run; |
| 663 base::ThreadTaskRunnerHandle::Get()->PostTask( | 661 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 664 FROM_HERE, second_failing_run.QuitClosure()); | 662 second_failing_run.QuitClosure()); |
| 665 second_failing_run.Run(); | 663 second_failing_run.Run(); |
| 666 EXPECT_FALSE(did_run_callback); | 664 EXPECT_FALSE(did_run_callback); |
| 667 } | 665 } |
| 668 | 666 |
| 669 // This time the QuitClosure from succeeding_run should get executed. | 667 // This time the QuitClosure from succeeding_run should get executed. |
| 670 succeeding_run.Run(); | 668 succeeding_run.Run(); |
| 671 EXPECT_TRUE(did_run_callback); | 669 EXPECT_TRUE(did_run_callback); |
| 672 | 670 |
| 673 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 671 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 674 loop_.RunUntilIdle(); | 672 loop_.RunUntilIdle(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 768 |
| 771 // Send some data, wait 3/4s of a second, run the message loop, and | 769 // Send some data, wait 3/4s of a second, run the message loop, and |
| 772 // confirm the values the observer received are correct. | 770 // confirm the values the observer received are correct. |
| 773 TEST_F(DownloadFileTest, ConfirmUpdate) { | 771 TEST_F(DownloadFileTest, ConfirmUpdate) { |
| 774 CreateDownloadFile(0, true); | 772 CreateDownloadFile(0, true); |
| 775 | 773 |
| 776 const char* chunks1[] = { kTestData1, kTestData2 }; | 774 const char* chunks1[] = { kTestData1, kTestData2 }; |
| 777 AppendDataToFile(chunks1, 2); | 775 AppendDataToFile(chunks1, 2); |
| 778 | 776 |
| 779 // Run the message loops for 750ms and check for results. | 777 // Run the message loops for 750ms and check for results. |
| 780 loop_.task_runner()->PostDelayedTask(FROM_HERE, | 778 loop_.PostDelayedTask(FROM_HERE, |
| 781 base::MessageLoop::QuitClosure(), | 779 base::MessageLoop::QuitClosure(), |
| 782 base::TimeDelta::FromMilliseconds(750)); | 780 base::TimeDelta::FromMilliseconds(750)); |
| 783 loop_.Run(); | 781 loop_.Run(); |
| 784 | 782 |
| 785 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), | 783 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), |
| 786 bytes_); | 784 bytes_); |
| 787 EXPECT_EQ(download_file_->GetHashState(), hash_state_); | 785 EXPECT_EQ(download_file_->GetHashState(), hash_state_); |
| 788 | 786 |
| 789 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 787 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 790 DestroyDownloadFile(0); | 788 DestroyDownloadFile(0); |
| 791 } | 789 } |
| 792 | 790 |
| 793 } // namespace content | 791 } // namespace content |
| OLD | NEW |