Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc

Issue 7635010: Add support for client-side phishing detection for non-UMA users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename method Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/common/safe_browsing/csd.pb.h" 14 #include "chrome/common/safe_browsing/csd.pb.h"
15 #include "chrome/browser/history/history.h" 15 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_backend.h" 16 #include "chrome/browser/history/history_backend.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/safe_browsing/browser_features.h"
18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 19 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
19 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
20 #include "content/browser/browser_thread.h" 21 #include "content/browser/browser_thread.h"
21 #include "content/browser/renderer_host/test_render_view_host.h" 22 #include "content/browser/renderer_host/test_render_view_host.h"
22 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/browser/tab_contents/test_tab_contents.h" 24 #include "content/browser/tab_contents/test_tab_contents.h"
24 #include "content/common/page_transition_types.h" 25 #include "content/common/page_transition_types.h"
25 #include "content/common/view_messages.h" 26 #include "content/common/view_messages.h"
27 #include "crypto/sha2.h"
26 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
27 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
30 using ::testing::Return; 32 using ::testing::Return;
31 using ::testing::StrictMock; 33 using ::testing::StrictMock;
32 34
33 namespace safe_browsing { 35 namespace safe_browsing {
34 namespace { 36 namespace {
35 class MockClientSideDetectionService : public ClientSideDetectionService { 37 class MockClientSideDetectionService : public ClientSideDetectionService {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 GetFeatureMap(request, &features); 469 GetFeatureMap(request, &features);
468 EXPECT_TRUE(features.count(StringPrintf("%s%s", 470 EXPECT_TRUE(features.count(StringPrintf("%s%s",
469 features::kSafeBrowsingMaliciousUrl, 471 features::kSafeBrowsingMaliciousUrl,
470 "http://www.malware.com/"))); 472 "http://www.malware.com/")));
471 EXPECT_TRUE(features.count(StringPrintf("%s%s", 473 EXPECT_TRUE(features.count(StringPrintf("%s%s",
472 features::kSafeBrowsingOriginalUrl, 474 features::kSafeBrowsingOriginalUrl,
473 "http://www.good.com/"))); 475 "http://www.good.com/")));
474 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]); 476 EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]);
475 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]); 477 EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]);
476 } 478 }
479
480 TEST_F(BrowserFeatureExtractorTest, URLHashes) {
481 ClientPhishingRequest request;
482 request.set_url("http://host.com/");
483 request.set_client_score(0.8f);
484
485 history_service()->AddPage(GURL("http://host.com/"),
486 history::SOURCE_BROWSED);
487 contents()->NavigateAndCommit(GURL("http://host.com/"));
488
489 EXPECT_TRUE(ExtractFeatures(&request));
490 EXPECT_EQ(crypto::SHA256HashString("host.com/").substr(
491 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
492 request.suffix_prefix_hash());
493
494 request.set_url("http://www.host.com/path/");
495 history_service()->AddPage(GURL("http://www.host.com/path/"),
496 history::SOURCE_BROWSED);
497 contents()->NavigateAndCommit(GURL("http://www.host.com/path/"));
498
499 EXPECT_TRUE(ExtractFeatures(&request));
500 EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/").substr(
501 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
502 request.suffix_prefix_hash());
503
504 request.set_url("http://user@www.host.com:1111/path/123?args");
505 history_service()->AddPage(
506 GURL("http://user@www.host.com:1111/path/123?args"),
507 history::SOURCE_BROWSED);
508 contents()->NavigateAndCommit(
509 GURL("http://user@www.host.com:1111/path/123?args"));
510
511 EXPECT_TRUE(ExtractFeatures(&request));
512 EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/123").substr(
513 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
514 request.suffix_prefix_hash());
515
516 // Check that escaping matches the SafeBrowsing specification.
517 request.set_url("http://www.host.com/A%21//B");
518 history_service()->AddPage(GURL("http://www.host.com/A%21//B"),
519 history::SOURCE_BROWSED);
520 contents()->NavigateAndCommit(GURL("http://www.host.com/A%21//B"));
521
522 EXPECT_TRUE(ExtractFeatures(&request));
523 EXPECT_EQ(crypto::SHA256HashString("www.host.com/A!/B").substr(
524 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
525 request.suffix_prefix_hash());
526 }
477 } // namespace safe_browsing 527 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/browser_feature_extractor.cc ('k') | chrome/browser/safe_browsing/browser_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698