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

Side by Side Diff: chrome/renderer/safe_browsing/features_unittest.cc

Issue 2878046: Add an extractor for DOM features to be used for client side phishing detection. (Closed)
Patch Set: address marria's comments Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/renderer/safe_browsing/features.h" 5 #include "chrome/renderer/safe_browsing/features.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace safe_browsing { 12 namespace safe_browsing {
12 13
13 TEST(PhishingFeaturesTest, TooManyFeatures) { 14 TEST(PhishingFeaturesTest, TooManyFeatures) {
14 FeatureMap features; 15 FeatureMap features;
15 for (size_t i = 0; i < FeatureMap::kMaxFeatureMapSize; ++i) { 16 for (size_t i = 0; i < FeatureMap::kMaxFeatureMapSize; ++i) {
16 EXPECT_TRUE(features.AddBooleanFeature(StringPrintf("Feature%" PRIuS, i))); 17 EXPECT_TRUE(features.AddBooleanFeature(StringPrintf("Feature%" PRIuS, i)));
17 } 18 }
18 EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size()); 19 EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size());
19 20
20 // Attempting to add more features should fail. 21 // Attempting to add more features should fail.
21 for (size_t i = 0; i < 3; ++i) { 22 for (size_t i = 0; i < 3; ++i) {
22 EXPECT_FALSE(features.AddBooleanFeature(StringPrintf("Extra%" PRIuS, i))); 23 EXPECT_FALSE(features.AddBooleanFeature(StringPrintf("Extra%" PRIuS, i)));
23 } 24 }
24 EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size()); 25 EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size());
25 } 26 }
26 27
28 TEST(PhishingFeaturesTest, IllegalFeatureValue) {
29 FeatureMap features;
30 EXPECT_FALSE(features.AddRealFeature("toosmall", -0.1));
31 EXPECT_TRUE(features.AddRealFeature("zero", 0.0));
32 EXPECT_TRUE(features.AddRealFeature("pointfive", 0.5));
33 EXPECT_TRUE(features.AddRealFeature("one", 1.0));
34 EXPECT_FALSE(features.AddRealFeature("toolarge", 1.1));
35
36 FeatureMap expected_features;
37 expected_features.AddRealFeature("zero", 0.0);
38 expected_features.AddRealFeature("pointfive", 0.5);
39 expected_features.AddRealFeature("one", 1.0);
40 EXPECT_THAT(features.features(),
41 ::testing::ContainerEq(expected_features.features()));
42 }
43
27 } // namespace safe_browsing 44 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/renderer/safe_browsing/features.cc ('k') | chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698