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

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

Issue 1784433003: Track CTR of uncommon download warning. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move function inside FULL_SAFE_BROWSING macros Created 4 years, 9 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
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 "chrome/browser/download/download_browsertest.h" 5 #include "chrome/browser/download/download_browsertest.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
28 #include "base/sys_info.h" 28 #include "base/sys_info.h"
29 #include "base/test/test_file_util.h" 29 #include "base/test/test_file_util.h"
30 #include "build/build_config.h" 30 #include "build/build_config.h"
31 #include "chrome/app/chrome_command_ids.h" 31 #include "chrome/app/chrome_command_ids.h"
32 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chrome_notification_types.h" 33 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/download/chrome_download_manager_delegate.h" 34 #include "chrome/browser/download/chrome_download_manager_delegate.h"
35 #include "chrome/browser/download/download_commands.h"
35 #include "chrome/browser/download/download_crx_util.h" 36 #include "chrome/browser/download/download_crx_util.h"
36 #include "chrome/browser/download/download_history.h" 37 #include "chrome/browser/download/download_history.h"
37 #include "chrome/browser/download/download_item_model.h" 38 #include "chrome/browser/download/download_item_model.h"
38 #include "chrome/browser/download/download_prefs.h" 39 #include "chrome/browser/download/download_prefs.h"
39 #include "chrome/browser/download/download_request_limiter.h" 40 #include "chrome/browser/download/download_request_limiter.h"
40 #include "chrome/browser/download/download_service.h" 41 #include "chrome/browser/download/download_service.h"
41 #include "chrome/browser/download/download_service_factory.h" 42 #include "chrome/browser/download/download_service_factory.h"
42 #include "chrome/browser/download/download_shelf.h" 43 #include "chrome/browser/download/download_shelf.h"
43 #include "chrome/browser/download/download_target_determiner.h" 44 #include "chrome/browser/download/download_target_determiner.h"
44 #include "chrome/browser/download/download_test_file_activity_observer.h" 45 #include "chrome/browser/download/download_test_file_activity_observer.h"
(...skipping 23 matching lines...) Expand all
68 #include "chrome/test/base/in_process_browser_test.h" 69 #include "chrome/test/base/in_process_browser_test.h"
69 #include "chrome/test/base/test_switches.h" 70 #include "chrome/test/base/test_switches.h"
70 #include "chrome/test/base/ui_test_utils.h" 71 #include "chrome/test/base/ui_test_utils.h"
71 #include "components/history/content/browser/download_constants_utils.h" 72 #include "components/history/content/browser/download_constants_utils.h"
72 #include "components/history/core/browser/download_constants.h" 73 #include "components/history/core/browser/download_constants.h"
73 #include "components/history/core/browser/download_row.h" 74 #include "components/history/core/browser/download_row.h"
74 #include "components/history/core/browser/history_service.h" 75 #include "components/history/core/browser/history_service.h"
75 #include "components/infobars/core/confirm_infobar_delegate.h" 76 #include "components/infobars/core/confirm_infobar_delegate.h"
76 #include "components/infobars/core/infobar.h" 77 #include "components/infobars/core/infobar.h"
77 #include "components/prefs/pref_service.h" 78 #include "components/prefs/pref_service.h"
79 #include "content/public/browser/download_danger_type.h"
78 #include "content/public/browser/download_interrupt_reasons.h" 80 #include "content/public/browser/download_interrupt_reasons.h"
79 #include "content/public/browser/download_item.h" 81 #include "content/public/browser/download_item.h"
80 #include "content/public/browser/download_manager.h" 82 #include "content/public/browser/download_manager.h"
81 #include "content/public/browser/download_save_info.h" 83 #include "content/public/browser/download_save_info.h"
82 #include "content/public/browser/download_url_parameters.h" 84 #include "content/public/browser/download_url_parameters.h"
83 #include "content/public/browser/notification_source.h" 85 #include "content/public/browser/notification_source.h"
84 #include "content/public/browser/render_frame_host.h" 86 #include "content/public/browser/render_frame_host.h"
85 #include "content/public/browser/render_view_host.h" 87 #include "content/public/browser/render_view_host.h"
86 #include "content/public/browser/render_widget_host.h" 88 #include "content/public/browser/render_widget_host.h"
87 #include "content/public/browser/resource_context.h" 89 #include "content/public/browser/resource_context.h"
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1071
1070 // Location of the test data. 1072 // Location of the test data.
1071 base::FilePath test_dir_; 1073 base::FilePath test_dir_;
1072 1074
1073 // Location of the downloads directory for these tests 1075 // Location of the downloads directory for these tests
1074 base::ScopedTempDir downloads_directory_; 1076 base::ScopedTempDir downloads_directory_;
1075 1077
1076 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_; 1078 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_;
1077 }; 1079 };
1078 1080
1081 class FakeDownloadProtectionService
1082 : public safe_browsing::DownloadProtectionService {
1083 public:
1084 FakeDownloadProtectionService()
1085 : safe_browsing::DownloadProtectionService(nullptr, nullptr) {}
1086
1087 void CheckClientDownload(DownloadItem* download_item,
1088 const CheckDownloadCallback& callback) override {
1089 callback.Run(
1090 safe_browsing::DownloadProtectionService::UNCOMMON);
1091 }
1092 };
1093
1094 class FakeSafeBrowsingService : public safe_browsing::SafeBrowsingService {
1095 public:
1096 FakeSafeBrowsingService() {}
1097
1098 safe_browsing::DownloadProtectionService* CreateDownloadProtectionService(
1099 net::URLRequestContextGetter* not_used_request_context_getter) override {
1100 return new FakeDownloadProtectionService();
1101 }
1102
1103 std::string GetDownloadReport() const { return report_; }
1104
1105 protected:
1106 ~FakeSafeBrowsingService() override {}
1107
1108 void SendSerializedDownloadReport(const std::string& report) override {
1109 report_ = report;
1110 }
1111
1112 std::string report_;
1113 };
1114
1115 // Factory that creates FakeSafeBrowsingService instances.
1116 class TestSafeBrowsingServiceFactory
1117 : public safe_browsing::SafeBrowsingServiceFactory {
1118 public:
1119 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {}
1120 ~TestSafeBrowsingServiceFactory() override {}
1121
1122 safe_browsing::SafeBrowsingService* CreateSafeBrowsingService() override {
1123 DCHECK(!fake_safe_browsing_service_);
1124 fake_safe_browsing_service_ = new FakeSafeBrowsingService();
1125 return fake_safe_browsing_service_.get();
1126 }
1127
1128 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service() {
1129 return fake_safe_browsing_service_;
1130 }
1131
1132 private:
1133 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service_;
1134 };
1135
1136 class DownloadTestWithFakeSafeBrowsing : public DownloadTest {
1137 public:
1138 DownloadTestWithFakeSafeBrowsing()
1139 : test_safe_browsing_factory_(new TestSafeBrowsingServiceFactory()) {}
1140
1141 void SetUp() override {
1142 safe_browsing::SafeBrowsingService::RegisterFactory(
1143 test_safe_browsing_factory_.get());
1144 InProcessBrowserTest::SetUp();
asanka 2016/03/16 01:29:50 Nit: You want to do DownloadTest::SetUp(). And sim
Jialiu Lin 2016/03/16 02:43:43 Done.
1145 }
1146
1147 void TearDown() override {
1148 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr);
1149 InProcessBrowserTest::TearDown();
1150 }
1151
1152 protected:
1153 scoped_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_;
1154 };
1155
1079 // NOTES: 1156 // NOTES:
1080 // 1157 //
1081 // Files for these tests are found in DIR_TEST_DATA (currently 1158 // Files for these tests are found in DIR_TEST_DATA (currently
1082 // "chrome\test\data\", see chrome_paths.cc). 1159 // "chrome\test\data\", see chrome_paths.cc).
1083 // Mock responses have extension .mock-http-headers appended to the file name. 1160 // Mock responses have extension .mock-http-headers appended to the file name.
1084 1161
1085 // Download a file due to the associated MIME type. 1162 // Download a file due to the associated MIME type.
1086 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { 1163 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) {
1087 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); 1164 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path));
1088 1165
(...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after
3263 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload( 3340 ASSERT_TRUE(safe_browsing::DownloadFeedbackService::IsEnabledForDownload(
3264 *(downloads[0]))); 3341 *(downloads[0])));
3265 3342
3266 // Begin feedback and check that the file is "stolen". 3343 // Begin feedback and check that the file is "stolen".
3267 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3344 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3268 downloads[0]); 3345 downloads[0]);
3269 std::vector<DownloadItem*> updated_downloads; 3346 std::vector<DownloadItem*> updated_downloads;
3270 GetDownloads(browser(), &updated_downloads); 3347 GetDownloads(browser(), &updated_downloads);
3271 ASSERT_TRUE(updated_downloads.empty()); 3348 ASSERT_TRUE(updated_downloads.empty());
3272 } 3349 }
3350
3351 IN_PROC_BROWSER_TEST_F(
3352 DownloadTestWithFakeSafeBrowsing, SendUncommonDownloadAcceptReport) {
3353 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
3354 true);
3355 // Make a dangerous file.
3356 GURL download_url(
3357 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath));
3358 scoped_ptr<content::DownloadTestObserver> dangerous_observer(
3359 DangerousDownloadWaiter(
3360 browser(), 1,
3361 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT));
3362 ui_test_utils::NavigateToURL(browser(), download_url);
3363 dangerous_observer->WaitForFinished();
3364
3365 std::vector<DownloadItem*> downloads;
3366 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
3367 ASSERT_EQ(1u, downloads.size());
3368 DownloadItem* download = downloads[0];
3369 DownloadCommands(download).ExecuteCommand(DownloadCommands::KEEP);
3370
3371 safe_browsing::ClientSafeBrowsingReportRequest actual_report;
3372 actual_report.ParseFromString(
3373 test_safe_browsing_factory_->fake_safe_browsing_service()
3374 ->GetDownloadReport());
3375 EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest::
3376 DANGEROUS_DOWNLOAD_WARNING,
3377 actual_report.type());
3378 EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON,
3379 actual_report.download_verdict());
3380 EXPECT_EQ(download_url.spec(), actual_report.url());
3381 EXPECT_TRUE(actual_report.did_proceed());
3382
3383 download->Cancel(true);
3384 }
3273 #endif // FULL_SAFE_BROWSING 3385 #endif // FULL_SAFE_BROWSING
3274 3386
3275 class DownloadTestWithShelf : public DownloadTest { 3387 class DownloadTestWithShelf : public DownloadTest {
3276 void SetUpCommandLine(base::CommandLine* command_line) override { 3388 void SetUpCommandLine(base::CommandLine* command_line) override {
3277 #if defined(OS_CHROMEOS) 3389 #if defined(OS_CHROMEOS)
3278 command_line->AppendSwitch(switches::kDisableDownloadNotification); 3390 command_line->AppendSwitch(switches::kDisableDownloadNotification);
3279 #endif 3391 #endif
3280 DownloadTest::SetUpCommandLine(command_line); 3392 DownloadTest::SetUpCommandLine(command_line);
3281 } 3393 }
3282 }; 3394 };
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 3637
3526 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( 3638 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter(
3527 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3639 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3528 ui_test_utils::NavigateToURL(browser(), extension_url); 3640 ui_test_utils::NavigateToURL(browser(), extension_url);
3529 3641
3530 observer->WaitForFinished(); 3642 observer->WaitForFinished();
3531 3643
3532 // Download shelf should close. 3644 // Download shelf should close.
3533 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3645 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3534 } 3646 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('j') | chrome/browser/download/download_commands.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698