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