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

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: Add one more test 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
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
Nico 2016/03/21 16:03:42 This is 8th TestSafeBrowsingServiceFactory we have
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 DownloadTest::SetUp();
1145 }
1146
1147 void TearDown() override {
1148 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr);
1149 DownloadTest::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,
3353 SendUncommonDownloadReportIfUserProceed) {
3354 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
3355 true);
3356 // Make a dangerous file.
3357 GURL download_url(
3358 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath));
3359 scoped_ptr<content::DownloadTestObserver> dangerous_observer(
3360 DangerousDownloadWaiter(
3361 browser(), 1,
3362 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT));
3363 ui_test_utils::NavigateToURL(browser(), download_url);
3364 dangerous_observer->WaitForFinished();
3365
3366 std::vector<DownloadItem*> downloads;
3367 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
3368 ASSERT_EQ(1u, downloads.size());
3369 DownloadItem* download = downloads[0];
3370 DownloadCommands(download).ExecuteCommand(DownloadCommands::KEEP);
3371
3372 safe_browsing::ClientSafeBrowsingReportRequest actual_report;
3373 actual_report.ParseFromString(
3374 test_safe_browsing_factory_->fake_safe_browsing_service()
3375 ->GetDownloadReport());
3376 EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest::
3377 DANGEROUS_DOWNLOAD_WARNING,
3378 actual_report.type());
3379 EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON,
3380 actual_report.download_verdict());
3381 EXPECT_EQ(download_url.spec(), actual_report.url());
3382 EXPECT_TRUE(actual_report.did_proceed());
3383
3384 download->Cancel(true);
3385 }
3386
3387 IN_PROC_BROWSER_TEST_F(
3388 DownloadTestWithFakeSafeBrowsing,
3389 NoUncommonDownloadReportWithoutUserProceed) {
3390 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled,
3391 true);
3392 // Make a dangerous file.
3393 GURL download_url(
3394 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath));
3395 scoped_ptr<content::DownloadTestObserver> dangerous_observer(
3396 DangerousDownloadWaiter(
3397 browser(), 1,
3398 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT));
3399 ui_test_utils::NavigateToURL(browser(), download_url);
3400 dangerous_observer->WaitForFinished();
3401
3402 std::vector<DownloadItem*> downloads;
3403 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads);
3404 ASSERT_EQ(1u, downloads.size());
3405 DownloadItem* download = downloads[0];
3406 DownloadCommands(download).ExecuteCommand(DownloadCommands::DISCARD);
3407
3408 EXPECT_TRUE(
3409 test_safe_browsing_factory_->fake_safe_browsing_service()
3410 ->GetDownloadReport().empty());
3411 }
3273 #endif // FULL_SAFE_BROWSING 3412 #endif // FULL_SAFE_BROWSING
3274 3413
3275 class DownloadTestWithShelf : public DownloadTest { 3414 class DownloadTestWithShelf : public DownloadTest {
3276 void SetUpCommandLine(base::CommandLine* command_line) override { 3415 void SetUpCommandLine(base::CommandLine* command_line) override {
3277 #if defined(OS_CHROMEOS) 3416 #if defined(OS_CHROMEOS)
3278 command_line->AppendSwitch(switches::kDisableDownloadNotification); 3417 command_line->AppendSwitch(switches::kDisableDownloadNotification);
3279 #endif 3418 #endif
3280 DownloadTest::SetUpCommandLine(command_line); 3419 DownloadTest::SetUpCommandLine(command_line);
3281 } 3420 }
3282 }; 3421 };
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 3664
3526 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( 3665 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter(
3527 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3666 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3528 ui_test_utils::NavigateToURL(browser(), extension_url); 3667 ui_test_utils::NavigateToURL(browser(), extension_url);
3529 3668
3530 observer->WaitForFinished(); 3669 observer->WaitForFinished();
3531 3670
3532 // Download shelf should close. 3671 // Download shelf should close.
3533 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3672 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3534 } 3673 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698