| 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 "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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 #include "net/test/embedded_test_server/http_response.h" | 102 #include "net/test/embedded_test_server/http_response.h" |
| 103 #include "net/test/url_request/url_request_mock_http_job.h" | 103 #include "net/test/url_request/url_request_mock_http_job.h" |
| 104 #include "net/test/url_request/url_request_slow_download_job.h" | 104 #include "net/test/url_request/url_request_slow_download_job.h" |
| 105 #include "testing/gtest/include/gtest/gtest.h" | 105 #include "testing/gtest/include/gtest/gtest.h" |
| 106 #include "ui/base/l10n/l10n_util.h" | 106 #include "ui/base/l10n/l10n_util.h" |
| 107 #include "ui/base/page_transition_types.h" | 107 #include "ui/base/page_transition_types.h" |
| 108 | 108 |
| 109 #if defined(FULL_SAFE_BROWSING) | 109 #if defined(FULL_SAFE_BROWSING) |
| 110 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 110 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 111 #include "chrome/browser/safe_browsing/download_protection_service.h" | 111 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 112 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 112 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
| 113 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 114 #endif | 113 #endif |
| 115 | 114 |
| 116 using content::BrowserContext; | 115 using content::BrowserContext; |
| 117 using content::BrowserThread; | 116 using content::BrowserThread; |
| 118 using content::DownloadItem; | 117 using content::DownloadItem; |
| 119 using content::DownloadManager; | 118 using content::DownloadManager; |
| 120 using content::DownloadUrlParameters; | 119 using content::DownloadUrlParameters; |
| 121 using content::WebContents; | 120 using content::WebContents; |
| 122 using extensions::Extension; | 121 using extensions::Extension; |
| 123 using extensions::FeatureSwitch; | 122 using extensions::FeatureSwitch; |
| (...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 : safe_browsing::DownloadProtectionService(nullptr) {} | 1080 : safe_browsing::DownloadProtectionService(nullptr) {} |
| 1082 | 1081 |
| 1083 void CheckClientDownload(DownloadItem* download_item, | 1082 void CheckClientDownload(DownloadItem* download_item, |
| 1084 const CheckDownloadCallback& callback) override { | 1083 const CheckDownloadCallback& callback) override { |
| 1085 callback.Run( | 1084 callback.Run( |
| 1086 safe_browsing::DownloadProtectionService::UNCOMMON); | 1085 safe_browsing::DownloadProtectionService::UNCOMMON); |
| 1087 } | 1086 } |
| 1088 }; | 1087 }; |
| 1089 | 1088 |
| 1090 class FakeSafeBrowsingService | 1089 class FakeSafeBrowsingService |
| 1091 : public safe_browsing::SafeBrowsingService, | 1090 : public safe_browsing::TestSafeBrowsingService, |
| 1092 public safe_browsing::ServicesDelegate::ServicesCreator { | 1091 public safe_browsing::ServicesDelegate::ServicesCreator { |
| 1093 public: | 1092 public: |
| 1094 FakeSafeBrowsingService() { | 1093 FakeSafeBrowsingService() { |
| 1095 services_delegate_ = | 1094 services_delegate_ = |
| 1096 safe_browsing::ServicesDelegate::CreateForTest(this, this); | 1095 safe_browsing::ServicesDelegate::CreateForTest(this, this); |
| 1097 } | 1096 } |
| 1098 | 1097 |
| 1099 std::string GetDownloadReport() const { return report_; } | |
| 1100 | |
| 1101 protected: | 1098 protected: |
| 1102 ~FakeSafeBrowsingService() override {} | 1099 ~FakeSafeBrowsingService() override {} |
| 1103 | 1100 |
| 1104 // ServicesDelegate::ServicesCreator: | 1101 // ServicesDelegate::ServicesCreator: |
| 1105 bool CanCreateDownloadProtectionService() override { return true; } | 1102 bool CanCreateDownloadProtectionService() override { return true; } |
| 1106 bool CanCreateIncidentReportingService() override { return false; } | 1103 bool CanCreateIncidentReportingService() override { return false; } |
| 1107 bool CanCreateResourceRequestDetector() override { return false; } | 1104 bool CanCreateResourceRequestDetector() override { return false; } |
| 1108 safe_browsing::DownloadProtectionService* CreateDownloadProtectionService() | 1105 safe_browsing::DownloadProtectionService* CreateDownloadProtectionService() |
| 1109 override { | 1106 override { |
| 1110 return new FakeDownloadProtectionService(); | 1107 return new FakeDownloadProtectionService(); |
| 1111 } | 1108 } |
| 1112 safe_browsing::IncidentReportingService* CreateIncidentReportingService() | 1109 safe_browsing::IncidentReportingService* CreateIncidentReportingService() |
| 1113 override { | 1110 override { |
| 1114 NOTREACHED(); | 1111 NOTREACHED(); |
| 1115 return nullptr; | 1112 return nullptr; |
| 1116 } | 1113 } |
| 1117 safe_browsing::ResourceRequestDetector* CreateResourceRequestDetector() | 1114 safe_browsing::ResourceRequestDetector* CreateResourceRequestDetector() |
| 1118 override { | 1115 override { |
| 1119 NOTREACHED(); | 1116 NOTREACHED(); |
| 1120 return nullptr; | 1117 return nullptr; |
| 1121 } | 1118 } |
| 1122 | 1119 |
| 1123 // SafeBrowsingService: | |
| 1124 void SendSerializedDownloadReport(const std::string& report) override { | |
| 1125 report_ = report; | |
| 1126 } | |
| 1127 | |
| 1128 std::string report_; | |
| 1129 | |
| 1130 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); | 1120 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); |
| 1131 }; | 1121 }; |
| 1132 | 1122 |
| 1133 // Factory that creates FakeSafeBrowsingService instances. | 1123 // Factory that creates FakeSafeBrowsingService instances. |
| 1134 class TestSafeBrowsingServiceFactory | 1124 class TestSafeBrowsingServiceFactory |
| 1135 : public safe_browsing::SafeBrowsingServiceFactory { | 1125 : public safe_browsing::SafeBrowsingServiceFactory { |
| 1136 public: | 1126 public: |
| 1137 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {} | 1127 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {} |
| 1138 ~TestSafeBrowsingServiceFactory() override {} | 1128 ~TestSafeBrowsingServiceFactory() override {} |
| 1139 | 1129 |
| (...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3372 | 3362 |
| 3373 std::vector<DownloadItem*> downloads; | 3363 std::vector<DownloadItem*> downloads; |
| 3374 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 3364 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 3375 ASSERT_EQ(1u, downloads.size()); | 3365 ASSERT_EQ(1u, downloads.size()); |
| 3376 DownloadItem* download = downloads[0]; | 3366 DownloadItem* download = downloads[0]; |
| 3377 DownloadCommands(download).ExecuteCommand(DownloadCommands::KEEP); | 3367 DownloadCommands(download).ExecuteCommand(DownloadCommands::KEEP); |
| 3378 | 3368 |
| 3379 safe_browsing::ClientSafeBrowsingReportRequest actual_report; | 3369 safe_browsing::ClientSafeBrowsingReportRequest actual_report; |
| 3380 actual_report.ParseFromString( | 3370 actual_report.ParseFromString( |
| 3381 test_safe_browsing_factory_->fake_safe_browsing_service() | 3371 test_safe_browsing_factory_->fake_safe_browsing_service() |
| 3382 ->GetDownloadReport()); | 3372 ->serilized_download_report()); |
| 3383 EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest:: | 3373 EXPECT_EQ(safe_browsing::ClientSafeBrowsingReportRequest:: |
| 3384 DANGEROUS_DOWNLOAD_WARNING, | 3374 DANGEROUS_DOWNLOAD_WARNING, |
| 3385 actual_report.type()); | 3375 actual_report.type()); |
| 3386 EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON, | 3376 EXPECT_EQ(safe_browsing::ClientDownloadResponse::UNCOMMON, |
| 3387 actual_report.download_verdict()); | 3377 actual_report.download_verdict()); |
| 3388 EXPECT_EQ(download_url.spec(), actual_report.url()); | 3378 EXPECT_EQ(download_url.spec(), actual_report.url()); |
| 3389 EXPECT_TRUE(actual_report.did_proceed()); | 3379 EXPECT_TRUE(actual_report.did_proceed()); |
| 3390 | 3380 |
| 3391 download->Cancel(true); | 3381 download->Cancel(true); |
| 3392 } | 3382 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3405 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3395 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
| 3406 ui_test_utils::NavigateToURL(browser(), download_url); | 3396 ui_test_utils::NavigateToURL(browser(), download_url); |
| 3407 dangerous_observer->WaitForFinished(); | 3397 dangerous_observer->WaitForFinished(); |
| 3408 | 3398 |
| 3409 std::vector<DownloadItem*> downloads; | 3399 std::vector<DownloadItem*> downloads; |
| 3410 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 3400 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 3411 ASSERT_EQ(1u, downloads.size()); | 3401 ASSERT_EQ(1u, downloads.size()); |
| 3412 DownloadItem* download = downloads[0]; | 3402 DownloadItem* download = downloads[0]; |
| 3413 DownloadCommands(download).ExecuteCommand(DownloadCommands::DISCARD); | 3403 DownloadCommands(download).ExecuteCommand(DownloadCommands::DISCARD); |
| 3414 | 3404 |
| 3415 EXPECT_TRUE( | 3405 EXPECT_TRUE(test_safe_browsing_factory_->fake_safe_browsing_service() |
| 3416 test_safe_browsing_factory_->fake_safe_browsing_service() | 3406 ->serilized_download_report() |
| 3417 ->GetDownloadReport().empty()); | 3407 .empty()); |
| 3418 } | 3408 } |
| 3419 #endif // FULL_SAFE_BROWSING | 3409 #endif // FULL_SAFE_BROWSING |
| 3420 | 3410 |
| 3421 class DownloadTestWithShelf : public DownloadTest { | 3411 class DownloadTestWithShelf : public DownloadTest { |
| 3422 void SetUpCommandLine(base::CommandLine* command_line) override { | 3412 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 3423 #if defined(OS_CHROMEOS) | 3413 #if defined(OS_CHROMEOS) |
| 3424 command_line->AppendSwitch(switches::kDisableDownloadNotification); | 3414 command_line->AppendSwitch(switches::kDisableDownloadNotification); |
| 3425 #endif | 3415 #endif |
| 3426 DownloadTest::SetUpCommandLine(command_line); | 3416 DownloadTest::SetUpCommandLine(command_line); |
| 3427 } | 3417 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3673 DangerousDownloadWaiter( | 3663 DangerousDownloadWaiter( |
| 3674 browser(), 1, | 3664 browser(), 1, |
| 3675 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3665 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3676 ui_test_utils::NavigateToURL(browser(), extension_url); | 3666 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3677 | 3667 |
| 3678 observer->WaitForFinished(); | 3668 observer->WaitForFinished(); |
| 3679 | 3669 |
| 3680 // Download shelf should close. | 3670 // Download shelf should close. |
| 3681 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3671 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3682 } | 3672 } |
| OLD | NEW |