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

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

Issue 10912183: Remove DownloadManager::GetDownloadItem in favor of GetDownload() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/observer_list.h" 8 #include "base/observer_list.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 scoped_refptr<content::MockDownloadManager> download_manager_; 286 scoped_refptr<content::MockDownloadManager> download_manager_;
287 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; 287 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_;
288 MockWebContentsDelegate web_contents_delegate_; 288 MockWebContentsDelegate web_contents_delegate_;
289 }; 289 };
290 290
291 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() 291 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest()
292 : ChromeRenderViewHostTestHarness(), 292 : ChromeRenderViewHostTestHarness(),
293 ui_thread_(content::BrowserThread::UI, &message_loop_), 293 ui_thread_(content::BrowserThread::UI, &message_loop_),
294 file_thread_(content::BrowserThread::FILE, &message_loop_), 294 file_thread_(content::BrowserThread::FILE, &message_loop_),
295 download_manager_(new content::MockDownloadManager) { 295 download_manager_(new content::MockDownloadManager) {
296 EXPECT_CALL(*download_manager_, AddObserver(_)).WillRepeatedly(Return());
297 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return());
296 } 298 }
297 299
298 void ChromeDownloadManagerDelegateTest::SetUp() { 300 void ChromeDownloadManagerDelegateTest::SetUp() {
299 ChromeRenderViewHostTestHarness::SetUp(); 301 ChromeRenderViewHostTestHarness::SetUp();
300 302
301 CHECK(profile()); 303 CHECK(profile());
302 delegate_ = new TestChromeDownloadManagerDelegate(profile()); 304 delegate_ = new TestChromeDownloadManagerDelegate(profile());
303 delegate_->SetDownloadManager(download_manager_.get()); 305 delegate_->SetDownloadManager(download_manager_.get());
304 pref_service_ = profile()->GetTestingPrefService(); 306 pref_service_ = profile()->GetTestingPrefService();
305 contents()->SetDelegate(&web_contents_delegate_); 307 contents()->SetDelegate(&web_contents_delegate_);
306 308
307 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); 309 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir());
308 SetDefaultDownloadPath(test_download_dir_.path()); 310 SetDefaultDownloadPath(test_download_dir_.path());
309 } 311 }
310 312
311 void ChromeDownloadManagerDelegateTest::TearDown() { 313 void ChromeDownloadManagerDelegateTest::TearDown() {
312 message_loop_.RunAllPending(); 314 message_loop_.RunAllPending();
313 delegate_->Shutdown(); 315 delegate_->Shutdown();
314 ChromeRenderViewHostTestHarness::TearDown(); 316 ChromeRenderViewHostTestHarness::TearDown();
315 } 317 }
316 318
317 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { 319 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() {
318 ::testing::Mock::VerifyAndClearExpectations(delegate_); 320 ::testing::Mock::VerifyAndClearExpectations(delegate_);
319 ::testing::Mock::VerifyAndClearExpectations(download_manager_); 321 ::testing::Mock::VerifyAndClearExpectations(download_manager_);
322 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return());
320 } 323 }
321 324
322 content::MockDownloadItem* 325 content::MockDownloadItem*
323 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { 326 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) {
324 content::MockDownloadItem* item = 327 content::MockDownloadItem* item =
325 new ::testing::NiceMock<content::MockDownloadItem>(); 328 new ::testing::NiceMock<content::MockDownloadItem>();
326 ON_CALL(*item, GetFullPath()) 329 ON_CALL(*item, GetFullPath())
327 .WillByDefault(ReturnRefOfCopy(FilePath())); 330 .WillByDefault(ReturnRefOfCopy(FilePath()));
328 ON_CALL(*item, GetHash()) 331 ON_CALL(*item, GetHash())
329 .WillByDefault(ReturnRefOfCopy(std::string())); 332 .WillByDefault(ReturnRefOfCopy(std::string()));
330 ON_CALL(*item, GetReferrerUrl()) 333 ON_CALL(*item, GetReferrerUrl())
331 .WillByDefault(ReturnRefOfCopy(GURL())); 334 .WillByDefault(ReturnRefOfCopy(GURL()));
332 ON_CALL(*item, GetTransitionType()) 335 ON_CALL(*item, GetTransitionType())
333 .WillByDefault(Return(content::PAGE_TRANSITION_LINK)); 336 .WillByDefault(Return(content::PAGE_TRANSITION_LINK));
334 ON_CALL(*item, HasUserGesture()) 337 ON_CALL(*item, HasUserGesture())
335 .WillByDefault(Return(false)); 338 .WillByDefault(Return(false));
336 ON_CALL(*item, IsDangerous()) 339 ON_CALL(*item, IsDangerous())
337 .WillByDefault(Return(false)); 340 .WillByDefault(Return(false));
338 ON_CALL(*item, IsTemporary()) 341 ON_CALL(*item, IsTemporary())
339 .WillByDefault(Return(false)); 342 .WillByDefault(Return(false));
340 ON_CALL(*item, GetWebContents()) 343 ON_CALL(*item, GetWebContents())
341 .WillByDefault(Return(contents())); 344 .WillByDefault(Return(contents()));
342 EXPECT_CALL(*item, GetId()) 345 EXPECT_CALL(*item, GetId())
343 .WillRepeatedly(Return(id)); 346 .WillRepeatedly(Return(id));
344 EXPECT_CALL(*download_manager_, GetActiveDownloadItem(id)) 347 EXPECT_CALL(*item, AddObserver(_)).WillRepeatedly(Return());
348 EXPECT_CALL(*item, RemoveObserver(_)).WillRepeatedly(Return());
349 EXPECT_CALL(*download_manager_, GetDownload(id))
345 .WillRepeatedly(Return(item)); 350 .WillRepeatedly(Return(item));
346 return item; 351 return item;
347 } 352 }
348 353
349 void ChromeDownloadManagerDelegateTest::EnableAutoOpenBasedOnExtension( 354 void ChromeDownloadManagerDelegateTest::EnableAutoOpenBasedOnExtension(
350 const FilePath& path) { 355 const FilePath& path) {
351 EXPECT_TRUE( 356 EXPECT_TRUE(
352 delegate_->download_prefs()->EnableAutoOpenBasedOnExtension(path)); 357 delegate_->download_prefs()->EnableAutoOpenBasedOnExtension(path));
353 } 358 }
354 359
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 }; 935 };
931 936
932 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); 937 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases));
933 } 938 }
934 939
935 // TODO(asanka): Add more tests. 940 // TODO(asanka): Add more tests.
936 // * Default download path is not writable. 941 // * Default download path is not writable.
937 // * Download path doesn't exist. 942 // * Download path doesn't exist.
938 // * IsDangerousFile(). 943 // * IsDangerousFile().
939 // * Filename generation. 944 // * Filename generation.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698