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) { |
| 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 ASSERT_FALSE(csd_host_->DidShowSBInterstitial()); |
| 399 |
| 400 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
| 401 ASSERT_FALSE(csd_host_->DidPageReceiveSafeBrowsingMatch()); |
| 402 ASSERT_FALSE(csd_host_->DidShowSBInterstitial()); |
| 403 } |
| 404 |
382 void CheckIPUrlEqual(const std::vector<IPUrlInfo>& expect, | 405 void CheckIPUrlEqual(const std::vector<IPUrlInfo>& expect, |
383 const std::vector<IPUrlInfo>& result) { | 406 const std::vector<IPUrlInfo>& result) { |
384 ASSERT_EQ(expect.size(), result.size()); | 407 ASSERT_EQ(expect.size(), result.size()); |
385 | 408 |
386 for (unsigned int i = 0; i < expect.size(); ++i) { | 409 for (unsigned int i = 0; i < expect.size(); ++i) { |
387 EXPECT_EQ(expect[i].url, result[i].url); | 410 EXPECT_EQ(expect[i].url, result[i].url); |
388 EXPECT_EQ(expect[i].method, result[i].method); | 411 EXPECT_EQ(expect[i].method, result[i].method); |
389 EXPECT_EQ(expect[i].referrer, result[i].referrer); | 412 EXPECT_EQ(expect[i].referrer, result[i].referrer); |
390 EXPECT_EQ(expect[i].resource_type, result[i].resource_type); | 413 EXPECT_EQ(expect[i].resource_type, result[i].resource_type); |
391 } | 414 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 EXPECT_CALL(*csd_service_, | 747 EXPECT_CALL(*csd_service_, |
725 SendClientReportPhishingRequest( | 748 SendClientReportPhishingRequest( |
726 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 749 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
727 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 750 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
728 std::vector<GURL> redirect_chain; | 751 std::vector<GURL> redirect_chain; |
729 redirect_chain.push_back(url); | 752 redirect_chain.push_back(url); |
730 SetRedirectChain(redirect_chain); | 753 SetRedirectChain(redirect_chain); |
731 OnPhishingDetectionDone(verdict.SerializeAsString()); | 754 OnPhishingDetectionDone(verdict.SerializeAsString()); |
732 base::MessageLoop::current()->Run(); | 755 base::MessageLoop::current()->Run(); |
733 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 756 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 757 |
| 758 ExpectPreClassificationChecks(start_url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 759 &kFalse, &kFalse); |
| 760 NavigateWithoutSBHitAndCommit(start_url); |
| 761 WaitAndCheckPreClassificationChecks(); |
734 } | 762 } |
735 | 763 |
736 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { | 764 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
737 BrowseInfo* browse_info = GetBrowseInfo(); | 765 BrowseInfo* browse_info = GetBrowseInfo(); |
738 | 766 |
739 // Empty IP or host are skipped | 767 // Empty IP or host are skipped |
740 UpdateIPUrlMap("250.10.10.10", std::string()); | 768 UpdateIPUrlMap("250.10.10.10", std::string()); |
741 ASSERT_EQ(0U, browse_info->ips.size()); | 769 ASSERT_EQ(0U, browse_info->ips.size()); |
742 UpdateIPUrlMap(std::string(), "http://google.com/a"); | 770 UpdateIPUrlMap(std::string(), "http://google.com/a"); |
743 ASSERT_EQ(0U, browse_info->ips.size()); | 771 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())); | 1164 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
1137 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 1165 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
1138 EXPECT_EQ(url, resource.url); | 1166 EXPECT_EQ(url, resource.url); |
1139 EXPECT_EQ(url, resource.original_url); | 1167 EXPECT_EQ(url, resource.original_url); |
1140 resource.callback.Reset(); | 1168 resource.callback.Reset(); |
1141 msg = process()->sink().GetFirstMessageMatching( | 1169 msg = process()->sink().GetFirstMessageMatching( |
1142 SafeBrowsingMsg_StartPhishingDetection::ID); | 1170 SafeBrowsingMsg_StartPhishingDetection::ID); |
1143 ASSERT_FALSE(msg); | 1171 ASSERT_FALSE(msg); |
1144 } | 1172 } |
1145 } // namespace safe_browsing | 1173 } // namespace safe_browsing |
OLD | NEW |