OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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: this test uses RenderViewFakeResourcesTest in order to set up a | 5 // Note: this test uses RenderViewFakeResourcesTest in order to set up a |
6 // real RenderThread to hold the phishing Scorer object. | 6 // real RenderThread to hold the phishing Scorer object. |
7 | 7 |
8 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 8 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
9 | 9 |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/safebrowsing_messages.h" |
13 #include "chrome/renderer/render_view.h" | 13 #include "chrome/renderer/render_view.h" |
14 #include "chrome/renderer/safe_browsing/features.h" | 14 #include "chrome/renderer/safe_browsing/features.h" |
15 #include "chrome/renderer/safe_browsing/phishing_classifier.h" | 15 #include "chrome/renderer/safe_browsing/phishing_classifier.h" |
16 #include "chrome/renderer/safe_browsing/render_view_fake_resources_test.h" | 16 #include "chrome/renderer/safe_browsing/render_view_fake_resources_test.h" |
17 #include "chrome/renderer/safe_browsing/scorer.h" | 17 #include "chrome/renderer/safe_browsing/scorer.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 private: | 54 private: |
55 DISALLOW_COPY_AND_ASSIGN(MockScorer); | 55 DISALLOW_COPY_AND_ASSIGN(MockScorer); |
56 }; | 56 }; |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 class PhishingClassifierDelegateTest : public RenderViewFakeResourcesTest { | 59 class PhishingClassifierDelegateTest : public RenderViewFakeResourcesTest { |
60 protected: | 60 protected: |
61 bool OnMessageReceived(const IPC::Message& message) { | 61 bool OnMessageReceived(const IPC::Message& message) { |
62 bool handled = true; | 62 bool handled = true; |
63 IPC_BEGIN_MESSAGE_MAP(PhishingClassifierDelegateTest, message) | 63 IPC_BEGIN_MESSAGE_MAP(PhishingClassifierDelegateTest, message) |
64 IPC_MESSAGE_HANDLER(ViewHostMsg_DetectedPhishingSite, | 64 IPC_MESSAGE_HANDLER(SafeBrowsingDetectionHostMsg_DetectedPhishingSite, |
65 OnDetectedPhishingSite) | 65 OnDetectedPhishingSite) |
66 IPC_MESSAGE_UNHANDLED( | 66 IPC_MESSAGE_UNHANDLED( |
67 handled = RenderViewFakeResourcesTest::OnMessageReceived(message)) | 67 handled = RenderViewFakeResourcesTest::OnMessageReceived(message)) |
68 IPC_END_MESSAGE_MAP() | 68 IPC_END_MESSAGE_MAP() |
69 return handled; | 69 return handled; |
70 } | 70 } |
71 | 71 |
72 void OnDetectedPhishingSite(GURL phishing_url, double phishing_score) { | 72 void OnDetectedPhishingSite(GURL phishing_url, double phishing_score) { |
73 detected_phishing_site_ = true; | 73 detected_phishing_site_ = true; |
74 detected_url_ = phishing_url; | 74 detected_url_ = phishing_url; |
75 detected_score_ = phishing_score; | 75 detected_score_ = phishing_score; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 RunClassificationDone(delegate, true, 0.8); | 307 RunClassificationDone(delegate, true, 0.8); |
308 EXPECT_TRUE(detected_phishing_site_); | 308 EXPECT_TRUE(detected_phishing_site_); |
309 EXPECT_EQ(GURL("http://host.com/"), detected_url_); | 309 EXPECT_EQ(GURL("http://host.com/"), detected_url_); |
310 EXPECT_EQ(0.8, detected_score_); | 310 EXPECT_EQ(0.8, detected_score_); |
311 | 311 |
312 // The delegate will cancel pending classification on destruction. | 312 // The delegate will cancel pending classification on destruction. |
313 EXPECT_CALL(*classifier, CancelPendingClassification()); | 313 EXPECT_CALL(*classifier, CancelPendingClassification()); |
314 } | 314 } |
315 | 315 |
316 } // namespace safe_browsing | 316 } // namespace safe_browsing |
OLD | NEW |