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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 | 1074 |
1075 VerifyResults(actual, expected); | 1075 VerifyResults(actual, expected); |
1076 } | 1076 } |
1077 | 1077 |
1078 // Tests the interaction with the HTTP cache. | 1078 // Tests the interaction with the HTTP cache. |
1079 TEST_F(ThreatDetailsTest, HTTPCache) { | 1079 TEST_F(ThreatDetailsTest, HTTPCache) { |
1080 content::WebContentsTester::For(web_contents()) | 1080 content::WebContentsTester::For(web_contents()) |
1081 ->NavigateAndCommit(GURL(kLandingURL)); | 1081 ->NavigateAndCommit(GURL(kLandingURL)); |
1082 | 1082 |
1083 UnsafeResource resource; | 1083 UnsafeResource resource; |
1084 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, | 1084 InitResource(&resource, SB_THREAT_TYPE_URL_CLIENT_SIDE_PHISHING, |
1085 true /* is_subresource */, GURL(kThreatURL)); | 1085 true /* is_subresource */, GURL(kThreatURL)); |
1086 | 1086 |
1087 scoped_refptr<ThreatDetailsWrap> report = | 1087 scoped_refptr<ThreatDetailsWrap> report = |
1088 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 1088 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
1089 profile()->GetRequestContext(), history_service()); | 1089 profile()->GetRequestContext(), history_service()); |
1090 | 1090 |
1091 BrowserThread::PostTask( | 1091 BrowserThread::PostTask( |
1092 BrowserThread::IO, FROM_HERE, | 1092 BrowserThread::IO, FROM_HERE, |
1093 base::BindOnce(&FillCache, | 1093 base::BindOnce(&FillCache, |
1094 base::RetainedRef(profile()->GetRequestContext()))); | 1094 base::RetainedRef(profile()->GetRequestContext()))); |
1095 | 1095 |
1096 // The cache collection starts after the IPC from the DOM is fired. | 1096 // The cache collection starts after the IPC from the DOM is fired. |
1097 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1097 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
1098 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1098 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
1099 | 1099 |
1100 // Let the cache callbacks complete. | 1100 // Let the cache callbacks complete. |
1101 base::RunLoop().RunUntilIdle(); | 1101 base::RunLoop().RunUntilIdle(); |
1102 | 1102 |
1103 DVLOG(1) << "Getting serialized report"; | 1103 DVLOG(1) << "Getting serialized report"; |
1104 std::string serialized = WaitForSerializedReport( | 1104 std::string serialized = WaitForSerializedReport( |
1105 report.get(), true /* did_proceed*/, -1 /* num_visit */); | 1105 report.get(), true /* did_proceed*/, -1 /* num_visit */); |
1106 ClientSafeBrowsingReportRequest actual; | 1106 ClientSafeBrowsingReportRequest actual; |
1107 actual.ParseFromString(serialized); | 1107 actual.ParseFromString(serialized); |
1108 | 1108 |
1109 ClientSafeBrowsingReportRequest expected; | 1109 ClientSafeBrowsingReportRequest expected; |
1110 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_PHISHING_URL); | 1110 expected.set_type(ClientSafeBrowsingReportRequest::URL_CLIENT_SIDE_PHISHING); |
1111 expected.set_url(kThreatURL); | 1111 expected.set_url(kThreatURL); |
1112 expected.set_page_url(kLandingURL); | 1112 expected.set_page_url(kLandingURL); |
1113 expected.set_referrer_url(""); | 1113 expected.set_referrer_url(""); |
1114 expected.set_did_proceed(true); | 1114 expected.set_did_proceed(true); |
1115 | 1115 |
1116 ClientSafeBrowsingReportRequest::Resource* pb_resource = | 1116 ClientSafeBrowsingReportRequest::Resource* pb_resource = |
1117 expected.add_resources(); | 1117 expected.add_resources(); |
1118 pb_resource->set_id(0); | 1118 pb_resource->set_id(0); |
1119 pb_resource->set_url(kLandingURL); | 1119 pb_resource->set_url(kLandingURL); |
1120 ClientSafeBrowsingReportRequest::HTTPResponse* pb_response = | 1120 ClientSafeBrowsingReportRequest::HTTPResponse* pb_response = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 VerifyResults(actual, expected); | 1157 VerifyResults(actual, expected); |
1158 } | 1158 } |
1159 | 1159 |
1160 // Test that only some fields of the HTTPS resource (eg: whitelisted headers) | 1160 // Test that only some fields of the HTTPS resource (eg: whitelisted headers) |
1161 // are reported. | 1161 // are reported. |
1162 TEST_F(ThreatDetailsTest, HttpsResourceSanitization) { | 1162 TEST_F(ThreatDetailsTest, HttpsResourceSanitization) { |
1163 content::WebContentsTester::For(web_contents()) | 1163 content::WebContentsTester::For(web_contents()) |
1164 ->NavigateAndCommit(GURL(kLandingURL)); | 1164 ->NavigateAndCommit(GURL(kLandingURL)); |
1165 | 1165 |
1166 UnsafeResource resource; | 1166 UnsafeResource resource; |
1167 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, | 1167 InitResource(&resource, SB_THREAT_TYPE_URL_CLIENT_SIDE_PHISHING, |
1168 true /* is_subresource */, GURL(kThreatURLHttps)); | 1168 true /* is_subresource */, GURL(kThreatURLHttps)); |
1169 | 1169 |
1170 scoped_refptr<ThreatDetailsWrap> report = | 1170 scoped_refptr<ThreatDetailsWrap> report = |
1171 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 1171 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
1172 profile()->GetRequestContext(), history_service()); | 1172 profile()->GetRequestContext(), history_service()); |
1173 | 1173 |
1174 BrowserThread::PostTask( | 1174 BrowserThread::PostTask( |
1175 BrowserThread::IO, FROM_HERE, | 1175 BrowserThread::IO, FROM_HERE, |
1176 base::BindOnce(&FillCacheHttps, | 1176 base::BindOnce(&FillCacheHttps, |
1177 base::RetainedRef(profile()->GetRequestContext()))); | 1177 base::RetainedRef(profile()->GetRequestContext()))); |
1178 | 1178 |
1179 // The cache collection starts after the IPC from the DOM is fired. | 1179 // The cache collection starts after the IPC from the DOM is fired. |
1180 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1180 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
1181 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1181 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
1182 | 1182 |
1183 // Let the cache callbacks complete. | 1183 // Let the cache callbacks complete. |
1184 base::RunLoop().RunUntilIdle(); | 1184 base::RunLoop().RunUntilIdle(); |
1185 | 1185 |
1186 DVLOG(1) << "Getting serialized report"; | 1186 DVLOG(1) << "Getting serialized report"; |
1187 std::string serialized = WaitForSerializedReport( | 1187 std::string serialized = WaitForSerializedReport( |
1188 report.get(), true /* did_proceed*/, -1 /* num_visit */); | 1188 report.get(), true /* did_proceed*/, -1 /* num_visit */); |
1189 ClientSafeBrowsingReportRequest actual; | 1189 ClientSafeBrowsingReportRequest actual; |
1190 actual.ParseFromString(serialized); | 1190 actual.ParseFromString(serialized); |
1191 | 1191 |
1192 ClientSafeBrowsingReportRequest expected; | 1192 ClientSafeBrowsingReportRequest expected; |
1193 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_PHISHING_URL); | 1193 expected.set_type(ClientSafeBrowsingReportRequest::URL_CLIENT_SIDE_PHISHING); |
1194 expected.set_url(kThreatURLHttps); | 1194 expected.set_url(kThreatURLHttps); |
1195 expected.set_page_url(kLandingURL); | 1195 expected.set_page_url(kLandingURL); |
1196 expected.set_referrer_url(""); | 1196 expected.set_referrer_url(""); |
1197 expected.set_did_proceed(true); | 1197 expected.set_did_proceed(true); |
1198 | 1198 |
1199 ClientSafeBrowsingReportRequest::Resource* pb_resource = | 1199 ClientSafeBrowsingReportRequest::Resource* pb_resource = |
1200 expected.add_resources(); | 1200 expected.add_resources(); |
1201 pb_resource->set_id(0); | 1201 pb_resource->set_id(0); |
1202 pb_resource->set_url(kLandingURL); | 1202 pb_resource->set_url(kLandingURL); |
1203 ClientSafeBrowsingReportRequest::HTTPResponse* pb_response = | 1203 ClientSafeBrowsingReportRequest::HTTPResponse* pb_response = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1237 |
1238 VerifyResults(actual, expected); | 1238 VerifyResults(actual, expected); |
1239 } | 1239 } |
1240 | 1240 |
1241 // Tests the interaction with the HTTP cache (where the cache is empty). | 1241 // Tests the interaction with the HTTP cache (where the cache is empty). |
1242 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { | 1242 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { |
1243 content::WebContentsTester::For(web_contents()) | 1243 content::WebContentsTester::For(web_contents()) |
1244 ->NavigateAndCommit(GURL(kLandingURL)); | 1244 ->NavigateAndCommit(GURL(kLandingURL)); |
1245 | 1245 |
1246 UnsafeResource resource; | 1246 UnsafeResource resource; |
1247 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, | 1247 InitResource(&resource, SB_THREAT_TYPE_URL_CLIENT_SIDE_MALWARE, |
1248 true /* is_subresource */, GURL(kThreatURL)); | 1248 true /* is_subresource */, GURL(kThreatURL)); |
1249 | 1249 |
1250 scoped_refptr<ThreatDetailsWrap> report = | 1250 scoped_refptr<ThreatDetailsWrap> report = |
1251 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, | 1251 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, |
1252 profile()->GetRequestContext(), history_service()); | 1252 profile()->GetRequestContext(), history_service()); |
1253 | 1253 |
1254 // No call to FillCache | 1254 // No call to FillCache |
1255 | 1255 |
1256 // The cache collection starts after the IPC from the DOM is fired. | 1256 // The cache collection starts after the IPC from the DOM is fired. |
1257 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; | 1257 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params; |
1258 report->OnReceivedThreatDOMDetails(main_rfh(), params); | 1258 report->OnReceivedThreatDOMDetails(main_rfh(), params); |
1259 | 1259 |
1260 // Let the cache callbacks complete. | 1260 // Let the cache callbacks complete. |
1261 base::RunLoop().RunUntilIdle(); | 1261 base::RunLoop().RunUntilIdle(); |
1262 | 1262 |
1263 DVLOG(1) << "Getting serialized report"; | 1263 DVLOG(1) << "Getting serialized report"; |
1264 std::string serialized = WaitForSerializedReport( | 1264 std::string serialized = WaitForSerializedReport( |
1265 report.get(), false /* did_proceed*/, -1 /* num_visit */); | 1265 report.get(), false /* did_proceed*/, -1 /* num_visit */); |
1266 ClientSafeBrowsingReportRequest actual; | 1266 ClientSafeBrowsingReportRequest actual; |
1267 actual.ParseFromString(serialized); | 1267 actual.ParseFromString(serialized); |
1268 | 1268 |
1269 ClientSafeBrowsingReportRequest expected; | 1269 ClientSafeBrowsingReportRequest expected; |
1270 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_MALWARE_URL); | 1270 expected.set_type(ClientSafeBrowsingReportRequest::URL_CLIENT_SIDE_MALWARE); |
1271 expected.set_url(kThreatURL); | 1271 expected.set_url(kThreatURL); |
1272 expected.set_page_url(kLandingURL); | 1272 expected.set_page_url(kLandingURL); |
1273 expected.set_referrer_url(""); | 1273 expected.set_referrer_url(""); |
1274 expected.set_did_proceed(false); | 1274 expected.set_did_proceed(false); |
1275 | 1275 |
1276 ClientSafeBrowsingReportRequest::Resource* pb_resource = | 1276 ClientSafeBrowsingReportRequest::Resource* pb_resource = |
1277 expected.add_resources(); | 1277 expected.add_resources(); |
1278 pb_resource->set_id(0); | 1278 pb_resource->set_id(0); |
1279 pb_resource->set_url(kLandingURL); | 1279 pb_resource->set_url(kLandingURL); |
1280 pb_resource = expected.add_resources(); | 1280 pb_resource = expected.add_resources(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 pb_resource->set_parent_id(3); | 1340 pb_resource->set_parent_id(3); |
1341 pb_resource->set_url(kSecondRedirectURL); | 1341 pb_resource->set_url(kSecondRedirectURL); |
1342 pb_resource = expected.add_resources(); | 1342 pb_resource = expected.add_resources(); |
1343 pb_resource->set_id(3); | 1343 pb_resource->set_id(3); |
1344 pb_resource->set_url(kFirstRedirectURL); | 1344 pb_resource->set_url(kFirstRedirectURL); |
1345 | 1345 |
1346 VerifyResults(actual, expected); | 1346 VerifyResults(actual, expected); |
1347 } | 1347 } |
1348 | 1348 |
1349 } // namespace safe_browsing | 1349 } // namespace safe_browsing |
OLD | NEW |