Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/download/download_resource_throttle_unittest.cc

Issue 1467563002: Use ResourceRequestInfo::GetWebContents in DownloadRequestLimiter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-contents-callback
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 29 matching lines...) Expand all
40 MOCK_METHOD1(CancelWithError, void(int)); 40 MOCK_METHOD1(CancelWithError, void(int));
41 MOCK_METHOD0(Resume, void()); 41 MOCK_METHOD0(Resume, void());
42 }; 42 };
43 43
44 // Posts |quit_closure| to UI thread. 44 // Posts |quit_closure| to UI thread.
45 ACTION_P(QuitLoop, quit_closure) { 45 ACTION_P(QuitLoop, quit_closure) {
46 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 46 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
47 quit_closure); 47 quit_closure);
48 } 48 }
49 49
50 content::WebContents* GetWebContents(int process_id, int render_view_id) {
51 content::RenderViewHost* render_view_host =
52 content::RenderViewHost::FromID(process_id, render_view_id);
53 if (!render_view_host)
54 return nullptr;
55 return content::WebContents::FromRenderViewHost(render_view_host);
56 }
57
50 class DownloadResourceThrottleTest : public ChromeRenderViewHostTestHarness { 58 class DownloadResourceThrottleTest : public ChromeRenderViewHostTestHarness {
51 public: 59 public:
52 DownloadResourceThrottleTest() 60 DownloadResourceThrottleTest()
53 : throttle_(nullptr), limiter_(new DownloadRequestLimiter()) { 61 : throttle_(nullptr), limiter_(new DownloadRequestLimiter()) {
54 // Cannot use IO_MAIN_LOOP with RenderViewHostTestHarness. 62 // Cannot use IO_MAIN_LOOP with RenderViewHostTestHarness.
55 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); 63 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
56 } 64 }
57 65
58 ~DownloadResourceThrottleTest() override {} 66 ~DownloadResourceThrottleTest() override {}
59 67
(...skipping 11 matching lines...) Expand all
71 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, 79 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
72 throttle_); 80 throttle_);
73 #if defined(OS_ANDROID) 81 #if defined(OS_ANDROID)
74 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); 82 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr);
75 #endif 83 #endif
76 ChromeRenderViewHostTestHarness::TearDown(); 84 ChromeRenderViewHostTestHarness::TearDown();
77 } 85 }
78 86
79 void StartThrottleOnIOThread(int process_id, int render_view_id) { 87 void StartThrottleOnIOThread(int process_id, int render_view_id) {
80 throttle_ = new DownloadResourceThrottle( 88 throttle_ = new DownloadResourceThrottle(
81 limiter_, process_id, render_view_id, GURL(kTestUrl), "GET"); 89 limiter_, base::Bind(&GetWebContents, process_id, render_view_id),
davidben 2015/11/24 15:51:16 There's a tab_util::GetWebContentsByID you could u
clamy 2015/11/25 14:02:02 Done.
90 GURL(kTestUrl), "GET");
82 throttle_->set_controller_for_testing(&resource_controller_); 91 throttle_->set_controller_for_testing(&resource_controller_);
83 bool defer; 92 bool defer;
84 throttle_->WillStartRequest(&defer); 93 throttle_->WillStartRequest(&defer);
85 EXPECT_EQ(true, defer); 94 EXPECT_EQ(true, defer);
86 } 95 }
87 96
88 void StartThrottle() { 97 void StartThrottle() {
89 content::BrowserThread::PostTask( 98 content::BrowserThread::PostTask(
90 content::BrowserThread::IO, FROM_HERE, 99 content::BrowserThread::IO, FROM_HERE,
91 base::Bind(&DownloadResourceThrottleTest::StartThrottleOnIOThread, 100 base::Bind(&DownloadResourceThrottleTest::StartThrottleOnIOThread,
(...skipping 22 matching lines...) Expand all
114 123
115 #if defined(OS_ANDROID) 124 #if defined(OS_ANDROID)
116 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) { 125 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) {
117 content::DownloadControllerAndroid::Get() 126 content::DownloadControllerAndroid::Get()
118 ->SetApproveFileAccessRequestForTesting(false); 127 ->SetApproveFileAccessRequestForTesting(false);
119 EXPECT_CALL(resource_controller_, Cancel()) 128 EXPECT_CALL(resource_controller_, Cancel())
120 .WillOnce(QuitLoop(run_loop_->QuitClosure())); 129 .WillOnce(QuitLoop(run_loop_->QuitClosure()));
121 StartThrottle(); 130 StartThrottle();
122 } 131 }
123 #endif 132 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698