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 10 matching lines...) Expand all Loading... |
21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/renderer/render_view.h" | 23 #include "content/public/renderer/render_view.h" |
24 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
25 #include "net/dns/mock_host_resolver.h" | 25 #include "net/dns/mock_host_resolver.h" |
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 #if defined(OS_MACOSX) | |
32 #include "base/mac/mac_util.h" | |
33 #endif | |
34 | |
35 using ::testing::AllOf; | 31 using ::testing::AllOf; |
36 using ::testing::Contains; | 32 using ::testing::Contains; |
37 using ::testing::Not; | 33 using ::testing::Not; |
38 using ::testing::Pair; | 34 using ::testing::Pair; |
39 | 35 |
40 namespace safe_browsing { | 36 namespace safe_browsing { |
41 | 37 |
42 class PhishingClassifierTest : public InProcessBrowserTest { | 38 class PhishingClassifierTest : public InProcessBrowserTest { |
43 protected: | 39 protected: |
44 PhishingClassifierTest() | 40 PhishingClassifierTest() |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 EXPECT_EQ(0U, features.features().size()); | 261 EXPECT_EQ(0U, features.features().size()); |
266 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); | 262 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); |
267 | 263 |
268 // Extraction should fail for this case because the URL is a POST request. | 264 // Extraction should fail for this case because the URL is a POST request. |
269 LoadHtmlPost("host.net", "<html><body>content</body></html>"); | 265 LoadHtmlPost("host.net", "<html><body>content</body></html>"); |
270 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); | 266 EXPECT_FALSE(RunPhishingClassifier(&page_text, &phishy_score, &features)); |
271 EXPECT_EQ(0U, features.features().size()); | 267 EXPECT_EQ(0U, features.features().size()); |
272 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); | 268 EXPECT_EQ(PhishingClassifier::kInvalidScore, phishy_score); |
273 } | 269 } |
274 | 270 |
275 IN_PROC_BROWSER_TEST_F(PhishingClassifierTest, DisableDetection) { | 271 // This test flakes on Mac with force compositing mode for an unknown reason. |
| 272 // http://crbug.com/316709 |
276 #if defined(OS_MACOSX) | 273 #if defined(OS_MACOSX) |
277 if (base::mac::IsOSMountainLionOrLater()) { | 274 #define MAYBE_DisableDetection DISABLED_DisableDetection |
278 // This test flakes on 10.8 only for an unknown reason. | 275 #else |
279 // http://crbug.com/316709 | 276 #define MAYBE_DisableDetection DisableDetection |
280 return; | |
281 } | |
282 #endif | 277 #endif |
283 | 278 IN_PROC_BROWSER_TEST_F(PhishingClassifierTest, MAYBE_DisableDetection) { |
284 // No scorer yet, so the classifier is not ready. | 279 // No scorer yet, so the classifier is not ready. |
285 EXPECT_FALSE(classifier_->is_ready()); | 280 EXPECT_FALSE(classifier_->is_ready()); |
286 | 281 |
287 // Now set the scorer. | 282 // Now set the scorer. |
288 classifier_->set_phishing_scorer(scorer_.get()); | 283 classifier_->set_phishing_scorer(scorer_.get()); |
289 EXPECT_TRUE(classifier_->is_ready()); | 284 EXPECT_TRUE(classifier_->is_ready()); |
290 | 285 |
291 // Set a NULL scorer, which turns detection back off. | 286 // Set a NULL scorer, which turns detection back off. |
292 classifier_->set_phishing_scorer(NULL); | 287 classifier_->set_phishing_scorer(NULL); |
293 EXPECT_FALSE(classifier_->is_ready()); | 288 EXPECT_FALSE(classifier_->is_ready()); |
294 } | 289 } |
295 | 290 |
296 } // namespace safe_browsing | 291 } // namespace safe_browsing |
OLD | NEW |