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/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_controller.h" |
13 #include "content/public/browser/resource_throttle.h" | 14 #include "content/public/browser/resource_throttle.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_delegate.h" | 16 #include "content/public/browser/web_contents_delegate.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 72 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
72 throttle_); | 73 throttle_); |
73 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
74 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); | 75 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); |
75 #endif | 76 #endif |
76 ChromeRenderViewHostTestHarness::TearDown(); | 77 ChromeRenderViewHostTestHarness::TearDown(); |
77 } | 78 } |
78 | 79 |
79 void StartThrottleOnIOThread(int process_id, int render_view_id) { | 80 void StartThrottleOnIOThread(int process_id, int render_view_id) { |
80 throttle_ = new DownloadResourceThrottle( | 81 throttle_ = new DownloadResourceThrottle( |
81 limiter_, process_id, render_view_id, GURL(kTestUrl), "GET"); | 82 limiter_, |
| 83 base::Bind(&tab_util::GetWebContentsByID, process_id, render_view_id), |
| 84 GURL(kTestUrl), "GET"); |
82 throttle_->set_controller_for_testing(&resource_controller_); | 85 throttle_->set_controller_for_testing(&resource_controller_); |
83 bool defer; | 86 bool defer; |
84 throttle_->WillStartRequest(&defer); | 87 throttle_->WillStartRequest(&defer); |
85 EXPECT_EQ(true, defer); | 88 EXPECT_EQ(true, defer); |
86 } | 89 } |
87 | 90 |
88 void StartThrottle() { | 91 void StartThrottle() { |
89 content::BrowserThread::PostTask( | 92 content::BrowserThread::PostTask( |
90 content::BrowserThread::IO, FROM_HERE, | 93 content::BrowserThread::IO, FROM_HERE, |
91 base::Bind(&DownloadResourceThrottleTest::StartThrottleOnIOThread, | 94 base::Bind(&DownloadResourceThrottleTest::StartThrottleOnIOThread, |
(...skipping 22 matching lines...) Expand all Loading... |
114 | 117 |
115 #if defined(OS_ANDROID) | 118 #if defined(OS_ANDROID) |
116 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) { | 119 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) { |
117 content::DownloadControllerAndroid::Get() | 120 content::DownloadControllerAndroid::Get() |
118 ->SetApproveFileAccessRequestForTesting(false); | 121 ->SetApproveFileAccessRequestForTesting(false); |
119 EXPECT_CALL(resource_controller_, Cancel()) | 122 EXPECT_CALL(resource_controller_, Cancel()) |
120 .WillOnce(QuitLoop(run_loop_->QuitClosure())); | 123 .WillOnce(QuitLoop(run_loop_->QuitClosure())); |
121 StartThrottle(); | 124 StartThrottle(); |
122 } | 125 } |
123 #endif | 126 #endif |
OLD | NEW |