| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "chrome/browser/download/download_request_limiter.h" | 7 #include "chrome/browser/download/download_request_limiter.h" |
| 8 #include "chrome/browser/download/download_resource_throttle.h" | 8 #include "chrome/browser/download/download_resource_throttle.h" |
| 9 #include "chrome/browser/tab_contents/tab_util.h" | 9 #include "chrome/browser/tab_contents/tab_util.h" |
| 10 #include "chrome/common/features.h" | 10 #include "chrome/common/features.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/resource_controller.h" | 14 #include "content/public/browser/resource_controller.h" |
| 15 #include "content/public/browser/resource_throttle.h" | 15 #include "content/public/browser/resource_throttle.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 #if BUILDFLAG(ANDROID_JAVA_UI) | 22 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 23 #include "chrome/browser/android/download/mock_download_controller_android.h" | 23 #include "chrome/browser/android/download/mock_download_controller.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kTestUrl[] = "http://www.example.com/"; | 28 const char kTestUrl[] = "http://www.example.com/"; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 class MockWebContentsDelegate : public content::WebContentsDelegate { | 32 class MockWebContentsDelegate : public content::WebContentsDelegate { |
| 33 public: | 33 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); | 57 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); |
| 58 } | 58 } |
| 59 | 59 |
| 60 ~DownloadResourceThrottleTest() override {} | 60 ~DownloadResourceThrottleTest() override {} |
| 61 | 61 |
| 62 void SetUp() override { | 62 void SetUp() override { |
| 63 ChromeRenderViewHostTestHarness::SetUp(); | 63 ChromeRenderViewHostTestHarness::SetUp(); |
| 64 web_contents()->SetDelegate(&delegate_); | 64 web_contents()->SetDelegate(&delegate_); |
| 65 run_loop_.reset(new base::RunLoop()); | 65 run_loop_.reset(new base::RunLoop()); |
| 66 #if BUILDFLAG(ANDROID_JAVA_UI) | 66 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 67 content::DownloadControllerAndroid::SetDownloadControllerAndroid( | 67 DownloadControllerBase::SetDownloadControllerBase(&download_controller_); |
| 68 &download_controller_); | |
| 69 #endif | 68 #endif |
| 70 } | 69 } |
| 71 | 70 |
| 72 void TearDown() override { | 71 void TearDown() override { |
| 73 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 72 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| 74 throttle_); | 73 throttle_); |
| 75 #if BUILDFLAG(ANDROID_JAVA_UI) | 74 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 76 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); | 75 DownloadControllerBase::SetDownloadControllerBase(nullptr); |
| 77 #endif | 76 #endif |
| 78 ChromeRenderViewHostTestHarness::TearDown(); | 77 ChromeRenderViewHostTestHarness::TearDown(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 void StartThrottleOnIOThread(int process_id, int render_view_id) { | 80 void StartThrottleOnIOThread(int process_id, int render_view_id) { |
| 82 throttle_ = new DownloadResourceThrottle( | 81 throttle_ = new DownloadResourceThrottle( |
| 83 limiter_, | 82 limiter_, |
| 84 base::Bind(&tab_util::GetWebContentsByID, process_id, render_view_id), | 83 base::Bind(&tab_util::GetWebContentsByID, process_id, render_view_id), |
| 85 GURL(kTestUrl), "GET"); | 84 GURL(kTestUrl), "GET"); |
| 86 throttle_->set_controller_for_testing(&resource_controller_); | 85 throttle_->set_controller_for_testing(&resource_controller_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 99 run_loop_->Run(); | 98 run_loop_->Run(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 protected: | 101 protected: |
| 103 content::ResourceThrottle* throttle_; | 102 content::ResourceThrottle* throttle_; |
| 104 MockWebContentsDelegate delegate_; | 103 MockWebContentsDelegate delegate_; |
| 105 scoped_refptr<DownloadRequestLimiter> limiter_; | 104 scoped_refptr<DownloadRequestLimiter> limiter_; |
| 106 ::testing::NiceMock<MockResourceController> resource_controller_; | 105 ::testing::NiceMock<MockResourceController> resource_controller_; |
| 107 std::unique_ptr<base::RunLoop> run_loop_; | 106 std::unique_ptr<base::RunLoop> run_loop_; |
| 108 #if BUILDFLAG(ANDROID_JAVA_UI) | 107 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 109 chrome::android::MockDownloadControllerAndroid download_controller_; | 108 chrome::android::MockDownloadController download_controller_; |
| 110 #endif | 109 #endif |
| 111 }; | 110 }; |
| 112 | 111 |
| 113 TEST_F(DownloadResourceThrottleTest, StartDownloadThrottle_Basic) { | 112 TEST_F(DownloadResourceThrottleTest, StartDownloadThrottle_Basic) { |
| 114 EXPECT_CALL(resource_controller_, Resume()) | 113 EXPECT_CALL(resource_controller_, Resume()) |
| 115 .WillOnce(QuitLoop(run_loop_->QuitClosure())); | 114 .WillOnce(QuitLoop(run_loop_->QuitClosure())); |
| 116 StartThrottle(); | 115 StartThrottle(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 #if BUILDFLAG(ANDROID_JAVA_UI) | 118 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 120 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) { | 119 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) { |
| 121 content::DownloadControllerAndroid::Get() | 120 DownloadControllerBase::Get() |
| 122 ->SetApproveFileAccessRequestForTesting(false); | 121 ->SetApproveFileAccessRequestForTesting(false); |
| 123 EXPECT_CALL(resource_controller_, Cancel()) | 122 EXPECT_CALL(resource_controller_, Cancel()) |
| 124 .WillOnce(QuitLoop(run_loop_->QuitClosure())); | 123 .WillOnce(QuitLoop(run_loop_->QuitClosure())); |
| 125 StartThrottle(); | 124 StartThrottle(); |
| 126 } | 125 } |
| 127 #endif | 126 #endif |
| OLD | NEW |