| OLD | NEW | 
|---|
| 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 <stddef.h> | 5 #include <stddef.h> | 
| 6 #include <stdint.h> | 6 #include <stdint.h> | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
|  | 10 #include "base/command_line.h" | 
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" | 
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" | 
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" | 
| 13 #include "base/location.h" | 14 #include "base/location.h" | 
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" | 
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" | 
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" | 
| 17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" | 
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" | 
| 19 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 20 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 
| 20 #include "chrome/browser/download/download_item_model.h" | 21 #include "chrome/browser/download/download_item_model.h" | 
| 21 #include "chrome/browser/download/download_prefs.h" | 22 #include "chrome/browser/download/download_prefs.h" | 
| 22 #include "chrome/browser/download/download_target_info.h" | 23 #include "chrome/browser/download/download_target_info.h" | 
|  | 24 #include "chrome/common/chrome_switches.h" | 
| 23 #include "chrome/common/features.h" | 25 #include "chrome/common/features.h" | 
| 24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" | 
| 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 
| 26 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" | 
| 27 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" | 
| 28 #include "components/sync_preferences/testing_pref_service_syncable.h" | 30 #include "components/sync_preferences/testing_pref_service_syncable.h" | 
| 29 #include "content/public/browser/download_interrupt_reasons.h" | 31 #include "content/public/browser/download_interrupt_reasons.h" | 
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" | 
| 31 #include "content/public/browser/web_contents_delegate.h" | 33 #include "content/public/browser/web_contents_delegate.h" | 
| 32 #include "content/public/test/mock_download_item.h" | 34 #include "content/public/test/mock_download_item.h" | 
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 876   pref_service()->SetInteger( | 878   pref_service()->SetInteger( | 
| 877       prefs::kDownloadRestrictions, | 879       prefs::kDownloadRestrictions, | 
| 878       static_cast<int>(kParameters.download_restriction)); | 880       static_cast<int>(kParameters.download_restriction)); | 
| 879 | 881 | 
| 880   base::RunLoop run_loop; | 882   base::RunLoop run_loop; | 
| 881   ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), | 883   ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), | 
| 882                                                   run_loop.QuitClosure())); | 884                                                   run_loop.QuitClosure())); | 
| 883   run_loop.Run(); | 885   run_loop.Run(); | 
| 884 } | 886 } | 
| 885 | 887 | 
|  | 888 TEST_F(ChromeDownloadManagerDelegateTestWithSafeBrowsing, | 
|  | 889        TrustedSourcesPolicyNotTrusted) { | 
|  | 890   GURL download_url("http://untrusted.com/best-download-ever.exe"); | 
|  | 891   pref_service()->SetBoolean(prefs::kSafeBrowsingForTrustedSourcesEnabled, | 
|  | 892                              false); | 
|  | 893   std::unique_ptr<content::MockDownloadItem> download_item = | 
|  | 894       CreateActiveDownloadItem(0); | 
|  | 895   EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(download_url)); | 
|  | 896 | 
|  | 897   EXPECT_CALL(*delegate(), GetDownloadProtectionService()); | 
|  | 898   EXPECT_CALL(*download_protection_service(), MockCheckClientDownload()) | 
|  | 899       .WillOnce(Return(safe_browsing::DownloadProtectionService::SAFE)); | 
|  | 900   EXPECT_CALL(*download_item, GetDangerType()) | 
|  | 901       .WillRepeatedly(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); | 
|  | 902 | 
|  | 903   base::RunLoop run_loop; | 
|  | 904   ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), | 
|  | 905                                                   run_loop.QuitClosure())); | 
|  | 906   run_loop.Run(); | 
|  | 907 } | 
|  | 908 | 
|  | 909 #if !defined(OS_WIN) | 
|  | 910 // TODO(crbug.com/739204) Add a Windows version of this test. | 
|  | 911 TEST_F(ChromeDownloadManagerDelegateTestWithSafeBrowsing, | 
|  | 912        TrustedSourcesPolicyTrusted) { | 
|  | 913   base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); | 
|  | 914   DCHECK(command_line); | 
|  | 915   command_line->AppendSwitchASCII(switches::kTrustedDownloadSources, | 
|  | 916                                   "trusted.com"); | 
|  | 917   GURL download_url("http://trusted.com/best-download-ever.exe"); | 
|  | 918   pref_service()->SetBoolean(prefs::kSafeBrowsingForTrustedSourcesEnabled, | 
|  | 919                              false); | 
|  | 920   std::unique_ptr<content::MockDownloadItem> download_item = | 
|  | 921       CreateActiveDownloadItem(0); | 
|  | 922   EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(download_url)); | 
|  | 923   EXPECT_CALL(*delegate(), GetDownloadProtectionService()).Times(0); | 
|  | 924   EXPECT_TRUE( | 
|  | 925       delegate()->ShouldCompleteDownload(download_item.get(), base::Closure())); | 
|  | 926 } | 
|  | 927 #endif  // OS_WIN | 
| 886 #endif  // FULL_SAFE_BROWSING | 928 #endif  // FULL_SAFE_BROWSING | 
| 887 | 929 | 
| 888 #if defined(OS_ANDROID) | 930 #if defined(OS_ANDROID) | 
| 889 | 931 | 
| 890 namespace { | 932 namespace { | 
| 891 | 933 | 
| 892 class AndroidDownloadInfobarCounter | 934 class AndroidDownloadInfobarCounter | 
| 893     : public infobars::InfoBarManager::Observer { | 935     : public infobars::InfoBarManager::Observer { | 
| 894  public: | 936  public: | 
| 895   explicit AndroidDownloadInfobarCounter(content::WebContents* web_contents) | 937   explicit AndroidDownloadInfobarCounter(content::WebContents* web_contents) | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1005         test_case.path == ExpectPath::FULL ? fake_path : base::FilePath()); | 1047         test_case.path == ExpectPath::FULL ? fake_path : base::FilePath()); | 
| 1006     delegate()->RequestConfirmation(download_item.get(), fake_path, | 1048     delegate()->RequestConfirmation(download_item.get(), fake_path, | 
| 1007                                     test_case.confirmation_reason, callback); | 1049                                     test_case.confirmation_reason, callback); | 
| 1008     loop.Run(); | 1050     loop.Run(); | 
| 1009 | 1051 | 
| 1010     EXPECT_EQ(test_case.info_bar == ExpectInfoBar::YES ? 1 : 0, | 1052     EXPECT_EQ(test_case.info_bar == ExpectInfoBar::YES ? 1 : 0, | 
| 1011               infobar_counter.CheckAndResetInfobarCount()); | 1053               infobar_counter.CheckAndResetInfobarCount()); | 
| 1012   } | 1054   } | 
| 1013 } | 1055 } | 
| 1014 #endif  // OS_ANDROID | 1056 #endif  // OS_ANDROID | 
| OLD | NEW | 
|---|