| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 190 |
| 191 void PageCaptured(base::string16* page_text, bool preliminary_capture) { | 191 void PageCaptured(base::string16* page_text, bool preliminary_capture) { |
| 192 PostTaskToInProcessRendererAndWait( | 192 PostTaskToInProcessRendererAndWait( |
| 193 base::Bind(&PhishingClassifierDelegate::PageCaptured, | 193 base::Bind(&PhishingClassifierDelegate::PageCaptured, |
| 194 base::Unretained(delegate_), page_text, | 194 base::Unretained(delegate_), page_text, |
| 195 preliminary_capture)); | 195 preliminary_capture)); |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool StartTestServer() { | 198 bool StartTestServer() { |
| 199 CHECK(!embedded_test_server_); | 199 CHECK(!embedded_test_server_); |
| 200 embedded_test_server_.reset(new net::test_server::EmbeddedTestServer()); | 200 embedded_test_server_.reset(new net::EmbeddedTestServer()); |
| 201 embedded_test_server_->RegisterRequestHandler( | 201 embedded_test_server_->RegisterRequestHandler( |
| 202 base::Bind(&PhishingClassifierDelegateTest::HandleRequest, | 202 base::Bind(&PhishingClassifierDelegateTest::HandleRequest, |
| 203 base::Unretained(this))); | 203 base::Unretained(this))); |
| 204 return embedded_test_server_->InitializeAndWaitUntilReady(); | 204 return embedded_test_server_->Start(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 scoped_ptr<net::test_server::HttpResponse> HandleRequest( | 207 scoped_ptr<net::test_server::HttpResponse> HandleRequest( |
| 208 const net::test_server::HttpRequest& request) { | 208 const net::test_server::HttpRequest& request) { |
| 209 std::map<std::string, std::string>::const_iterator host_it = | 209 std::map<std::string, std::string>::const_iterator host_it = |
| 210 request.headers.find("Host"); | 210 request.headers.find("Host"); |
| 211 if (host_it == request.headers.end()) | 211 if (host_it == request.headers.end()) |
| 212 return scoped_ptr<net::test_server::HttpResponse>(); | 212 return scoped_ptr<net::test_server::HttpResponse>(); |
| 213 | 213 |
| 214 std::string url = | 214 std::string url = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 | 250 |
| 251 void GoForward() { | 251 void GoForward() { |
| 252 GetWebContents()->GetController().GoForward(); | 252 GetWebContents()->GetController().GoForward(); |
| 253 content::WaitForLoadStop(GetWebContents()); | 253 content::WaitForLoadStop(GetWebContents()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 scoped_refptr<InterceptingMessageFilter> intercepting_filter_; | 256 scoped_refptr<InterceptingMessageFilter> intercepting_filter_; |
| 257 GURL response_url_; | 257 GURL response_url_; |
| 258 std::string response_content_; | 258 std::string response_content_; |
| 259 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; | 259 scoped_ptr<net::EmbeddedTestServer> embedded_test_server_; |
| 260 scoped_ptr<ClientPhishingRequest> verdict_; | 260 scoped_ptr<ClientPhishingRequest> verdict_; |
| 261 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. | 261 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. |
| 262 int32_t render_view_routing_id_; | 262 int32_t render_view_routing_id_; |
| 263 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. | 263 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. |
| 264 scoped_refptr<content::MessageLoopRunner> runner_; | 264 scoped_refptr<content::MessageLoopRunner> runner_; |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { | 267 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { |
| 268 MockScorer scorer; | 268 MockScorer scorer; |
| 269 delegate_->SetPhishingScorer(&scorer); | 269 delegate_->SetPhishingScorer(&scorer); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 RunClassificationDone(verdict); | 643 RunClassificationDone(verdict); |
| 644 ASSERT_TRUE(intercepting_filter_->verdict()); | 644 ASSERT_TRUE(intercepting_filter_->verdict()); |
| 645 EXPECT_EQ(verdict.SerializeAsString(), | 645 EXPECT_EQ(verdict.SerializeAsString(), |
| 646 intercepting_filter_->verdict()->SerializeAsString()); | 646 intercepting_filter_->verdict()->SerializeAsString()); |
| 647 | 647 |
| 648 // The delegate will cancel pending classification on destruction. | 648 // The delegate will cancel pending classification on destruction. |
| 649 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 649 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 650 } | 650 } |
| 651 | 651 |
| 652 } // namespace safe_browsing | 652 } // namespace safe_browsing |
| OLD | NEW |