summaryrefslogtreecommitdiff
path: root/chromium/chrome/renderer/safe_browsing/features_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/renderer/safe_browsing/features_unittest.cc')
-rw-r--r--chromium/chrome/renderer/safe_browsing/features_unittest.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/chromium/chrome/renderer/safe_browsing/features_unittest.cc b/chromium/chrome/renderer/safe_browsing/features_unittest.cc
new file mode 100644
index 00000000000..0ba14e71f7c
--- /dev/null
+++ b/chromium/chrome/renderer/safe_browsing/features_unittest.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/safe_browsing/features.h"
+
+#include <stddef.h>
+
+#include "base/format_macros.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/renderer/safe_browsing/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace safe_browsing {
+
+TEST(PhishingFeaturesTest, TooManyFeatures) {
+ FeatureMap features;
+ for (size_t i = 0; i < FeatureMap::kMaxFeatureMapSize; ++i) {
+ EXPECT_TRUE(features.AddBooleanFeature(
+ base::StringPrintf("Feature%" PRIuS, i)));
+ }
+ EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size());
+
+ // Attempting to add more features should fail.
+ for (size_t i = 0; i < 3; ++i) {
+ EXPECT_FALSE(features.AddBooleanFeature(
+ base::StringPrintf("Extra%" PRIuS, i)));
+ }
+ EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size());
+}
+
+TEST(PhishingFeaturesTest, IllegalFeatureValue) {
+ FeatureMap features;
+ EXPECT_FALSE(features.AddRealFeature("toosmall", -0.1));
+ EXPECT_TRUE(features.AddRealFeature("zero", 0.0));
+ EXPECT_TRUE(features.AddRealFeature("pointfive", 0.5));
+ EXPECT_TRUE(features.AddRealFeature("one", 1.0));
+ EXPECT_FALSE(features.AddRealFeature("toolarge", 1.1));
+
+ FeatureMap expected_features;
+ expected_features.AddRealFeature("zero", 0.0);
+ expected_features.AddRealFeature("pointfive", 0.5);
+ expected_features.AddRealFeature("one", 1.0);
+ ExpectFeatureMapsAreEqual(features, expected_features);
+}
+
+} // namespace safe_browsing