Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/renderer/safe_browsing/phishing_term_feature_extractor_unittest.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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/callback.h" 9 #include "base/callback.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/sha2.h"
14 #include "base/string16.h" 13 #include "base/string16.h"
15 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
16 #include "base/time.h" 15 #include "base/time.h"
17 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "crypto/sha2.h"
18 #include "chrome/renderer/safe_browsing/features.h" 18 #include "chrome/renderer/safe_browsing/features.h"
19 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" 19 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 using ::testing::ContainerEq; 23 using ::testing::ContainerEq;
24 using ::testing::Return; 24 using ::testing::Return;
25 25
26 namespace safe_browsing { 26 namespace safe_browsing {
27 27
28 class PhishingTermFeatureExtractorTest : public ::testing::Test { 28 class PhishingTermFeatureExtractorTest : public ::testing::Test {
29 protected: 29 protected:
30 virtual void SetUp() { 30 virtual void SetUp() {
31 base::hash_set<std::string> terms; 31 base::hash_set<std::string> terms;
32 terms.insert("one"); 32 terms.insert("one");
33 terms.insert("one one"); 33 terms.insert("one one");
34 terms.insert("two"); 34 terms.insert("two");
35 terms.insert("multi word test"); 35 terms.insert("multi word test");
36 terms.insert("capitalization"); 36 terms.insert("capitalization");
37 terms.insert("space"); 37 terms.insert("space");
38 terms.insert("separator"); 38 terms.insert("separator");
39 terms.insert("punctuation"); 39 terms.insert("punctuation");
40 // Chinese (translation of "hello") 40 // Chinese (translation of "hello")
41 terms.insert("\xe4\xbd\xa0\xe5\xa5\xbd"); 41 terms.insert("\xe4\xbd\xa0\xe5\xa5\xbd");
42 // Chinese (translation of "goodbye") 42 // Chinese (translation of "goodbye")
43 terms.insert("\xe5\x86\x8d\xe8\xa7\x81"); 43 terms.insert("\xe5\x86\x8d\xe8\xa7\x81");
44 44
45 for (base::hash_set<std::string>::iterator it = terms.begin(); 45 for (base::hash_set<std::string>::iterator it = terms.begin();
46 it != terms.end(); ++it) { 46 it != terms.end(); ++it) {
47 term_hashes_.insert(base::SHA256HashString(*it)); 47 term_hashes_.insert(crypto::SHA256HashString(*it));
48 } 48 }
49 49
50 base::hash_set<std::string> words; 50 base::hash_set<std::string> words;
51 words.insert("one"); 51 words.insert("one");
52 words.insert("two"); 52 words.insert("two");
53 words.insert("multi"); 53 words.insert("multi");
54 words.insert("word"); 54 words.insert("word");
55 words.insert("test"); 55 words.insert("test");
56 words.insert("capitalization"); 56 words.insert("capitalization");
57 words.insert("space"); 57 words.insert("space");
58 words.insert("separator"); 58 words.insert("separator");
59 words.insert("punctuation"); 59 words.insert("punctuation");
60 words.insert("\xe4\xbd\xa0\xe5\xa5\xbd"); 60 words.insert("\xe4\xbd\xa0\xe5\xa5\xbd");
61 words.insert("\xe5\x86\x8d\xe8\xa7\x81"); 61 words.insert("\xe5\x86\x8d\xe8\xa7\x81");
62 62
63 for (base::hash_set<std::string>::iterator it = words.begin(); 63 for (base::hash_set<std::string>::iterator it = words.begin();
64 it != words.end(); ++it) { 64 it != words.end(); ++it) {
65 word_hashes_.insert(base::SHA256HashString(*it)); 65 word_hashes_.insert(crypto::SHA256HashString(*it));
66 } 66 }
67 67
68 extractor_.reset(new PhishingTermFeatureExtractor( 68 extractor_.reset(new PhishingTermFeatureExtractor(
69 &term_hashes_, 69 &term_hashes_,
70 &word_hashes_, 70 &word_hashes_,
71 3 /* max_words_per_term */, 71 3 /* max_words_per_term */,
72 &clock_)); 72 &clock_));
73 } 73 }
74 74
75 // Runs the TermFeatureExtractor on |page_text|, waiting for the 75 // Runs the TermFeatureExtractor on |page_text|, waiting for the
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // Time check after the next 10 words. This is over the limit. 236 // Time check after the next 10 words. This is over the limit.
237 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(600))) 237 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(600)))
238 // A final time check for the histograms. 238 // A final time check for the histograms.
239 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(620))); 239 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(620)));
240 240
241 features.Clear(); 241 features.Clear();
242 EXPECT_FALSE(ExtractFeatures(&page_text, &features)); 242 EXPECT_FALSE(ExtractFeatures(&page_text, &features));
243 } 243 }
244 244
245 } // namespace safe_browsing 245 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/renderer/safe_browsing/phishing_term_feature_extractor.cc ('k') | chrome/service/service_process_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698