OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/safe_browsing/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 history_service()->AddPage(GURL("http://www.baz.com/"), | 265 history_service()->AddPage(GURL("http://www.baz.com/"), |
266 history::SOURCE_BROWSED); | 266 history::SOURCE_BROWSED); |
267 | 267 |
268 ClientPhishingRequest request; | 268 ClientPhishingRequest request; |
269 request.set_url("http://www.foo.com/"); | 269 request.set_url("http://www.foo.com/"); |
270 request.set_client_score(0.5); | 270 request.set_client_score(0.5); |
271 std::vector<GURL> redirect_chain; | 271 std::vector<GURL> redirect_chain; |
272 redirect_chain.push_back(GURL("http://somerandomwebsite.com/")); | 272 redirect_chain.push_back(GURL("http://somerandomwebsite.com/")); |
273 redirect_chain.push_back(GURL("http://www.foo.com/")); | 273 redirect_chain.push_back(GURL("http://www.foo.com/")); |
274 SetRedirectChain(redirect_chain, true); | 274 SetRedirectChain(redirect_chain, true); |
| 275 browse_info_->http_status_code = 200; |
275 NavigateAndCommit(GURL("http://www.foo.com/"), | 276 NavigateAndCommit(GURL("http://www.foo.com/"), |
276 GURL("http://google.com/"), | 277 GURL("http://google.com/"), |
277 content::PageTransitionFromInt( | 278 content::PageTransitionFromInt( |
278 content::PAGE_TRANSITION_AUTO_BOOKMARK | | 279 content::PAGE_TRANSITION_AUTO_BOOKMARK | |
279 content::PAGE_TRANSITION_FORWARD_BACK)); | 280 content::PAGE_TRANSITION_FORWARD_BACK)); |
280 | 281 |
281 EXPECT_TRUE(ExtractFeatures(&request)); | 282 EXPECT_TRUE(ExtractFeatures(&request)); |
282 std::map<std::string, double> features; | 283 std::map<std::string, double> features; |
283 GetFeatureMap(request, &features); | 284 GetFeatureMap(request, &features); |
284 | 285 |
285 EXPECT_EQ(1.0, | 286 EXPECT_EQ(1.0, |
286 features[StringPrintf("%s=%s", | 287 features[StringPrintf("%s=%s", |
287 features::kReferrer, | 288 features::kReferrer, |
288 "http://google.com/")]); | 289 "http://google.com/")]); |
289 EXPECT_EQ(1.0, | 290 EXPECT_EQ(1.0, |
290 features[StringPrintf("%s[0]=%s", | 291 features[StringPrintf("%s[0]=%s", |
291 features::kRedirect, | 292 features::kRedirect, |
292 "http://somerandomwebsite.com/")]); | 293 "http://somerandomwebsite.com/")]); |
293 // We shouldn't have a feature for the last redirect in the chain, since it | 294 // We shouldn't have a feature for the last redirect in the chain, since it |
294 // should always be the URL that we navigated to. | 295 // should always be the URL that we navigated to. |
295 EXPECT_EQ(0.0, | 296 EXPECT_EQ(0.0, |
296 features[StringPrintf("%s[1]=%s", | 297 features[StringPrintf("%s[1]=%s", |
297 features::kRedirect, | 298 features::kRedirect, |
298 "http://foo.com/")]); | 299 "http://foo.com/")]); |
299 EXPECT_EQ(0.0, features[features::kHasSSLReferrer]); | 300 EXPECT_EQ(0.0, features[features::kHasSSLReferrer]); |
300 EXPECT_EQ(2.0, features[features::kPageTransitionType]); | 301 EXPECT_EQ(2.0, features[features::kPageTransitionType]); |
301 EXPECT_EQ(1.0, features[features::kIsFirstNavigation]); | 302 EXPECT_EQ(1.0, features[features::kIsFirstNavigation]); |
| 303 EXPECT_EQ(200.0, features[features::kHttpStatusCode]); |
302 | 304 |
303 request.Clear(); | 305 request.Clear(); |
304 request.set_url("http://www.foo.com/page.html"); | 306 request.set_url("http://www.foo.com/page.html"); |
305 request.set_client_score(0.5); | 307 request.set_client_score(0.5); |
306 redirect_chain.clear(); | 308 redirect_chain.clear(); |
307 redirect_chain.push_back(GURL("http://www.foo.com/redirect")); | 309 redirect_chain.push_back(GURL("http://www.foo.com/redirect")); |
308 redirect_chain.push_back(GURL("http://www.foo.com/second_redirect")); | 310 redirect_chain.push_back(GURL("http://www.foo.com/second_redirect")); |
309 redirect_chain.push_back(GURL("http://www.foo.com/page.html")); | 311 redirect_chain.push_back(GURL("http://www.foo.com/page.html")); |
310 SetRedirectChain(redirect_chain, false); | 312 SetRedirectChain(redirect_chain, false); |
| 313 browse_info_->http_status_code = 404; |
311 NavigateAndCommit(GURL("http://www.foo.com/page.html"), | 314 NavigateAndCommit(GURL("http://www.foo.com/page.html"), |
312 GURL("http://www.foo.com"), | 315 GURL("http://www.foo.com"), |
313 content::PageTransitionFromInt( | 316 content::PageTransitionFromInt( |
314 content::PAGE_TRANSITION_TYPED | | 317 content::PAGE_TRANSITION_TYPED | |
315 content::PAGE_TRANSITION_CHAIN_START | | 318 content::PAGE_TRANSITION_CHAIN_START | |
316 content::PAGE_TRANSITION_CLIENT_REDIRECT)); | 319 content::PAGE_TRANSITION_CLIENT_REDIRECT)); |
317 | 320 |
318 EXPECT_TRUE(ExtractFeatures(&request)); | 321 EXPECT_TRUE(ExtractFeatures(&request)); |
319 features.clear(); | 322 features.clear(); |
320 GetFeatureMap(request, &features); | 323 GetFeatureMap(request, &features); |
(...skipping 24 matching lines...) Expand all Loading... |
345 features::kRedirect, | 348 features::kRedirect, |
346 "http://somerandomwebsite.com/")]); | 349 "http://somerandomwebsite.com/")]); |
347 EXPECT_EQ(2.0, | 350 EXPECT_EQ(2.0, |
348 features[StringPrintf("%s%s", | 351 features[StringPrintf("%s%s", |
349 features::kHostPrefix, | 352 features::kHostPrefix, |
350 features::kPageTransitionType)]); | 353 features::kPageTransitionType)]); |
351 EXPECT_EQ(1.0, | 354 EXPECT_EQ(1.0, |
352 features[StringPrintf("%s%s", | 355 features[StringPrintf("%s%s", |
353 features::kHostPrefix, | 356 features::kHostPrefix, |
354 features::kIsFirstNavigation)]); | 357 features::kIsFirstNavigation)]); |
| 358 EXPECT_EQ(404.0, features[features::kHttpStatusCode]); |
355 | 359 |
356 request.Clear(); | 360 request.Clear(); |
357 request.set_url("http://www.bar.com/"); | 361 request.set_url("http://www.bar.com/"); |
358 request.set_client_score(0.5); | 362 request.set_client_score(0.5); |
359 redirect_chain.clear(); | 363 redirect_chain.clear(); |
360 redirect_chain.push_back(GURL("http://www.foo.com/page.html")); | 364 redirect_chain.push_back(GURL("http://www.foo.com/page.html")); |
361 redirect_chain.push_back(GURL("http://www.bar.com/")); | 365 redirect_chain.push_back(GURL("http://www.bar.com/")); |
362 SetRedirectChain(redirect_chain, true); | 366 SetRedirectChain(redirect_chain, true); |
363 NavigateAndCommit(GURL("http://www.bar.com/"), | 367 NavigateAndCommit(GURL("http://www.bar.com/"), |
364 GURL("http://www.foo.com/page.html"), | 368 GURL("http://www.foo.com/page.html"), |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 EXPECT_TRUE(features.count(StringPrintf("%s%s", | 495 EXPECT_TRUE(features.count(StringPrintf("%s%s", |
492 features::kSafeBrowsingMaliciousUrl, | 496 features::kSafeBrowsingMaliciousUrl, |
493 "http://www.malware.com/"))); | 497 "http://www.malware.com/"))); |
494 EXPECT_TRUE(features.count(StringPrintf("%s%s", | 498 EXPECT_TRUE(features.count(StringPrintf("%s%s", |
495 features::kSafeBrowsingOriginalUrl, | 499 features::kSafeBrowsingOriginalUrl, |
496 "http://www.good.com/"))); | 500 "http://www.good.com/"))); |
497 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); | 501 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); |
498 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); | 502 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); |
499 } | 503 } |
500 } // namespace safe_browsing | 504 } // namespace safe_browsing |
OLD | NEW |