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_classifier.h" | 5 #include "chrome/renderer/safe_browsing/phishing_classifier.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
27 #include "net/test/embedded_test_server/http_response.h" | 27 #include "net/test/embedded_test_server/http_response.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
30 | 30 |
31 using ::testing::AllOf; | 31 using ::testing::AllOf; |
32 using ::testing::Contains; | 32 using ::testing::Contains; |
33 using ::testing::Not; | 33 using ::testing::Not; |
34 using ::testing::Pair; | 34 using ::testing::Pair; |
35 | 35 |
36 namespace { | |
37 | |
38 // The first RenderFrame is routing ID 1, and the first RenderView is 2. | |
39 const int kRenderViewRoutingId = 2; | |
40 | |
41 } | |
42 | |
43 namespace safe_browsing { | 36 namespace safe_browsing { |
44 | 37 |
45 class PhishingClassifierTest : public InProcessBrowserTest { | 38 class PhishingClassifierTest : public InProcessBrowserTest { |
46 protected: | 39 protected: |
47 PhishingClassifierTest() | 40 PhishingClassifierTest() |
48 : url_tld_token_net_(features::kUrlTldToken + std::string("net")), | 41 : url_tld_token_net_(features::kUrlTldToken + std::string("net")), |
49 page_link_domain_phishing_(features::kPageLinkDomain + | 42 page_link_domain_phishing_(features::kPageLinkDomain + |
50 std::string("phishing.com")), | 43 std::string("phishing.com")), |
51 page_term_login_(features::kPageTerm + std::string("login")) { | 44 page_term_login_(features::kPageTerm + std::string("login")) { |
52 } | 45 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 model.add_page_term(3); | 85 model.add_page_term(3); |
93 model.set_murmur_hash_seed(2777808611U); | 86 model.set_murmur_hash_seed(2777808611U); |
94 model.add_page_word(MurmurHash3String("login", model.murmur_hash_seed())); | 87 model.add_page_word(MurmurHash3String("login", model.murmur_hash_seed())); |
95 model.set_max_words_per_term(1); | 88 model.set_max_words_per_term(1); |
96 | 89 |
97 clock_ = new MockFeatureExtractorClock; | 90 clock_ = new MockFeatureExtractorClock; |
98 scorer_.reset(Scorer::Create(model.SerializeAsString())); | 91 scorer_.reset(Scorer::Create(model.SerializeAsString())); |
99 ASSERT_TRUE(scorer_.get()); | 92 ASSERT_TRUE(scorer_.get()); |
100 | 93 |
101 classifier_.reset(new PhishingClassifier( | 94 classifier_.reset(new PhishingClassifier( |
102 content::RenderView::FromRoutingID(kRenderViewRoutingId), | 95 content::RenderView::FromRoutingID(1), |
103 clock_)); | 96 clock_)); |
104 } | 97 } |
105 | 98 |
106 virtual void TearDownOnMainThread() OVERRIDE { | 99 virtual void TearDownOnMainThread() OVERRIDE { |
107 content::RunAllPendingInMessageLoop(); | 100 content::RunAllPendingInMessageLoop(); |
108 } | 101 } |
109 | 102 |
110 // Helper method to start phishing classification and wait for it to | 103 // Helper method to start phishing classification and wait for it to |
111 // complete. Returns the true if the page is classified as phishy and | 104 // complete. Returns the true if the page is classified as phishy and |
112 // false otherwise. | 105 // false otherwise. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // Now set the scorer. | 281 // Now set the scorer. |
289 classifier_->set_phishing_scorer(scorer_.get()); | 282 classifier_->set_phishing_scorer(scorer_.get()); |
290 EXPECT_TRUE(classifier_->is_ready()); | 283 EXPECT_TRUE(classifier_->is_ready()); |
291 | 284 |
292 // Set a NULL scorer, which turns detection back off. | 285 // Set a NULL scorer, which turns detection back off. |
293 classifier_->set_phishing_scorer(NULL); | 286 classifier_->set_phishing_scorer(NULL); |
294 EXPECT_FALSE(classifier_->is_ready()); | 287 EXPECT_FALSE(classifier_->is_ready()); |
295 } | 288 } |
296 | 289 |
297 } // namespace safe_browsing | 290 } // namespace safe_browsing |
OLD | NEW |