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