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