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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
11 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 11 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.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/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "content/browser/renderer_host/test_render_view_host.h" | 19 #include "content/browser/renderer_host/mock_render_process_host.h" |
20 #include "content/browser/tab_contents/test_tab_contents.h" | 20 #include "content/browser/tab_contents/test_tab_contents.h" |
21 #include "content/test/test_browser_thread.h" | 21 #include "content/test/test_browser_thread.h" |
| 22 #include "content/test/test_renderer_host.h" |
22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
23 #include "ipc/ipc_test_sink.h" | 24 #include "ipc/ipc_test_sink.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 using ::testing::_; | 28 using ::testing::_; |
28 using ::testing::DeleteArg; | 29 using ::testing::DeleteArg; |
29 using ::testing::DoAll; | 30 using ::testing::DoAll; |
30 using ::testing::Eq; | 31 using ::testing::Eq; |
31 using ::testing::IsNull; | 32 using ::testing::IsNull; |
32 using ::testing::Mock; | 33 using ::testing::Mock; |
33 using ::testing::NiceMock; | 34 using ::testing::NiceMock; |
34 using ::testing::NotNull; | 35 using ::testing::NotNull; |
35 using ::testing::Pointee; | 36 using ::testing::Pointee; |
36 using ::testing::Return; | 37 using ::testing::Return; |
37 using ::testing::SaveArg; | 38 using ::testing::SaveArg; |
38 using ::testing::SetArgumentPointee; | 39 using ::testing::SetArgumentPointee; |
39 using ::testing::StrictMock; | 40 using ::testing::StrictMock; |
40 using content::BrowserThread; | 41 using content::BrowserThread; |
| 42 using content::RenderViewHostTester; |
41 | 43 |
42 namespace { | 44 namespace { |
43 const bool kFalse = false; | 45 const bool kFalse = false; |
44 const bool kTrue = true; | 46 const bool kTrue = true; |
45 } | 47 } |
46 | 48 |
47 namespace safe_browsing { | 49 namespace safe_browsing { |
48 namespace { | 50 namespace { |
49 // This matcher verifies that the client computed verdict | 51 // This matcher verifies that the client computed verdict |
50 // (ClientPhishingRequest) which is passed to SendClientReportPhishingRequest | 52 // (ClientPhishingRequest) which is passed to SendClientReportPhishingRequest |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 652 |
651 msg = process()->sink().GetFirstMessageMatching( | 653 msg = process()->sink().GetFirstMessageMatching( |
652 SafeBrowsingMsg_StartPhishingDetection::ID); | 654 SafeBrowsingMsg_StartPhishingDetection::ID); |
653 ASSERT_FALSE(msg); | 655 ASSERT_FALSE(msg); |
654 | 656 |
655 // Check that XHTML is supported, in addition to the default HTML type. | 657 // Check that XHTML is supported, in addition to the default HTML type. |
656 // Note: for this test to work correctly, the new URL must be on the | 658 // Note: for this test to work correctly, the new URL must be on the |
657 // same domain as the previous URL, otherwise it will create a new | 659 // same domain as the previous URL, otherwise it will create a new |
658 // RenderViewHost that won't have the mime type set. | 660 // RenderViewHost that won't have the mime type set. |
659 url = GURL("http://host.com/xhtml"); | 661 url = GURL("http://host.com/xhtml"); |
660 rvh()->set_contents_mime_type("application/xhtml+xml"); | 662 rvh_tester()->SetContentsMimeType("application/xhtml+xml"); |
661 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 663 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
662 &kFalse, &kFalse); | 664 &kFalse, &kFalse); |
663 NavigateAndCommit(url); | 665 NavigateAndCommit(url); |
664 WaitAndCheckPreClassificationChecks(); | 666 WaitAndCheckPreClassificationChecks(); |
665 msg = process()->sink().GetFirstMessageMatching( | 667 msg = process()->sink().GetFirstMessageMatching( |
666 SafeBrowsingMsg_StartPhishingDetection::ID); | 668 SafeBrowsingMsg_StartPhishingDetection::ID); |
667 ASSERT_TRUE(msg); | 669 ASSERT_TRUE(msg); |
668 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 670 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); |
669 EXPECT_EQ(url, actual_url.a); | 671 EXPECT_EQ(url, actual_url.a); |
670 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | 672 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
(...skipping 11 matching lines...) Expand all Loading... |
682 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 684 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); |
683 EXPECT_EQ(url, actual_url.a); | 685 EXPECT_EQ(url, actual_url.a); |
684 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | 686 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
685 process()->sink().ClearMessages(); | 687 process()->sink().ClearMessages(); |
686 | 688 |
687 // If the mime type is not one that we support, no IPC should be triggered. | 689 // If the mime type is not one that we support, no IPC should be triggered. |
688 // Note: for this test to work correctly, the new URL must be on the | 690 // Note: for this test to work correctly, the new URL must be on the |
689 // same domain as the previous URL, otherwise it will create a new | 691 // same domain as the previous URL, otherwise it will create a new |
690 // RenderViewHost that won't have the mime type set. | 692 // RenderViewHost that won't have the mime type set. |
691 url = GURL("http://host2.com/image.jpg"); | 693 url = GURL("http://host2.com/image.jpg"); |
692 rvh()->set_contents_mime_type("image/jpeg"); | 694 rvh_tester()->SetContentsMimeType("image/jpeg"); |
693 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); | 695 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); |
694 NavigateAndCommit(url); | 696 NavigateAndCommit(url); |
695 WaitAndCheckPreClassificationChecks(); | 697 WaitAndCheckPreClassificationChecks(); |
696 msg = process()->sink().GetFirstMessageMatching( | 698 msg = process()->sink().GetFirstMessageMatching( |
697 SafeBrowsingMsg_StartPhishingDetection::ID); | 699 SafeBrowsingMsg_StartPhishingDetection::ID); |
698 ASSERT_FALSE(msg); | 700 ASSERT_FALSE(msg); |
699 | 701 |
700 // If IsPrivateIPAddress returns true, no IPC should be triggered. | 702 // If IsPrivateIPAddress returns true, no IPC should be triggered. |
701 url = GURL("http://host3.com/"); | 703 url = GURL("http://host3.com/"); |
702 ExpectPreClassificationChecks(url, &kTrue, NULL, NULL, NULL, NULL, NULL); | 704 ExpectPreClassificationChecks(url, &kTrue, NULL, NULL, NULL, NULL, NULL); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 775 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
774 EXPECT_EQ(url, resource.url); | 776 EXPECT_EQ(url, resource.url); |
775 EXPECT_EQ(url, resource.original_url); | 777 EXPECT_EQ(url, resource.original_url); |
776 resource.callback.Reset(); | 778 resource.callback.Reset(); |
777 msg = process()->sink().GetFirstMessageMatching( | 779 msg = process()->sink().GetFirstMessageMatching( |
778 SafeBrowsingMsg_StartPhishingDetection::ID); | 780 SafeBrowsingMsg_StartPhishingDetection::ID); |
779 ASSERT_FALSE(msg); | 781 ASSERT_FALSE(msg); |
780 } | 782 } |
781 | 783 |
782 } // namespace safe_browsing | 784 } // namespace safe_browsing |
OLD | NEW |