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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jyasskin's comments\ Created 7 years, 7 months 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 | Annotate | Revision Log
OLDNEW
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_path.h" 5 #include "base/files/file_path.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/browser/download/chrome_download_manager_delegate.h" 10 #include "chrome/browser/download/chrome_download_manager_delegate.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 private: 161 private:
162 void OnDownloadTargetDone(DownloadTarget* result, 162 void OnDownloadTargetDone(DownloadTarget* result,
163 const base::FilePath& target_path, 163 const base::FilePath& target_path,
164 DownloadItem::TargetDisposition disposition, 164 DownloadItem::TargetDisposition disposition,
165 content::DownloadDangerType danger_type, 165 content::DownloadDangerType danger_type,
166 const base::FilePath& intermediate_path); 166 const base::FilePath& intermediate_path);
167 167
168 TestingPrefServiceSyncable* pref_service_; 168 TestingPrefServiceSyncable* pref_service_;
169 base::ScopedTempDir test_download_dir_; 169 base::ScopedTempDir test_download_dir_;
170 content::TestBrowserThread ui_thread_;
171 content::TestBrowserThread file_thread_;
172 scoped_refptr<content::MockDownloadManager> download_manager_; 170 scoped_refptr<content::MockDownloadManager> download_manager_;
173 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; 171 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_;
174 MockWebContentsDelegate web_contents_delegate_; 172 MockWebContentsDelegate web_contents_delegate_;
175 }; 173 };
176 174
177 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() 175 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest()
178 : ChromeRenderViewHostTestHarness(), 176 : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) {
179 ui_thread_(content::BrowserThread::UI, &message_loop_),
180 file_thread_(content::BrowserThread::FILE, &message_loop_),
181 download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) {
182 } 177 }
183 178
184 void ChromeDownloadManagerDelegateTest::SetUp() { 179 void ChromeDownloadManagerDelegateTest::SetUp() {
185 ChromeRenderViewHostTestHarness::SetUp(); 180 ChromeRenderViewHostTestHarness::SetUp();
186 181
187 CHECK(profile()); 182 CHECK(profile());
188 delegate_ = new TestChromeDownloadManagerDelegate(profile()); 183 delegate_ = new TestChromeDownloadManagerDelegate(profile());
189 delegate_->SetDownloadManager(download_manager_.get()); 184 delegate_->SetDownloadManager(download_manager_.get());
190 pref_service_ = profile()->GetTestingPrefService(); 185 pref_service_ = profile()->GetTestingPrefService();
191 web_contents()->SetDelegate(&web_contents_delegate_); 186 web_contents()->SetDelegate(&web_contents_delegate_);
192 187
193 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); 188 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir());
194 SetDefaultDownloadPath(test_download_dir_.path()); 189 SetDefaultDownloadPath(test_download_dir_.path());
195 } 190 }
196 191
197 void ChromeDownloadManagerDelegateTest::TearDown() { 192 void ChromeDownloadManagerDelegateTest::TearDown() {
198 message_loop_.RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
199 delegate_->Shutdown(); 194 delegate_->Shutdown();
200 ChromeRenderViewHostTestHarness::TearDown(); 195 ChromeRenderViewHostTestHarness::TearDown();
201 } 196 }
202 197
203 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { 198 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() {
204 ::testing::Mock::VerifyAndClearExpectations(delegate_); 199 ::testing::Mock::VerifyAndClearExpectations(delegate_);
205 } 200 }
206 201
207 content::MockDownloadItem* 202 content::MockDownloadItem*
208 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { 203 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 DownloadTarget result; 361 DownloadTarget result;
367 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); 362 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt"));
368 EXPECT_CALL(*delegate(), 363 EXPECT_CALL(*delegate(),
369 MockPromptUserForDownloadPath(save_as_download.get(), 364 MockPromptUserForDownloadPath(save_as_download.get(),
370 expected_prompt_path, _)) 365 expected_prompt_path, _))
371 .WillOnce(Return(base::FilePath())); 366 .WillOnce(Return(base::FilePath()));
372 DetermineDownloadTarget(save_as_download.get(), &result); 367 DetermineDownloadTarget(save_as_download.get(), &result);
373 VerifyAndClearExpectations(); 368 VerifyAndClearExpectations();
374 } 369 }
375 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698