Chromium Code Reviews| 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/files/file_path.h" | 5 #include "base/files/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/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 controller().LoadURL( | 408 controller().LoadURL( |
| 409 safe_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 409 safe_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 410 std::string()); | 410 std::string()); |
| 411 | 411 |
| 412 ASSERT_TRUE(pending_rvh()); | 412 ASSERT_TRUE(pending_rvh()); |
| 413 if (web_contents()->GetRenderViewHost()->GetProcess()->GetID() == | 413 if (web_contents()->GetRenderViewHost()->GetProcess()->GetID() == |
| 414 pending_rvh()->GetProcess()->GetID()) { | 414 pending_rvh()->GetProcess()->GetID()) { |
| 415 EXPECT_NE(web_contents()->GetRenderViewHost()->GetRoutingID(), | 415 EXPECT_NE(web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 416 pending_rvh()->GetRoutingID()); | 416 pending_rvh()->GetRoutingID()); |
| 417 } | 417 } |
| 418 ASSERT_FALSE(csd_host_->DidShowSBInterstitial()); | |
| 419 | 418 |
| 420 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 419 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 421 ASSERT_FALSE(csd_host_->DidShowSBInterstitial()); | 420 ASSERT_FALSE(csd_host_->DidShowSBInterstitial()); |
| 422 } | 421 } |
| 423 | 422 |
| 424 void CheckIPUrlEqual(const std::vector<IPUrlInfo>& expect, | 423 void CheckIPUrlEqual(const std::vector<IPUrlInfo>& expect, |
| 425 const std::vector<IPUrlInfo>& result) { | 424 const std::vector<IPUrlInfo>& result) { |
| 426 ASSERT_EQ(expect.size(), result.size()); | 425 ASSERT_EQ(expect.size(), result.size()); |
| 427 | 426 |
| 428 for (unsigned int i = 0; i < expect.size(); ++i) { | 427 for (unsigned int i = 0; i < expect.size(); ++i) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 OnPhishingDetectionDone(verdict.SerializeAsString()); | 740 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 742 base::MessageLoop::current()->Run(); | 741 base::MessageLoop::current()->Run(); |
| 743 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 742 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 744 | 743 |
| 745 ExpectPreClassificationChecks(start_url, &kFalse, &kFalse, &kFalse, &kFalse, | 744 ExpectPreClassificationChecks(start_url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 746 &kFalse, &kFalse, &kFalse, &kFalse); | 745 &kFalse, &kFalse, &kFalse, &kFalse); |
| 747 NavigateWithoutSBHitAndCommit(start_url); | 746 NavigateWithoutSBHitAndCommit(start_url); |
| 748 WaitAndCheckPreClassificationChecks(); | 747 WaitAndCheckPreClassificationChecks(); |
| 749 } | 748 } |
| 750 | 749 |
| 750 TEST_F( | |
| 751 ClientSideDetectionHostTest, | |
| 752 OnPhishingDetectionDoneVerdictNotPhishingButSBMatchOnSubresourceWhileNavPend ing) { | |
|
Charlie Reis
2015/12/11 05:39:24
That's a mouthful! Would a shorter name be worthw
mattm
2015/12/15 01:42:25
It's following the same convention as other tests
| |
| 753 // When a malware hit happens on a committed page while a slow pending load is | |
| 754 // in progress, the csd report should be sent for the committed page. | |
| 755 | |
| 756 // Do an initial navigation to a safe host. | |
| 757 GURL start_url("http://safe.example.com/"); | |
| 758 ExpectPreClassificationChecks( | |
| 759 start_url, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, | |
| 760 &kFalse); | |
| 761 NavigateAndCommit(start_url); | |
| 762 WaitAndCheckPreClassificationChecks(); | |
| 763 | |
| 764 // Now navigate to a different host which does not have a SB hit. | |
| 765 GURL url("http://not-malware-not-phishing-but-malware-subresource.com/"); | |
| 766 ClientPhishingRequest verdict; | |
| 767 verdict.set_url(url.spec()); | |
| 768 verdict.set_client_score(0.1f); | |
| 769 verdict.set_is_phishing(false); | |
| 770 | |
| 771 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
| 772 &kFalse, &kFalse, &kFalse, &kFalse); | |
| 773 NavigateWithoutSBHitAndCommit(url); | |
| 774 | |
| 775 // Simulate a subresource malware hit on committed page. | |
| 776 SetUnsafeSubResourceForCurrent(); | |
| 777 | |
| 778 // Create a pending navigation, but don't commit it. | |
| 779 GURL pending_url("http://slow.example.com/"); | |
| 780 content::WebContentsTester::For(web_contents())->StartNavigation(pending_url); | |
| 781 | |
| 782 WaitAndCheckPreClassificationChecks(); | |
| 783 | |
| 784 // Even though we have a pending navigation, the DidShowSBInterstitial check | |
| 785 // should apply to the committed navigation, so we should get a report even | |
| 786 // though the verdict has is_phishing = false. | |
| 787 EXPECT_CALL(*csd_service_, | |
| 788 SendClientReportPhishingRequest( | |
| 789 Pointee(PartiallyEqualVerdict(verdict)), _, CallbackIsNull())) | |
| 790 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | |
| 791 std::vector<GURL> redirect_chain; | |
| 792 redirect_chain.push_back(url); | |
| 793 SetRedirectChain(redirect_chain); | |
| 794 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
| 795 base::MessageLoop::current()->Run(); | |
| 796 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | |
| 797 } | |
| 798 | |
| 751 TEST_F(ClientSideDetectionHostTest, | 799 TEST_F(ClientSideDetectionHostTest, |
| 752 DidStopLoadingShowMalwareInterstitial) { | 800 DidStopLoadingShowMalwareInterstitial) { |
| 753 // Case 9: client thinks the page match malware IP and so does the server. | 801 // Case 9: client thinks the page match malware IP and so does the server. |
| 754 // We show an sub-resource malware interstitial. | 802 // We show an sub-resource malware interstitial. |
| 755 MockBrowserFeatureExtractor* mock_extractor = | 803 MockBrowserFeatureExtractor* mock_extractor = |
| 756 new StrictMock<MockBrowserFeatureExtractor>( | 804 new StrictMock<MockBrowserFeatureExtractor>( |
| 757 web_contents(), | 805 web_contents(), |
| 758 csd_host_.get()); | 806 csd_host_.get()); |
| 759 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 807 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 760 | 808 |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 EXPECT_EQ(url, resource.url); | 1177 EXPECT_EQ(url, resource.url); |
| 1130 EXPECT_EQ(url, resource.original_url); | 1178 EXPECT_EQ(url, resource.original_url); |
| 1131 | 1179 |
| 1132 ExpectStartPhishingDetection(NULL); | 1180 ExpectStartPhishingDetection(NULL); |
| 1133 | 1181 |
| 1134 // Showing a phishing warning will invalidate all the weak pointers which | 1182 // Showing a phishing warning will invalidate all the weak pointers which |
| 1135 // means we will not extract malware features. | 1183 // means we will not extract malware features. |
| 1136 ExpectShouldClassifyForMalwareResult(false); | 1184 ExpectShouldClassifyForMalwareResult(false); |
| 1137 } | 1185 } |
| 1138 } // namespace safe_browsing | 1186 } // namespace safe_browsing |
| OLD | NEW |