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

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

Issue 1459793002: Android: Allow compiling browser without Java UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/browser/tab_contents/tab_util.h" 9 #include "chrome/browser/tab_contents/tab_util.h"
10 #include "chrome/common/features.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/resource_controller.h" 14 #include "content/public/browser/resource_controller.h"
14 #include "content/public/browser/resource_throttle.h" 15 #include "content/public/browser/resource_throttle.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h" 17 #include "content/public/browser/web_contents_delegate.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 #if defined(OS_ANDROID) 22 #if BUILDFLAG(ANDROID_JAVA_UI)
22 #include "chrome/browser/android/download/mock_download_controller_android.h" 23 #include "chrome/browser/android/download/mock_download_controller_android.h"
23 #endif 24 #endif
24 25
25 namespace { 26 namespace {
26 27
27 const char kTestUrl[] = "http://www.example.com/"; 28 const char kTestUrl[] = "http://www.example.com/";
28 29
29 } // namespace 30 } // namespace
30 31
31 class MockWebContentsDelegate : public content::WebContentsDelegate { 32 class MockWebContentsDelegate : public content::WebContentsDelegate {
(...skipping 23 matching lines...) Expand all
55 // Cannot use IO_MAIN_LOOP with RenderViewHostTestHarness. 56 // Cannot use IO_MAIN_LOOP with RenderViewHostTestHarness.
56 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); 57 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
57 } 58 }
58 59
59 ~DownloadResourceThrottleTest() override {} 60 ~DownloadResourceThrottleTest() override {}
60 61
61 void SetUp() override { 62 void SetUp() override {
62 ChromeRenderViewHostTestHarness::SetUp(); 63 ChromeRenderViewHostTestHarness::SetUp();
63 web_contents()->SetDelegate(&delegate_); 64 web_contents()->SetDelegate(&delegate_);
64 run_loop_.reset(new base::RunLoop()); 65 run_loop_.reset(new base::RunLoop());
65 #if defined(OS_ANDROID) 66 #if BUILDFLAG(ANDROID_JAVA_UI)
66 content::DownloadControllerAndroid::SetDownloadControllerAndroid( 67 content::DownloadControllerAndroid::SetDownloadControllerAndroid(
67 &download_controller_); 68 &download_controller_);
68 #endif 69 #endif
69 } 70 }
70 71
71 void TearDown() override { 72 void TearDown() override {
72 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, 73 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
73 throttle_); 74 throttle_);
74 #if defined(OS_ANDROID) 75 #if BUILDFLAG(ANDROID_JAVA_UI)
75 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); 76 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr);
76 #endif 77 #endif
77 ChromeRenderViewHostTestHarness::TearDown(); 78 ChromeRenderViewHostTestHarness::TearDown();
78 } 79 }
79 80
80 void StartThrottleOnIOThread(int process_id, int render_view_id) { 81 void StartThrottleOnIOThread(int process_id, int render_view_id) {
81 throttle_ = new DownloadResourceThrottle( 82 throttle_ = new DownloadResourceThrottle(
82 limiter_, 83 limiter_,
83 base::Bind(&tab_util::GetWebContentsByID, process_id, render_view_id), 84 base::Bind(&tab_util::GetWebContentsByID, process_id, render_view_id),
84 GURL(kTestUrl), "GET"); 85 GURL(kTestUrl), "GET");
(...skipping 12 matching lines...) Expand all
97 web_contents()->GetRoutingID())); 98 web_contents()->GetRoutingID()));
98 run_loop_->Run(); 99 run_loop_->Run();
99 } 100 }
100 101
101 protected: 102 protected:
102 content::ResourceThrottle* throttle_; 103 content::ResourceThrottle* throttle_;
103 MockWebContentsDelegate delegate_; 104 MockWebContentsDelegate delegate_;
104 scoped_refptr<DownloadRequestLimiter> limiter_; 105 scoped_refptr<DownloadRequestLimiter> limiter_;
105 ::testing::NiceMock<MockResourceController> resource_controller_; 106 ::testing::NiceMock<MockResourceController> resource_controller_;
106 scoped_ptr<base::RunLoop> run_loop_; 107 scoped_ptr<base::RunLoop> run_loop_;
107 #if defined(OS_ANDROID) 108 #if BUILDFLAG(ANDROID_JAVA_UI)
108 chrome::android::MockDownloadControllerAndroid download_controller_; 109 chrome::android::MockDownloadControllerAndroid download_controller_;
109 #endif 110 #endif
110 }; 111 };
111 112
112 TEST_F(DownloadResourceThrottleTest, StartDownloadThrottle_Basic) { 113 TEST_F(DownloadResourceThrottleTest, StartDownloadThrottle_Basic) {
113 EXPECT_CALL(resource_controller_, Resume()) 114 EXPECT_CALL(resource_controller_, Resume())
114 .WillOnce(QuitLoop(run_loop_->QuitClosure())); 115 .WillOnce(QuitLoop(run_loop_->QuitClosure()));
115 StartThrottle(); 116 StartThrottle();
116 } 117 }
117 118
118 #if defined(OS_ANDROID) 119 #if BUILDFLAG(ANDROID_JAVA_UI)
119 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) { 120 TEST_F(DownloadResourceThrottleTest, DownloadWithFailedFileAcecssRequest) {
120 content::DownloadControllerAndroid::Get() 121 content::DownloadControllerAndroid::Get()
121 ->SetApproveFileAccessRequestForTesting(false); 122 ->SetApproveFileAccessRequestForTesting(false);
122 EXPECT_CALL(resource_controller_, Cancel()) 123 EXPECT_CALL(resource_controller_, Cancel())
123 .WillOnce(QuitLoop(run_loop_->QuitClosure())); 124 .WillOnce(QuitLoop(run_loop_->QuitClosure()));
124 StartThrottle(); 125 StartThrottle();
125 } 126 }
126 #endif 127 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698