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