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 // Note that although this is not a "browser" test, it runs as part of | 5 // Note that although this is not a "browser" test, it runs as part of |
6 // browser_tests. This is because WebKit does not work properly if it is | 6 // browser_tests. This is because WebKit does not work properly if it is |
7 // shutdown and re-initialized. Since browser_tests runs each test in a | 7 // shutdown and re-initialized. Since browser_tests runs each test in a |
8 // new process, this avoids the problem. | 8 // new process, this avoids the problem. |
9 | 9 |
10 #include "chrome/renderer/safe_browsing/phishing_classifier.h" | 10 #include "chrome/renderer/safe_browsing/phishing_classifier.h" |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/common/safe_browsing/client_model.pb.h" | 17 #include "chrome/common/safe_browsing/client_model.pb.h" |
18 #include "chrome/common/safe_browsing/csd.pb.h" | 18 #include "chrome/common/safe_browsing/csd.pb.h" |
19 #include "chrome/renderer/safe_browsing/features.h" | 19 #include "chrome/renderer/safe_browsing/features.h" |
20 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 20 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
| 21 #include "chrome/renderer/safe_browsing/murmurhash3_util.h" |
21 #include "chrome/renderer/safe_browsing/render_view_fake_resources_test.h" | 22 #include "chrome/renderer/safe_browsing/render_view_fake_resources_test.h" |
22 #include "chrome/renderer/safe_browsing/scorer.h" | 23 #include "chrome/renderer/safe_browsing/scorer.h" |
23 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 | 26 |
26 using ::testing::AllOf; | 27 using ::testing::AllOf; |
27 using ::testing::Contains; | 28 using ::testing::Contains; |
28 using ::testing::Not; | 29 using ::testing::Not; |
29 using ::testing::Pair; | 30 using ::testing::Pair; |
30 | 31 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // To give a phishy score, the total weight needs to be >= 0 | 66 // To give a phishy score, the total weight needs to be >= 0 |
66 // (0.5 when converted to a probability). This will only happen | 67 // (0.5 when converted to a probability). This will only happen |
67 // if all of the listed features are present. | 68 // if all of the listed features are present. |
68 rule = model.add_rule(); | 69 rule = model.add_rule(); |
69 rule->add_feature(0); | 70 rule->add_feature(0); |
70 rule->add_feature(1); | 71 rule->add_feature(1); |
71 rule->add_feature(2); | 72 rule->add_feature(2); |
72 rule->set_weight(1.0); | 73 rule->set_weight(1.0); |
73 | 74 |
74 model.add_page_term(3); | 75 model.add_page_term(3); |
75 model.add_page_word(3); | 76 model.set_murmur_hash_seed(2777808611U); |
| 77 model.add_page_word(MurmurHash3String("login", model.murmur_hash_seed())); |
76 model.set_max_words_per_term(1); | 78 model.set_max_words_per_term(1); |
77 | 79 |
78 clock_ = new MockFeatureExtractorClock; | 80 clock_ = new MockFeatureExtractorClock; |
79 scorer_.reset(Scorer::Create(model.SerializeAsString())); | 81 scorer_.reset(Scorer::Create(model.SerializeAsString())); |
80 ASSERT_TRUE(scorer_.get()); | 82 ASSERT_TRUE(scorer_.get()); |
81 classifier_.reset(new PhishingClassifier(view_, clock_)); | 83 classifier_.reset(new PhishingClassifier(view_, clock_)); |
82 } | 84 } |
83 | 85 |
84 virtual void TearDown() { | 86 virtual void TearDown() { |
85 RenderViewFakeResourcesTest::TearDown(); | 87 RenderViewFakeResourcesTest::TearDown(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); | 187 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); |
186 | 188 |
187 // Extraction should fail for this case because the URL is a POST request. | 189 // Extraction should fail for this case because the URL is a POST request. |
188 LoadURLWithPost("http://host.net/"); | 190 LoadURLWithPost("http://host.net/"); |
189 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); | 191 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); |
190 EXPECT_EQ(0U, features.features().size()); | 192 EXPECT_EQ(0U, features.features().size()); |
191 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); | 193 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); |
192 } | 194 } |
193 | 195 |
194 } // namespace safe_browsing | 196 } // namespace safe_browsing |
OLD | NEW |