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/bind.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "chrome/common/safe_browsing/client_model.pb.h" | 18 #include "chrome/common/safe_browsing/client_model.pb.h" |
18 #include "chrome/common/safe_browsing/csd.pb.h" | 19 #include "chrome/common/safe_browsing/csd.pb.h" |
19 #include "chrome/renderer/safe_browsing/features.h" | 20 #include "chrome/renderer/safe_browsing/features.h" |
20 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 21 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
21 #include "chrome/renderer/safe_browsing/murmurhash3_util.h" | 22 #include "chrome/renderer/safe_browsing/murmurhash3_util.h" |
22 #include "chrome/renderer/safe_browsing/scorer.h" | 23 #include "chrome/renderer/safe_browsing/scorer.h" |
23 #include "content/test/render_view_fake_resources_test.h" | 24 #include "content/test/render_view_fake_resources_test.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // false otherwise. | 93 // false otherwise. |
93 bool RunPhishingClassifier(const string16* page_text, | 94 bool RunPhishingClassifier(const string16* page_text, |
94 float* phishy_score, | 95 float* phishy_score, |
95 FeatureMap* features) { | 96 FeatureMap* features) { |
96 verdict_.Clear(); | 97 verdict_.Clear(); |
97 *phishy_score = PhishingClassifier::kInvalidScore; | 98 *phishy_score = PhishingClassifier::kInvalidScore; |
98 features->Clear(); | 99 features->Clear(); |
99 | 100 |
100 classifier_->BeginClassification( | 101 classifier_->BeginClassification( |
101 page_text, | 102 page_text, |
102 NewCallback(this, &PhishingClassifierTest::ClassificationFinished)); | 103 base::Bind(&PhishingClassifierTest::ClassificationFinished, |
| 104 base::Unretained(this))); |
103 message_loop_.Run(); | 105 message_loop_.Run(); |
104 | 106 |
105 *phishy_score = verdict_.client_score(); | 107 *phishy_score = verdict_.client_score(); |
106 for (int i = 0; i < verdict_.feature_map_size(); ++i) { | 108 for (int i = 0; i < verdict_.feature_map_size(); ++i) { |
107 features->AddRealFeature(verdict_.feature_map(i).name(), | 109 features->AddRealFeature(verdict_.feature_map(i).name(), |
108 verdict_.feature_map(i).value()); | 110 verdict_.feature_map(i).value()); |
109 } | 111 } |
110 return verdict_.is_phishing(); | 112 return verdict_.is_phishing(); |
111 } | 113 } |
112 | 114 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Now set the scorer. | 202 // Now set the scorer. |
201 classifier_->set_phishing_scorer(scorer_.get()); | 203 classifier_->set_phishing_scorer(scorer_.get()); |
202 EXPECT_TRUE(classifier_->is_ready()); | 204 EXPECT_TRUE(classifier_->is_ready()); |
203 | 205 |
204 // Set a NULL scorer, which turns detection back off. | 206 // Set a NULL scorer, which turns detection back off. |
205 classifier_->set_phishing_scorer(NULL); | 207 classifier_->set_phishing_scorer(NULL); |
206 EXPECT_FALSE(classifier_->is_ready()); | 208 EXPECT_FALSE(classifier_->is_ready()); |
207 } | 209 } |
208 | 210 |
209 } // namespace safe_browsing | 211 } // namespace safe_browsing |
OLD | NEW |