Chromium Code Reviews| 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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 | 1070 |
| 1071 // Location of the test data. | 1071 // Location of the test data. |
| 1072 base::FilePath test_dir_; | 1072 base::FilePath test_dir_; |
| 1073 | 1073 |
| 1074 // Location of the downloads directory for these tests | 1074 // Location of the downloads directory for these tests |
| 1075 base::ScopedTempDir downloads_directory_; | 1075 base::ScopedTempDir downloads_directory_; |
| 1076 | 1076 |
| 1077 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_; | 1077 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_; |
| 1078 }; | 1078 }; |
| 1079 | 1079 |
| 1080 class FakeDownloadProtectionService | 1080 namespace { |
| 1081 : public safe_browsing::DownloadProtectionService { | |
| 1082 public: | |
| 1083 FakeDownloadProtectionService() | |
| 1084 : safe_browsing::DownloadProtectionService(nullptr, nullptr) {} | |
| 1085 | 1081 |
| 1086 void CheckClientDownload(DownloadItem* download_item, | 1082 class FakeDownloadProtectionService |
|
Nico
2016/03/21 19:51:01
don't intend inside of namespaces.
(in general, r
| |
| 1087 const CheckDownloadCallback& callback) override { | 1083 : public safe_browsing::DownloadProtectionService { |
| 1088 callback.Run( | 1084 public: |
| 1089 safe_browsing::DownloadProtectionService::UNCOMMON); | 1085 FakeDownloadProtectionService() |
| 1090 } | 1086 : safe_browsing::DownloadProtectionService(nullptr, nullptr) {} |
| 1091 }; | |
| 1092 | 1087 |
| 1093 class FakeSafeBrowsingService : public safe_browsing::SafeBrowsingService { | 1088 void CheckClientDownload(DownloadItem* download_item, |
| 1094 public: | 1089 const CheckDownloadCallback& callback) override { |
| 1095 FakeSafeBrowsingService() {} | 1090 callback.Run( |
| 1091 safe_browsing::DownloadProtectionService::UNCOMMON); | |
| 1092 } | |
| 1093 }; | |
| 1096 | 1094 |
| 1097 safe_browsing::DownloadProtectionService* CreateDownloadProtectionService( | 1095 class FakeSafeBrowsingService : public safe_browsing::SafeBrowsingService { |
| 1098 net::URLRequestContextGetter* not_used_request_context_getter) override { | 1096 public: |
| 1099 return new FakeDownloadProtectionService(); | 1097 FakeSafeBrowsingService() {} |
| 1100 } | |
| 1101 | 1098 |
| 1102 std::string GetDownloadReport() const { return report_; } | 1099 safe_browsing::DownloadProtectionService* CreateDownloadProtectionService( |
| 1100 net::URLRequestContextGetter* unused_request_context_getter) override { | |
| 1101 return new FakeDownloadProtectionService(); | |
| 1102 } | |
| 1103 | 1103 |
| 1104 protected: | 1104 std::string GetDownloadReport() const { return report_; } |
| 1105 ~FakeSafeBrowsingService() override {} | |
| 1106 | 1105 |
| 1107 void SendSerializedDownloadReport(const std::string& report) override { | 1106 protected: |
| 1108 report_ = report; | 1107 ~FakeSafeBrowsingService() override {} |
| 1109 } | |
| 1110 | 1108 |
| 1111 std::string report_; | 1109 void SendSerializedDownloadReport(const std::string& report) override { |
| 1112 }; | 1110 report_ = report; |
| 1111 } | |
| 1113 | 1112 |
| 1114 // Factory that creates FakeSafeBrowsingService instances. | 1113 std::string report_; |
| 1115 class TestSafeBrowsingServiceFactory | 1114 }; |
| 1116 : public safe_browsing::SafeBrowsingServiceFactory { | |
| 1117 public: | |
| 1118 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {} | |
| 1119 ~TestSafeBrowsingServiceFactory() override {} | |
| 1120 | 1115 |
| 1121 safe_browsing::SafeBrowsingService* CreateSafeBrowsingService() override { | 1116 // Factory that creates FakeSafeBrowsingService instances. |
| 1122 DCHECK(!fake_safe_browsing_service_); | 1117 class TestSafeBrowsingServiceFactory |
| 1123 fake_safe_browsing_service_ = new FakeSafeBrowsingService(); | 1118 : public safe_browsing::SafeBrowsingServiceFactory { |
| 1124 return fake_safe_browsing_service_.get(); | 1119 public: |
| 1125 } | 1120 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {} |
| 1121 ~TestSafeBrowsingServiceFactory() override {} | |
| 1126 | 1122 |
| 1127 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service() { | 1123 safe_browsing::SafeBrowsingService* CreateSafeBrowsingService() override { |
| 1128 return fake_safe_browsing_service_; | 1124 DCHECK(!fake_safe_browsing_service_); |
| 1129 } | 1125 fake_safe_browsing_service_ = new FakeSafeBrowsingService(); |
| 1126 return fake_safe_browsing_service_.get(); | |
| 1127 } | |
| 1130 | 1128 |
| 1131 private: | 1129 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service() { |
| 1132 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service_; | 1130 return fake_safe_browsing_service_; |
| 1133 }; | 1131 } |
| 1134 | 1132 |
| 1135 class DownloadTestWithFakeSafeBrowsing : public DownloadTest { | 1133 private: |
| 1136 public: | 1134 scoped_refptr<FakeSafeBrowsingService> fake_safe_browsing_service_; |
| 1137 DownloadTestWithFakeSafeBrowsing() | 1135 }; |
| 1138 : test_safe_browsing_factory_(new TestSafeBrowsingServiceFactory()) {} | |
| 1139 | 1136 |
| 1140 void SetUp() override { | 1137 class DownloadTestWithFakeSafeBrowsing : public DownloadTest { |
| 1141 safe_browsing::SafeBrowsingService::RegisterFactory( | 1138 public: |
| 1142 test_safe_browsing_factory_.get()); | 1139 DownloadTestWithFakeSafeBrowsing() |
| 1143 DownloadTest::SetUp(); | 1140 : test_safe_browsing_factory_(new TestSafeBrowsingServiceFactory()) {} |
| 1144 } | |
| 1145 | 1141 |
| 1146 void TearDown() override { | 1142 void SetUp() override { |
| 1147 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr); | 1143 safe_browsing::SafeBrowsingService::RegisterFactory( |
| 1148 DownloadTest::TearDown(); | 1144 test_safe_browsing_factory_.get()); |
| 1149 } | 1145 DownloadTest::SetUp(); |
| 1146 } | |
| 1150 | 1147 |
| 1151 protected: | 1148 void TearDown() override { |
| 1152 scoped_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_; | 1149 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr); |
| 1153 }; | 1150 DownloadTest::TearDown(); |
| 1151 } | |
| 1152 | |
| 1153 protected: | |
| 1154 scoped_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_; | |
| 1155 }; | |
| 1156 | |
| 1157 } // namespace | |
| 1154 | 1158 |
| 1155 // NOTES: | 1159 // NOTES: |
| 1156 // | 1160 // |
| 1157 // Files for these tests are found in DIR_TEST_DATA (currently | 1161 // Files for these tests are found in DIR_TEST_DATA (currently |
| 1158 // "chrome\test\data\", see chrome_paths.cc). | 1162 // "chrome\test\data\", see chrome_paths.cc). |
| 1159 // Mock responses have extension .mock-http-headers appended to the file name. | 1163 // Mock responses have extension .mock-http-headers appended to the file name. |
| 1160 | 1164 |
| 1161 // Download a file due to the associated MIME type. | 1165 // Download a file due to the associated MIME type. |
| 1162 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 1166 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
| 1163 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 1167 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| (...skipping 2499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3663 | 3667 |
| 3664 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3668 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
| 3665 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3669 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3666 ui_test_utils::NavigateToURL(browser(), extension_url); | 3670 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3667 | 3671 |
| 3668 observer->WaitForFinished(); | 3672 observer->WaitForFinished(); |
| 3669 | 3673 |
| 3670 // Download shelf should close. | 3674 // Download shelf should close. |
| 3671 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3675 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3672 } | 3676 } |
| OLD | NEW |