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"); | |
David Trainor- moved to gerrit
2017/06/23 07:32:47
Haha :)
MAD
2017/06/29 14:44:53
Acknowledged.
| |
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 TEST_F(ChromeDownloadManagerDelegateTestWithSafeBrowsing, | |
910 TrustedSourcesPolicyTrusted) { | |
911 base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); | |
912 DCHECK(command_line); | |
913 command_line->AppendSwitchASCII(switches::kTrustedDownloadSources, | |
914 "trusted.com"); | |
915 GURL download_url("http://trusted.com/best-download-ever.exe"); | |
916 pref_service()->SetBoolean(prefs::kSafeBrowsingForTrustedSourcesEnabled, | |
917 false); | |
918 std::unique_ptr<content::MockDownloadItem> download_item = | |
919 CreateActiveDownloadItem(0); | |
920 EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(download_url)); | |
921 EXPECT_CALL(*delegate(), GetDownloadProtectionService()).Times(0); | |
922 EXPECT_TRUE( | |
923 delegate()->ShouldCompleteDownload(download_item.get(), base::Closure())); | |
924 } | |
925 | |
886 #endif // FULL_SAFE_BROWSING | 926 #endif // FULL_SAFE_BROWSING |
887 | 927 |
888 #if defined(OS_ANDROID) | 928 #if defined(OS_ANDROID) |
889 | 929 |
890 namespace { | 930 namespace { |
891 | 931 |
892 class AndroidDownloadInfobarCounter | 932 class AndroidDownloadInfobarCounter |
893 : public infobars::InfoBarManager::Observer { | 933 : public infobars::InfoBarManager::Observer { |
894 public: | 934 public: |
895 explicit AndroidDownloadInfobarCounter(content::WebContents* web_contents) | 935 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()); | 1045 test_case.path == ExpectPath::FULL ? fake_path : base::FilePath()); |
1006 delegate()->RequestConfirmation(download_item.get(), fake_path, | 1046 delegate()->RequestConfirmation(download_item.get(), fake_path, |
1007 test_case.confirmation_reason, callback); | 1047 test_case.confirmation_reason, callback); |
1008 loop.Run(); | 1048 loop.Run(); |
1009 | 1049 |
1010 EXPECT_EQ(test_case.info_bar == ExpectInfoBar::YES ? 1 : 0, | 1050 EXPECT_EQ(test_case.info_bar == ExpectInfoBar::YES ? 1 : 0, |
1011 infobar_counter.CheckAndResetInfobarCount()); | 1051 infobar_counter.CheckAndResetInfobarCount()); |
1012 } | 1052 } |
1013 } | 1053 } |
1014 #endif // OS_ANDROID | 1054 #endif // OS_ANDROID |
OLD | NEW |