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/renderer/safe_browsing/scorer.h" | 5 #include "chrome/renderer/safe_browsing/scorer.h" |
6 | 6 |
7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "chrome/common/safe_browsing/client_model.pb.h" | 14 #include "chrome/common/safe_browsing/client_model.pb.h" |
15 #include "chrome/renderer/safe_browsing/features.h" | 15 #include "chrome/renderer/safe_browsing/features.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace safe_browsing { | 19 namespace safe_browsing { |
20 | 20 |
21 class PhishingScorerTest : public ::testing::Test { | 21 class PhishingScorerTest : public ::testing::Test { |
22 protected: | 22 protected: |
23 virtual void SetUp() { | 23 void SetUp() override { |
24 // Setup a simple model. Note that the scorer does not care about | 24 // Setup a simple model. Note that the scorer does not care about |
25 // how features are encoded so we use readable strings here to make | 25 // how features are encoded so we use readable strings here to make |
26 // the test simpler to follow. | 26 // the test simpler to follow. |
27 model_.Clear(); | 27 model_.Clear(); |
28 model_.add_hashes("feature1"); | 28 model_.add_hashes("feature1"); |
29 model_.add_hashes("feature2"); | 29 model_.add_hashes("feature2"); |
30 model_.add_hashes("feature3"); | 30 model_.add_hashes("feature3"); |
31 model_.add_hashes("token one"); | 31 model_.add_hashes("token one"); |
32 model_.add_hashes("token two"); | 32 model_.add_hashes("token two"); |
33 | 33 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 EXPECT_DOUBLE_EQ(0.6899744811276125, scorer->ComputeScore(features)); | 137 EXPECT_DOUBLE_EQ(0.6899744811276125, scorer->ComputeScore(features)); |
138 | 138 |
139 // Now, both feature 1 and feature 2 match. Expected logodds: | 139 // Now, both feature 1 and feature 2 match. Expected logodds: |
140 // 0.5 (empty rule) + 2.0 (rule weight) * 0.15 (feature weight) + | 140 // 0.5 (empty rule) + 2.0 (rule weight) * 0.15 (feature weight) + |
141 // 3.0 (rule weight) * 0.15 (feature1 weight) * 1.0 (feature2) weight = 9.8 | 141 // 3.0 (rule weight) * 0.15 (feature1 weight) * 1.0 (feature2) weight = 9.8 |
142 // => p = 0.99999627336071584 | 142 // => p = 0.99999627336071584 |
143 EXPECT_TRUE(features.AddBooleanFeature("feature2")); | 143 EXPECT_TRUE(features.AddBooleanFeature("feature2")); |
144 EXPECT_DOUBLE_EQ(0.77729986117469119, scorer->ComputeScore(features)); | 144 EXPECT_DOUBLE_EQ(0.77729986117469119, scorer->ComputeScore(features)); |
145 } | 145 } |
146 } // namespace safe_browsing | 146 } // namespace safe_browsing |
OLD | NEW |