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