| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/safe_browsing/csd.pb.h" | 16 #include "chrome/common/safe_browsing/csd.pb.h" |
| 17 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 17 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 18 #include "chrome/renderer/safe_browsing/features.h" | 18 #include "chrome/renderer/safe_browsing/features.h" |
| 19 #include "chrome/renderer/safe_browsing/phishing_classifier.h" | 19 #include "chrome/renderer/safe_browsing/phishing_classifier.h" |
| 20 #include "chrome/renderer/safe_browsing/scorer.h" | 20 #include "chrome/renderer/safe_browsing/scorer.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "content/public/browser/browser_message_filter.h" | 23 #include "content/public/browser/browser_message_filter.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/public/test/routing_id_mangling_disabler.h" |
| 29 #include "content/public/test/test_navigation_observer.h" | 30 #include "content/public/test/test_navigation_observer.h" |
| 30 #include "content/public/test/test_utils.h" | 31 #include "content/public/test/test_utils.h" |
| 31 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
| 32 #include "net/test/embedded_test_server/embedded_test_server.h" | 33 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 33 #include "net/test/embedded_test_server/http_request.h" | 34 #include "net/test/embedded_test_server/http_request.h" |
| 34 #include "net/test/embedded_test_server/http_response.h" | 35 #include "net/test/embedded_test_server/http_response.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "third_party/WebKit/public/platform/WebURL.h" | 37 #include "third_party/WebKit/public/platform/WebURL.h" |
| 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 38 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 38 #include "third_party/WebKit/public/web/WebFrame.h" | 39 #include "third_party/WebKit/public/web/WebFrame.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 257 } |
| 257 | 258 |
| 258 scoped_refptr<InterceptingMessageFilter> intercepting_filter_; | 259 scoped_refptr<InterceptingMessageFilter> intercepting_filter_; |
| 259 GURL response_url_; | 260 GURL response_url_; |
| 260 std::string response_content_; | 261 std::string response_content_; |
| 261 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; | 262 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; |
| 262 scoped_ptr<ClientPhishingRequest> verdict_; | 263 scoped_ptr<ClientPhishingRequest> verdict_; |
| 263 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. | 264 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. |
| 264 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. | 265 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. |
| 265 scoped_refptr<content::MessageLoopRunner> runner_; | 266 scoped_refptr<content::MessageLoopRunner> runner_; |
| 267 content::RoutingIDManglingDisabler mangling_disabler_; |
| 266 }; | 268 }; |
| 267 | 269 |
| 268 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { | 270 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { |
| 269 MockScorer scorer; | 271 MockScorer scorer; |
| 270 delegate_->SetPhishingScorer(&scorer); | 272 delegate_->SetPhishingScorer(&scorer); |
| 271 ASSERT_TRUE(classifier_->is_ready()); | 273 ASSERT_TRUE(classifier_->is_ready()); |
| 272 | 274 |
| 273 // Test an initial load. We expect classification to happen normally. | 275 // Test an initial load. We expect classification to happen normally. |
| 274 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(2); | 276 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(2); |
| 275 std::string port = base::IntToString(embedded_test_server_->port()); | 277 std::string port = base::IntToString(embedded_test_server_->port()); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 RunClassificationDone(verdict); | 653 RunClassificationDone(verdict); |
| 652 ASSERT_TRUE(intercepting_filter_->verdict()); | 654 ASSERT_TRUE(intercepting_filter_->verdict()); |
| 653 EXPECT_EQ(verdict.SerializeAsString(), | 655 EXPECT_EQ(verdict.SerializeAsString(), |
| 654 intercepting_filter_->verdict()->SerializeAsString()); | 656 intercepting_filter_->verdict()->SerializeAsString()); |
| 655 | 657 |
| 656 // The delegate will cancel pending classification on destruction. | 658 // The delegate will cancel pending classification on destruction. |
| 657 EXPECT_CALL(*classifier_, CancelPendingClassification()); | 659 EXPECT_CALL(*classifier_, CancelPendingClassification()); |
| 658 } | 660 } |
| 659 | 661 |
| 660 } // namespace safe_browsing | 662 } // namespace safe_browsing |
| OLD | NEW |