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

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 13 matching lines...) Expand all
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_delegate.h" 25 #include "content/public/browser/web_contents_delegate.h"
26 #include "content/public/test/mock_download_item.h" 26 #include "content/public/test/mock_download_item.h"
27 #include "content/public/test/mock_download_manager.h" 27 #include "content/public/test/mock_download_manager.h"
28 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
29 #include "content/public/test/test_renderer_host.h" 29 #include "content/public/test/test_renderer_host.h"
30 #include "content/public/test/web_contents_tester.h" 30 #include "content/public/test/web_contents_tester.h"
31 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 using content::DownloadItem;
35 using safe_browsing::DownloadProtectionService;
36 using ::testing::AtMost; 34 using ::testing::AtMost;
37 using ::testing::Invoke; 35 using ::testing::Invoke;
38 using ::testing::Return; 36 using ::testing::Return;
39 using ::testing::ReturnPointee; 37 using ::testing::ReturnPointee;
40 using ::testing::ReturnRef; 38 using ::testing::ReturnRef;
41 using ::testing::ReturnRefOfCopy; 39 using ::testing::ReturnRefOfCopy;
40 using ::testing::SetArgPointee;
42 using ::testing::WithArg; 41 using ::testing::WithArg;
43 using ::testing::_; 42 using ::testing::_;
43 using content::DownloadItem;
44 using safe_browsing::DownloadProtectionService;
44 45
45 namespace { 46 namespace {
46 47
47 class MockWebContentsDelegate : public content::WebContentsDelegate { 48 class MockWebContentsDelegate : public content::WebContentsDelegate {
48 public: 49 public:
49 virtual ~MockWebContentsDelegate() {} 50 virtual ~MockWebContentsDelegate() {}
50 }; 51 };
51 52
52 // Google Mock action that posts a task to the current message loop that invokes 53 // Google Mock action that posts a task to the current message loop that invokes
53 // the first argument of the mocked method as a callback. Said argument must be 54 // the first argument of the mocked method as a callback. Said argument must be
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 scoped_refptr<content::MockDownloadManager> download_manager_; 287 scoped_refptr<content::MockDownloadManager> download_manager_;
287 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; 288 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_;
288 MockWebContentsDelegate web_contents_delegate_; 289 MockWebContentsDelegate web_contents_delegate_;
289 }; 290 };
290 291
291 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() 292 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest()
292 : ChromeRenderViewHostTestHarness(), 293 : ChromeRenderViewHostTestHarness(),
293 ui_thread_(content::BrowserThread::UI, &message_loop_), 294 ui_thread_(content::BrowserThread::UI, &message_loop_),
294 file_thread_(content::BrowserThread::FILE, &message_loop_), 295 file_thread_(content::BrowserThread::FILE, &message_loop_),
295 download_manager_(new content::MockDownloadManager) { 296 download_manager_(new content::MockDownloadManager) {
297 EXPECT_CALL(*download_manager_, GetAllDownloads(_)).WillRepeatedly(Return());
298 EXPECT_CALL(*download_manager_, AddObserver(_)).WillRepeatedly(Return());
299 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return());
296 } 300 }
297 301
298 void ChromeDownloadManagerDelegateTest::SetUp() { 302 void ChromeDownloadManagerDelegateTest::SetUp() {
299 ChromeRenderViewHostTestHarness::SetUp(); 303 ChromeRenderViewHostTestHarness::SetUp();
300 304
301 CHECK(profile()); 305 CHECK(profile());
302 delegate_ = new TestChromeDownloadManagerDelegate(profile()); 306 delegate_ = new TestChromeDownloadManagerDelegate(profile());
303 delegate_->SetDownloadManager(download_manager_.get()); 307 delegate_->SetDownloadManager(download_manager_.get());
304 pref_service_ = profile()->GetTestingPrefService(); 308 pref_service_ = profile()->GetTestingPrefService();
305 contents()->SetDelegate(&web_contents_delegate_); 309 contents()->SetDelegate(&web_contents_delegate_);
306 310
307 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); 311 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir());
308 SetDefaultDownloadPath(test_download_dir_.path()); 312 SetDefaultDownloadPath(test_download_dir_.path());
309 } 313 }
310 314
311 void ChromeDownloadManagerDelegateTest::TearDown() { 315 void ChromeDownloadManagerDelegateTest::TearDown() {
312 message_loop_.RunAllPending(); 316 message_loop_.RunAllPending();
313 delegate_->Shutdown(); 317 delegate_->Shutdown();
314 ChromeRenderViewHostTestHarness::TearDown(); 318 ChromeRenderViewHostTestHarness::TearDown();
315 } 319 }
316 320
317 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { 321 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() {
318 ::testing::Mock::VerifyAndClearExpectations(delegate_); 322 ::testing::Mock::VerifyAndClearExpectations(delegate_);
319 ::testing::Mock::VerifyAndClearExpectations(download_manager_); 323 ::testing::Mock::VerifyAndClearExpectations(download_manager_);
324 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return());
325 EXPECT_CALL(*download_manager_, GetAllDownloads(_))
326 .WillRepeatedly(Return());
320 } 327 }
321 328
322 content::MockDownloadItem* 329 content::MockDownloadItem*
323 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { 330 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) {
324 content::MockDownloadItem* item = 331 content::MockDownloadItem* item =
325 new ::testing::NiceMock<content::MockDownloadItem>(); 332 new ::testing::NiceMock<content::MockDownloadItem>();
326 ON_CALL(*item, GetFullPath()) 333 ON_CALL(*item, GetFullPath())
327 .WillByDefault(ReturnRefOfCopy(FilePath())); 334 .WillByDefault(ReturnRefOfCopy(FilePath()));
328 ON_CALL(*item, GetHash()) 335 ON_CALL(*item, GetHash())
329 .WillByDefault(ReturnRefOfCopy(std::string())); 336 .WillByDefault(ReturnRefOfCopy(std::string()));
330 ON_CALL(*item, GetReferrerUrl()) 337 ON_CALL(*item, GetReferrerUrl())
331 .WillByDefault(ReturnRefOfCopy(GURL())); 338 .WillByDefault(ReturnRefOfCopy(GURL()));
332 ON_CALL(*item, GetTransitionType()) 339 ON_CALL(*item, GetTransitionType())
333 .WillByDefault(Return(content::PAGE_TRANSITION_LINK)); 340 .WillByDefault(Return(content::PAGE_TRANSITION_LINK));
334 ON_CALL(*item, HasUserGesture()) 341 ON_CALL(*item, HasUserGesture())
335 .WillByDefault(Return(false)); 342 .WillByDefault(Return(false));
336 ON_CALL(*item, IsDangerous()) 343 ON_CALL(*item, IsDangerous())
337 .WillByDefault(Return(false)); 344 .WillByDefault(Return(false));
338 ON_CALL(*item, IsTemporary()) 345 ON_CALL(*item, IsTemporary())
339 .WillByDefault(Return(false)); 346 .WillByDefault(Return(false));
340 ON_CALL(*item, GetWebContents()) 347 ON_CALL(*item, GetWebContents())
341 .WillByDefault(Return(contents())); 348 .WillByDefault(Return(contents()));
342 EXPECT_CALL(*item, GetId()) 349 EXPECT_CALL(*item, GetId())
343 .WillRepeatedly(Return(id)); 350 .WillRepeatedly(Return(id));
344 EXPECT_CALL(*download_manager_, GetActiveDownloadItem(id)) 351 EXPECT_CALL(*item, GetState())
352 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS));
353 EXPECT_CALL(*item, AddObserver(_)).WillRepeatedly(Return());
354 EXPECT_CALL(*item, RemoveObserver(_)).WillRepeatedly(Return());
355 EXPECT_CALL(*download_manager_, GetDownload(id))
345 .WillRepeatedly(Return(item)); 356 .WillRepeatedly(Return(item));
346 return item; 357 return item;
347 } 358 }
348 359
349 void ChromeDownloadManagerDelegateTest::EnableAutoOpenBasedOnExtension( 360 void ChromeDownloadManagerDelegateTest::EnableAutoOpenBasedOnExtension(
350 const FilePath& path) { 361 const FilePath& path) {
351 EXPECT_TRUE( 362 EXPECT_TRUE(
352 delegate_->download_prefs()->EnableAutoOpenBasedOnExtension(path)); 363 delegate_->download_prefs()->EnableAutoOpenBasedOnExtension(path));
353 } 364 }
354 365
(...skipping 14 matching lines...) Expand all
369 url_chain.push_back(download_url); 380 url_chain.push_back(download_url);
370 FilePath forced_file_path(GetPathInDownloadDir(test_case.forced_file_path)); 381 FilePath forced_file_path(GetPathInDownloadDir(test_case.forced_file_path));
371 EXPECT_CALL(*item, GetURL()) 382 EXPECT_CALL(*item, GetURL())
372 .WillRepeatedly(ReturnRef(download_url)); 383 .WillRepeatedly(ReturnRef(download_url));
373 EXPECT_CALL(*item, GetUrlChain()) 384 EXPECT_CALL(*item, GetUrlChain())
374 .WillRepeatedly(ReturnRef(url_chain)); 385 .WillRepeatedly(ReturnRef(url_chain));
375 EXPECT_CALL(*item, GetForcedFilePath()) 386 EXPECT_CALL(*item, GetForcedFilePath())
376 .WillRepeatedly(ReturnRef(forced_file_path)); 387 .WillRepeatedly(ReturnRef(forced_file_path));
377 EXPECT_CALL(*item, GetMimeType()) 388 EXPECT_CALL(*item, GetMimeType())
378 .WillRepeatedly(Return(test_case.mime_type)); 389 .WillRepeatedly(Return(test_case.mime_type));
390 std::vector<DownloadItem*> items;
391 items.push_back(item);
392 EXPECT_CALL(*download_manager_, GetAllDownloads(_))
393 .WillRepeatedly(SetArgPointee<0>(items));
379 394
380 #if defined(ENABLE_SAFE_BROWSING) 395 #if defined(ENABLE_SAFE_BROWSING)
381 // Results of SafeBrowsing URL check. 396 // Results of SafeBrowsing URL check.
382 DownloadProtectionService::DownloadCheckResult url_check_result = 397 DownloadProtectionService::DownloadCheckResult url_check_result =
383 (test_case.danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL) ? 398 (test_case.danger_type == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL) ?
384 DownloadProtectionService::DANGEROUS : 399 DownloadProtectionService::DANGEROUS :
385 DownloadProtectionService::SAFE; 400 DownloadProtectionService::SAFE;
386 EXPECT_CALL(*delegate_->test_download_protection_service(), 401 EXPECT_CALL(*delegate_->test_download_protection_service(),
387 CheckDownloadUrl(InfoMatchingURL(download_url), _)) 402 CheckDownloadUrl(InfoMatchingURL(download_url), _))
388 .WillOnce(WithArg<1>(ScheduleCallback(url_check_result))); 403 .WillOnce(WithArg<1>(ScheduleCallback(url_check_result)));
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 }; 945 };
931 946
932 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); 947 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases));
933 } 948 }
934 949
935 // TODO(asanka): Add more tests. 950 // TODO(asanka): Add more tests.
936 // * Default download path is not writable. 951 // * Default download path is not writable.
937 // * Download path doesn't exist. 952 // * Download path doesn't exist.
938 // * IsDangerousFile(). 953 // * IsDangerousFile().
939 // * Filename generation. 954 // * Filename generation.
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.cc ('k') | chrome/browser/download/download_file_picker_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698