OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/phishing_term_feature_extractor.h" | 5 #include "chrome/renderer/safe_browsing/phishing_term_feature_extractor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/location.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
18 #include "chrome/renderer/safe_browsing/features.h" | 20 #include "chrome/renderer/safe_browsing/features.h" |
19 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 21 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
20 #include "chrome/renderer/safe_browsing/murmurhash3_util.h" | 22 #include "chrome/renderer/safe_browsing/murmurhash3_util.h" |
21 #include "chrome/renderer/safe_browsing/test_utils.h" | 23 #include "chrome/renderer/safe_browsing/test_utils.h" |
22 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 105 |
104 void PartialExtractFeatures(const base::string16* page_text, | 106 void PartialExtractFeatures(const base::string16* page_text, |
105 FeatureMap* features, | 107 FeatureMap* features, |
106 std::set<uint32>* shingle_hashes) { | 108 std::set<uint32>* shingle_hashes) { |
107 extractor_->ExtractFeatures( | 109 extractor_->ExtractFeatures( |
108 page_text, | 110 page_text, |
109 features, | 111 features, |
110 shingle_hashes, | 112 shingle_hashes, |
111 base::Bind(&PhishingTermFeatureExtractorTest::ExtractionDone, | 113 base::Bind(&PhishingTermFeatureExtractorTest::ExtractionDone, |
112 base::Unretained(this))); | 114 base::Unretained(this))); |
113 msg_loop_.PostTask( | 115 msg_loop_.task_runner()->PostTask( |
114 FROM_HERE, | 116 FROM_HERE, base::Bind(&PhishingTermFeatureExtractorTest::QuitExtraction, |
115 base::Bind(&PhishingTermFeatureExtractorTest::QuitExtraction, | 117 base::Unretained(this))); |
116 base::Unretained(this))); | |
117 msg_loop_.RunUntilIdle(); | 118 msg_loop_.RunUntilIdle(); |
118 } | 119 } |
119 | 120 |
120 // Completion callback for feature extraction. | 121 // Completion callback for feature extraction. |
121 void ExtractionDone(bool success) { | 122 void ExtractionDone(bool success) { |
122 success_ = success; | 123 success_ = success; |
123 msg_loop_.Quit(); | 124 msg_loop_.Quit(); |
124 } | 125 } |
125 | 126 |
126 void QuitExtraction() { | 127 void QuitExtraction() { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // Now extract normally and make sure nothing breaks. | 456 // Now extract normally and make sure nothing breaks. |
456 EXPECT_TRUE(ExtractFeatures(page_text.get(), &features, &shingle_hashes)); | 457 EXPECT_TRUE(ExtractFeatures(page_text.get(), &features, &shingle_hashes)); |
457 | 458 |
458 FeatureMap expected_features; | 459 FeatureMap expected_features; |
459 expected_features.AddBooleanFeature(features::kPageTerm + | 460 expected_features.AddBooleanFeature(features::kPageTerm + |
460 std::string("multi word test")); | 461 std::string("multi word test")); |
461 ExpectFeatureMapsAreEqual(features, expected_features); | 462 ExpectFeatureMapsAreEqual(features, expected_features); |
462 } | 463 } |
463 | 464 |
464 } // namespace safe_browsing | 465 } // namespace safe_browsing |
OLD | NEW |