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 30 matching lines...) Expand all Loading... | |
41 using ::testing::Pointee; | 41 using ::testing::Pointee; |
42 using ::testing::Return; | 42 using ::testing::Return; |
43 using ::testing::SaveArg; | 43 using ::testing::SaveArg; |
44 using ::testing::SetArgumentPointee; | 44 using ::testing::SetArgumentPointee; |
45 using ::testing::StrictMock; | 45 using ::testing::StrictMock; |
46 using content::BrowserThread; | 46 using content::BrowserThread; |
47 using content::RenderViewHostTester; | 47 using content::RenderViewHostTester; |
48 using content::WebContents; | 48 using content::WebContents; |
49 | 49 |
50 namespace { | 50 namespace { |
51 | |
51 const bool kFalse = false; | 52 const bool kFalse = false; |
52 const bool kTrue = true; | 53 const bool kTrue = true; |
53 } | 54 |
55 } // namespace | |
54 | 56 |
55 namespace safe_browsing { | 57 namespace safe_browsing { |
56 namespace { | 58 namespace { |
57 // This matcher verifies that the client computed verdict | 59 // This matcher verifies that the client computed verdict |
58 // (ClientPhishingRequest) which is passed to SendClientReportPhishingRequest | 60 // (ClientPhishingRequest) which is passed to SendClientReportPhishingRequest |
59 // has the expected fields set. Note: we can't simply compare the protocol | 61 // has the expected fields set. Note: we can't simply compare the protocol |
60 // buffer strings because the BrowserFeatureExtractor might add features to the | 62 // buffer strings because the BrowserFeatureExtractor might add features to the |
61 // verdict object before calling SendClientReportPhishingRequest. | 63 // verdict object before calling SendClientReportPhishingRequest. |
62 MATCHER_P(PartiallyEqualVerdict, other, "") { | 64 MATCHER_P(PartiallyEqualVerdict, other, "") { |
63 return (other.url() == arg.url() && | 65 return (other.url() == arg.url() && |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 resource.original_url = url; | 365 resource.original_url = url; |
364 resource.is_subresource = false; | 366 resource.is_subresource = false; |
365 resource.threat_type = SB_THREAT_TYPE_URL_MALWARE; | 367 resource.threat_type = SB_THREAT_TYPE_URL_MALWARE; |
366 resource.callback = base::Bind(&EmptyUrlCheckCallback); | 368 resource.callback = base::Bind(&EmptyUrlCheckCallback); |
367 resource.render_process_host_id = pending_rvh()->GetProcess()->GetID(); | 369 resource.render_process_host_id = pending_rvh()->GetProcess()->GetID(); |
368 resource.render_view_id = pending_rvh()->GetRoutingID(); | 370 resource.render_view_id = pending_rvh()->GetRoutingID(); |
369 csd_host_->OnSafeBrowsingMatch(resource); | 371 csd_host_->OnSafeBrowsingMatch(resource); |
370 csd_host_->OnSafeBrowsingHit(resource); | 372 csd_host_->OnSafeBrowsingHit(resource); |
371 resource.callback.Reset(); | 373 resource.callback.Reset(); |
372 | 374 |
375 ASSERT_TRUE(csd_host_->DidPageReceiveSafeBrowsingMatch()); | |
376 | |
373 // LoadURL created a navigation entry, now simulate the RenderView sending | 377 // LoadURL created a navigation entry, now simulate the RenderView sending |
374 // a notification that it actually navigated. | 378 // a notification that it actually navigated. |
375 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 379 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
376 | 380 |
377 ASSERT_TRUE(csd_host_->DidPageReceiveSafeBrowsingMatch()); | 381 ASSERT_TRUE(csd_host_->DidPageReceiveSafeBrowsingMatch()); |
378 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); | 382 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); |
379 TestUnsafeResourceCopied(resource); | 383 TestUnsafeResourceCopied(resource); |
380 } | 384 } |
381 | 385 |
386 void NavigateWithoutSBHitAndCommit(const GURL& safe_url) { | |
mattm
2013/12/16 22:36:11
Might as well check the DidShowSBInterstitial valu
Greg Billock
2013/12/16 23:00:22
Done.
| |
387 controller().LoadURL( | |
388 safe_url, content::Referrer(), content::PAGE_TRANSITION_LINK, | |
389 std::string()); | |
390 | |
391 ASSERT_TRUE(pending_rvh()); | |
392 if (web_contents()->GetRenderViewHost()->GetProcess()->GetID() == | |
393 pending_rvh()->GetProcess()->GetID()) { | |
394 EXPECT_NE(web_contents()->GetRenderViewHost()->GetRoutingID(), | |
395 pending_rvh()->GetRoutingID()); | |
396 } | |
397 ASSERT_FALSE(csd_host_->DidPageReceiveSafeBrowsingMatch()); | |
398 | |
399 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); | |
400 ASSERT_FALSE(csd_host_->DidPageReceiveSafeBrowsingMatch()); | |
401 } | |
402 | |
382 void CheckIPUrlEqual(const std::vector<IPUrlInfo>& expect, | 403 void CheckIPUrlEqual(const std::vector<IPUrlInfo>& expect, |
383 const std::vector<IPUrlInfo>& result) { | 404 const std::vector<IPUrlInfo>& result) { |
384 ASSERT_EQ(expect.size(), result.size()); | 405 ASSERT_EQ(expect.size(), result.size()); |
385 | 406 |
386 for (unsigned int i = 0; i < expect.size(); ++i) { | 407 for (unsigned int i = 0; i < expect.size(); ++i) { |
387 EXPECT_EQ(expect[i].url, result[i].url); | 408 EXPECT_EQ(expect[i].url, result[i].url); |
388 EXPECT_EQ(expect[i].method, result[i].method); | 409 EXPECT_EQ(expect[i].method, result[i].method); |
389 EXPECT_EQ(expect[i].referrer, result[i].referrer); | 410 EXPECT_EQ(expect[i].referrer, result[i].referrer); |
390 EXPECT_EQ(expect[i].resource_type, result[i].resource_type); | 411 EXPECT_EQ(expect[i].resource_type, result[i].resource_type); |
391 } | 412 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 EXPECT_CALL(*csd_service_, | 745 EXPECT_CALL(*csd_service_, |
725 SendClientReportPhishingRequest( | 746 SendClientReportPhishingRequest( |
726 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 747 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
727 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 748 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
728 std::vector<GURL> redirect_chain; | 749 std::vector<GURL> redirect_chain; |
729 redirect_chain.push_back(url); | 750 redirect_chain.push_back(url); |
730 SetRedirectChain(redirect_chain); | 751 SetRedirectChain(redirect_chain); |
731 OnPhishingDetectionDone(verdict.SerializeAsString()); | 752 OnPhishingDetectionDone(verdict.SerializeAsString()); |
732 base::MessageLoop::current()->Run(); | 753 base::MessageLoop::current()->Run(); |
733 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 754 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
755 | |
756 ExpectPreClassificationChecks(start_url, &kFalse, &kFalse, &kFalse, &kFalse, | |
757 &kFalse, &kFalse); | |
758 NavigateWithoutSBHitAndCommit(start_url); | |
759 WaitAndCheckPreClassificationChecks(); | |
734 } | 760 } |
735 | 761 |
736 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { | 762 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
737 BrowseInfo* browse_info = GetBrowseInfo(); | 763 BrowseInfo* browse_info = GetBrowseInfo(); |
738 | 764 |
739 // Empty IP or host are skipped | 765 // Empty IP or host are skipped |
740 UpdateIPUrlMap("250.10.10.10", std::string()); | 766 UpdateIPUrlMap("250.10.10.10", std::string()); |
741 ASSERT_EQ(0U, browse_info->ips.size()); | 767 ASSERT_EQ(0U, browse_info->ips.size()); |
742 UpdateIPUrlMap(std::string(), "http://google.com/a"); | 768 UpdateIPUrlMap(std::string(), "http://google.com/a"); |
743 ASSERT_EQ(0U, browse_info->ips.size()); | 769 ASSERT_EQ(0U, browse_info->ips.size()); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 1162 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
1137 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 1163 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
1138 EXPECT_EQ(url, resource.url); | 1164 EXPECT_EQ(url, resource.url); |
1139 EXPECT_EQ(url, resource.original_url); | 1165 EXPECT_EQ(url, resource.original_url); |
1140 resource.callback.Reset(); | 1166 resource.callback.Reset(); |
1141 msg = process()->sink().GetFirstMessageMatching( | 1167 msg = process()->sink().GetFirstMessageMatching( |
1142 SafeBrowsingMsg_StartPhishingDetection::ID); | 1168 SafeBrowsingMsg_StartPhishingDetection::ID); |
1143 ASSERT_FALSE(msg); | 1169 ASSERT_FALSE(msg); |
1144 } | 1170 } |
1145 } // namespace safe_browsing | 1171 } // namespace safe_browsing |
OLD | NEW |