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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc
diff --git a/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc b/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc
index f3337555c28d1ee7fa8a4eade438617f8041fdd8..3156f2823130330c1e587400b1ade9bf370ae5cd 100644
--- a/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc
+++ b/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/safe_browsing/browser_features.h"
#include "chrome/browser/safe_browsing/client_side_detection_service.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/browser_thread.h"
@@ -23,6 +24,7 @@
#include "content/browser/tab_contents/test_tab_contents.h"
#include "content/common/page_transition_types.h"
#include "content/common/view_messages.h"
+#include "crypto/sha2.h"
#include "googleurl/src/gurl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -474,4 +476,52 @@ TEST_F(BrowserFeatureExtractorTest, SafeBrowsingFeatures) {
EXPECT_DOUBLE_EQ(1.0, features[features::kSafeBrowsingIsSubresource]);
EXPECT_DOUBLE_EQ(2.0, features[features::kSafeBrowsingThreatType]);
}
+
+TEST_F(BrowserFeatureExtractorTest, URLHashes) {
+ ClientPhishingRequest request;
+ request.set_url("http://host.com/");
+ request.set_client_score(0.8f);
+
+ history_service()->AddPage(GURL("http://host.com/"),
+ history::SOURCE_BROWSED);
+ contents()->NavigateAndCommit(GURL("http://host.com/"));
+
+ EXPECT_TRUE(ExtractFeatures(&request));
+ EXPECT_EQ(crypto::SHA256HashString("host.com/").substr(
+ 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
+ request.suffix_prefix_hash());
+
+ request.set_url("http://www.host.com/path/");
+ history_service()->AddPage(GURL("http://www.host.com/path/"),
+ history::SOURCE_BROWSED);
+ contents()->NavigateAndCommit(GURL("http://www.host.com/path/"));
+
+ EXPECT_TRUE(ExtractFeatures(&request));
+ EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/").substr(
+ 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
+ request.suffix_prefix_hash());
+
+ request.set_url("http://user@www.host.com:1111/path/123?args");
+ history_service()->AddPage(
+ GURL("http://user@www.host.com:1111/path/123?args"),
+ history::SOURCE_BROWSED);
+ contents()->NavigateAndCommit(
+ GURL("http://user@www.host.com:1111/path/123?args"));
+
+ EXPECT_TRUE(ExtractFeatures(&request));
+ EXPECT_EQ(crypto::SHA256HashString("www.host.com/path/123").substr(
+ 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
+ request.suffix_prefix_hash());
+
+ // Check that escaping matches the SafeBrowsing specification.
+ request.set_url("http://www.host.com/A%21//B");
+ history_service()->AddPage(GURL("http://www.host.com/A%21//B"),
+ history::SOURCE_BROWSED);
+ contents()->NavigateAndCommit(GURL("http://www.host.com/A%21//B"));
+
+ EXPECT_TRUE(ExtractFeatures(&request));
+ EXPECT_EQ(crypto::SHA256HashString("www.host.com/A!/B").substr(
+ 0, BrowserFeatureExtractor::kSuffixPrefixHashLength),
+ request.suffix_prefix_hash());
+}
} // namespace safe_browsing
« 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