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_delegate.h" | 5 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 }; | 80 }; |
81 | 81 |
82 class InterceptingMessageFilter : public content::BrowserMessageFilter { | 82 class InterceptingMessageFilter : public content::BrowserMessageFilter { |
83 public: | 83 public: |
84 InterceptingMessageFilter() | 84 InterceptingMessageFilter() |
85 : BrowserMessageFilter(SafeBrowsingMsgStart), | 85 : BrowserMessageFilter(SafeBrowsingMsgStart), |
86 waiting_message_loop_(NULL) { | 86 waiting_message_loop_(NULL) { |
87 } | 87 } |
88 | 88 |
89 const ClientPhishingRequest* verdict() const { return verdict_.get(); } | 89 const ClientPhishingRequest* verdict() const { return verdict_.get(); } |
90 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 90 virtual bool OnMessageReceived(const IPC::Message& message) override { |
91 bool handled = true; | 91 bool handled = true; |
92 IPC_BEGIN_MESSAGE_MAP(InterceptingMessageFilter, message) | 92 IPC_BEGIN_MESSAGE_MAP(InterceptingMessageFilter, message) |
93 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, | 93 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, |
94 OnPhishingDetectionDone) | 94 OnPhishingDetectionDone) |
95 IPC_MESSAGE_UNHANDLED(handled = false); | 95 IPC_MESSAGE_UNHANDLED(handled = false); |
96 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
97 return handled; | 97 return handled; |
98 } | 98 } |
99 | 99 |
100 void Reset() { | 100 void Reset() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 class PhishingClassifierDelegateTest : public InProcessBrowserTest { | 134 class PhishingClassifierDelegateTest : public InProcessBrowserTest { |
135 public: | 135 public: |
136 void CancelCalled() { | 136 void CancelCalled() { |
137 if (runner_.get()) { | 137 if (runner_.get()) { |
138 content::BrowserThread::PostTask( | 138 content::BrowserThread::PostTask( |
139 content::BrowserThread::UI, FROM_HERE, runner_->QuitClosure()); | 139 content::BrowserThread::UI, FROM_HERE, runner_->QuitClosure()); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 protected: | 143 protected: |
144 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 144 virtual void SetUpCommandLine(CommandLine* command_line) override { |
145 command_line->AppendSwitch(switches::kSingleProcess); | 145 command_line->AppendSwitch(switches::kSingleProcess); |
146 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
147 // Don't want to try to create a GPU process. | 147 // Don't want to try to create a GPU process. |
148 command_line->AppendSwitch(switches::kDisableGpu); | 148 command_line->AppendSwitch(switches::kDisableGpu); |
149 #endif | 149 #endif |
150 } | 150 } |
151 | 151 |
152 virtual void SetUpOnMainThread() OVERRIDE { | 152 virtual void SetUpOnMainThread() override { |
153 intercepting_filter_ = new InterceptingMessageFilter(); | 153 intercepting_filter_ = new InterceptingMessageFilter(); |
154 content::RenderView* render_view = | 154 content::RenderView* render_view = |
155 content::RenderView::FromRoutingID(kRenderViewRoutingId); | 155 content::RenderView::FromRoutingID(kRenderViewRoutingId); |
156 | 156 |
157 GetWebContents()->GetRenderProcessHost()->AddFilter( | 157 GetWebContents()->GetRenderProcessHost()->AddFilter( |
158 intercepting_filter_.get()); | 158 intercepting_filter_.get()); |
159 classifier_ = new StrictMock<MockPhishingClassifier>(render_view); | 159 classifier_ = new StrictMock<MockPhishingClassifier>(render_view); |
160 delegate_ = PhishingClassifierDelegate::Create(render_view, classifier_); | 160 delegate_ = PhishingClassifierDelegate::Create(render_view, classifier_); |
161 | 161 |
162 ASSERT_TRUE(StartTestServer()); | 162 ASSERT_TRUE(StartTestServer()); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 RunClassificationDone(verdict); | 631 RunClassificationDone(verdict); |
632 ASSERT_TRUE(intercepting_filter_->verdict()); | 632 ASSERT_TRUE(intercepting_filter_->verdict()); |
633 EXPECT_EQ(verdict.SerializeAsString(), | 633 EXPECT_EQ(verdict.SerializeAsString(), |
634 intercepting_filter_->verdict()->SerializeAsString()); | 634 intercepting_filter_->verdict()->SerializeAsString()); |
635 | 635 |
636 // The delegate will cancel pending classification on destruction. | 636 // The delegate will cancel pending classification on destruction. |
637 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 637 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
638 } | 638 } |
639 | 639 |
640 } // namespace safe_browsing | 640 } // namespace safe_browsing |
OLD | NEW |