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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 using ::testing::_; | 42 using ::testing::_; |
43 using ::testing::InSequence; | 43 using ::testing::InSequence; |
44 using ::testing::Mock; | 44 using ::testing::Mock; |
45 using ::testing::Pointee; | 45 using ::testing::Pointee; |
46 using ::testing::StrictMock; | 46 using ::testing::StrictMock; |
47 | 47 |
48 namespace safe_browsing { | 48 namespace safe_browsing { |
49 | 49 |
50 namespace { | 50 namespace { |
51 | |
52 // The RenderFrame is routing ID 1, and the RenderView is 2. | |
53 const int kRenderViewRoutingId = 2; | |
54 | |
55 class MockPhishingClassifier : public PhishingClassifier { | 51 class MockPhishingClassifier : public PhishingClassifier { |
56 public: | 52 public: |
57 explicit MockPhishingClassifier(content::RenderView* render_view) | 53 explicit MockPhishingClassifier(content::RenderView* render_view) |
58 : PhishingClassifier(render_view, NULL /* clock */) {} | 54 : PhishingClassifier(render_view, NULL /* clock */) {} |
59 | 55 |
60 virtual ~MockPhishingClassifier() {} | 56 virtual ~MockPhishingClassifier() {} |
61 | 57 |
62 MOCK_METHOD2(BeginClassification, | 58 MOCK_METHOD2(BeginClassification, |
63 void(const base::string16*, const DoneCallback&)); | 59 void(const base::string16*, const DoneCallback&)); |
64 MOCK_METHOD0(CancelPendingClassification, void()); | 60 MOCK_METHOD0(CancelPendingClassification, void()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 139 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
144 command_line->AppendSwitch(switches::kSingleProcess); | 140 command_line->AppendSwitch(switches::kSingleProcess); |
145 #if defined(OS_WIN) && defined(USE_AURA) | 141 #if defined(OS_WIN) && defined(USE_AURA) |
146 // Don't want to try to create a GPU process. | 142 // Don't want to try to create a GPU process. |
147 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | 143 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); |
148 #endif | 144 #endif |
149 } | 145 } |
150 | 146 |
151 virtual void SetUpOnMainThread() OVERRIDE { | 147 virtual void SetUpOnMainThread() OVERRIDE { |
152 intercepting_filter_ = new InterceptingMessageFilter(); | 148 intercepting_filter_ = new InterceptingMessageFilter(); |
153 content::RenderView* render_view = | 149 content::RenderView* render_view = content::RenderView::FromRoutingID(1); |
154 content::RenderView::FromRoutingID(kRenderViewRoutingId); | |
155 | 150 |
156 GetWebContents()->GetRenderProcessHost()->AddFilter( | 151 GetWebContents()->GetRenderProcessHost()->AddFilter( |
157 intercepting_filter_.get()); | 152 intercepting_filter_.get()); |
158 classifier_ = new StrictMock<MockPhishingClassifier>(render_view); | 153 classifier_ = new StrictMock<MockPhishingClassifier>(render_view); |
159 delegate_ = PhishingClassifierDelegate::Create(render_view, classifier_); | 154 delegate_ = PhishingClassifierDelegate::Create(render_view, classifier_); |
160 | 155 |
161 ASSERT_TRUE(StartTestServer()); | 156 ASSERT_TRUE(StartTestServer()); |
162 host_resolver()->AddRule("*", "127.0.0.1"); | 157 host_resolver()->AddRule("*", "127.0.0.1"); |
163 } | 158 } |
164 | 159 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 return response_url_; | 226 return response_url_; |
232 } | 227 } |
233 | 228 |
234 void NavigateMainFrame(const GURL& url) { | 229 void NavigateMainFrame(const GURL& url) { |
235 PostTaskToInProcessRendererAndWait( | 230 PostTaskToInProcessRendererAndWait( |
236 base::Bind(&PhishingClassifierDelegateTest::NavigateMainFrameInternal, | 231 base::Bind(&PhishingClassifierDelegateTest::NavigateMainFrameInternal, |
237 base::Unretained(this), url)); | 232 base::Unretained(this), url)); |
238 } | 233 } |
239 | 234 |
240 void NavigateMainFrameInternal(const GURL& url) { | 235 void NavigateMainFrameInternal(const GURL& url) { |
241 content::RenderView* render_view = | 236 content::RenderView* render_view = content::RenderView::FromRoutingID(1); |
242 content::RenderView::FromRoutingID(kRenderViewRoutingId); | |
243 render_view->GetWebView()->mainFrame()->firstChild()->loadRequest( | 237 render_view->GetWebView()->mainFrame()->firstChild()->loadRequest( |
244 blink::WebURLRequest(url)); | 238 blink::WebURLRequest(url)); |
245 } | 239 } |
246 | 240 |
247 void GoBack() { | 241 void GoBack() { |
248 GetWebContents()->GetController().GoBack(); | 242 GetWebContents()->GetController().GoBack(); |
249 content::WaitForLoadStop(GetWebContents()); | 243 content::WaitForLoadStop(GetWebContents()); |
250 } | 244 } |
251 | 245 |
252 void GoForward() { | 246 void GoForward() { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 RunClassificationDone(verdict); | 618 RunClassificationDone(verdict); |
625 ASSERT_TRUE(intercepting_filter_->verdict()); | 619 ASSERT_TRUE(intercepting_filter_->verdict()); |
626 EXPECT_EQ(verdict.SerializeAsString(), | 620 EXPECT_EQ(verdict.SerializeAsString(), |
627 intercepting_filter_->verdict()->SerializeAsString()); | 621 intercepting_filter_->verdict()->SerializeAsString()); |
628 | 622 |
629 // The delegate will cancel pending classification on destruction. | 623 // The delegate will cancel pending classification on destruction. |
630 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 624 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
631 } | 625 } |
632 | 626 |
633 } // namespace safe_browsing | 627 } // namespace safe_browsing |
OLD | NEW |