| 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/browser/safe_browsing/client_side_detection_host.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 EXPECT_EQ(phishing_url, resource.url); | 560 EXPECT_EQ(phishing_url, resource.url); |
| 561 EXPECT_EQ(phishing_url, resource.original_url); | 561 EXPECT_EQ(phishing_url, resource.original_url); |
| 562 EXPECT_FALSE(resource.is_subresource); | 562 EXPECT_FALSE(resource.is_subresource); |
| 563 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); | 563 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); |
| 564 EXPECT_EQ(ThreatSource::CLIENT_SIDE_DETECTION, resource.threat_source); | 564 EXPECT_EQ(ThreatSource::CLIENT_SIDE_DETECTION, resource.threat_source); |
| 565 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run()); | 565 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run()); |
| 566 | 566 |
| 567 // Make sure the client object will be deleted. | 567 // Make sure the client object will be deleted. |
| 568 BrowserThread::PostTask( | 568 BrowserThread::PostTask( |
| 569 BrowserThread::IO, FROM_HERE, | 569 BrowserThread::IO, FROM_HERE, |
| 570 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | 570 base::BindOnce(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, |
| 571 ui_manager_, resource.callback)); | 571 ui_manager_, resource.callback)); |
| 572 } | 572 } |
| 573 | 573 |
| 574 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { | 574 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { |
| 575 // Case 4 & 5: client thinks a page is phishing then navigates to | 575 // Case 4 & 5: client thinks a page is phishing then navigates to |
| 576 // another page which is also considered phishing by the client | 576 // another page which is also considered phishing by the client |
| 577 // before the server responds with a verdict. After a while the | 577 // before the server responds with a verdict. After a while the |
| 578 // server responds for both requests with a phishing verdict. Only | 578 // server responds for both requests with a phishing verdict. Only |
| 579 // a single interstitial is shown for the second URL. | 579 // a single interstitial is shown for the second URL. |
| 580 MockBrowserFeatureExtractor* mock_extractor = | 580 MockBrowserFeatureExtractor* mock_extractor = |
| 581 new StrictMock<MockBrowserFeatureExtractor>( | 581 new StrictMock<MockBrowserFeatureExtractor>( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 EXPECT_EQ(other_phishing_url, resource.url); | 646 EXPECT_EQ(other_phishing_url, resource.url); |
| 647 EXPECT_EQ(other_phishing_url, resource.original_url); | 647 EXPECT_EQ(other_phishing_url, resource.original_url); |
| 648 EXPECT_FALSE(resource.is_subresource); | 648 EXPECT_FALSE(resource.is_subresource); |
| 649 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); | 649 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); |
| 650 EXPECT_EQ(ThreatSource::CLIENT_SIDE_DETECTION, resource.threat_source); | 650 EXPECT_EQ(ThreatSource::CLIENT_SIDE_DETECTION, resource.threat_source); |
| 651 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run()); | 651 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run()); |
| 652 | 652 |
| 653 // Make sure the client object will be deleted. | 653 // Make sure the client object will be deleted. |
| 654 BrowserThread::PostTask( | 654 BrowserThread::PostTask( |
| 655 BrowserThread::IO, FROM_HERE, | 655 BrowserThread::IO, FROM_HERE, |
| 656 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | 656 base::BindOnce(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, |
| 657 ui_manager_, resource.callback)); | 657 ui_manager_, resource.callback)); |
| 658 } | 658 } |
| 659 | 659 |
| 660 TEST_F(ClientSideDetectionHostTest, | 660 TEST_F(ClientSideDetectionHostTest, |
| 661 OnPhishingDetectionDoneVerdictNotPhishing) { | 661 OnPhishingDetectionDoneVerdictNotPhishing) { |
| 662 // Case 6: renderer sends a verdict string that isn't phishing. | 662 // Case 6: renderer sends a verdict string that isn't phishing. |
| 663 MockBrowserFeatureExtractor* mock_extractor = | 663 MockBrowserFeatureExtractor* mock_extractor = |
| 664 new StrictMock<MockBrowserFeatureExtractor>( | 664 new StrictMock<MockBrowserFeatureExtractor>( |
| 665 web_contents(), | 665 web_contents(), |
| 666 csd_host_.get()); | 666 csd_host_.get()); |
| 667 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 667 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 EXPECT_EQ(malware_ip_url, resource.url); | 859 EXPECT_EQ(malware_ip_url, resource.url); |
| 860 EXPECT_EQ(malware_landing_url, resource.original_url); | 860 EXPECT_EQ(malware_landing_url, resource.original_url); |
| 861 EXPECT_TRUE(resource.is_subresource); | 861 EXPECT_TRUE(resource.is_subresource); |
| 862 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, resource.threat_type); | 862 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, resource.threat_type); |
| 863 EXPECT_EQ(ThreatSource::CLIENT_SIDE_DETECTION, resource.threat_source); | 863 EXPECT_EQ(ThreatSource::CLIENT_SIDE_DETECTION, resource.threat_source); |
| 864 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run()); | 864 EXPECT_EQ(web_contents(), resource.web_contents_getter.Run()); |
| 865 | 865 |
| 866 // Make sure the client object will be deleted. | 866 // Make sure the client object will be deleted. |
| 867 BrowserThread::PostTask( | 867 BrowserThread::PostTask( |
| 868 BrowserThread::IO, FROM_HERE, | 868 BrowserThread::IO, FROM_HERE, |
| 869 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | 869 base::BindOnce(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, |
| 870 ui_manager_, resource.callback)); | 870 ui_manager_, resource.callback)); |
| 871 } | 871 } |
| 872 | 872 |
| 873 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { | 873 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
| 874 BrowseInfo* browse_info = GetBrowseInfo(); | 874 BrowseInfo* browse_info = GetBrowseInfo(); |
| 875 | 875 |
| 876 // Empty IP or host are skipped | 876 // Empty IP or host are skipped |
| 877 UpdateIPUrlMap("250.10.10.10", std::string()); | 877 UpdateIPUrlMap("250.10.10.10", std::string()); |
| 878 ASSERT_EQ(0U, browse_info->ips.size()); | 878 ASSERT_EQ(0U, browse_info->ips.size()); |
| 879 UpdateIPUrlMap(std::string(), "http://google.com/a"); | 879 UpdateIPUrlMap(std::string(), "http://google.com/a"); |
| 880 ASSERT_EQ(0U, browse_info->ips.size()); | 880 ASSERT_EQ(0U, browse_info->ips.size()); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 EXPECT_EQ(url, resource.url); | 1191 EXPECT_EQ(url, resource.url); |
| 1192 EXPECT_EQ(url, resource.original_url); | 1192 EXPECT_EQ(url, resource.original_url); |
| 1193 | 1193 |
| 1194 ExpectStartPhishingDetection(NULL); | 1194 ExpectStartPhishingDetection(NULL); |
| 1195 | 1195 |
| 1196 // Showing a phishing warning will invalidate all the weak pointers which | 1196 // Showing a phishing warning will invalidate all the weak pointers which |
| 1197 // means we will not extract malware features. | 1197 // means we will not extract malware features. |
| 1198 ExpectShouldClassifyForMalwareResult(false); | 1198 ExpectShouldClassifyForMalwareResult(false); |
| 1199 } | 1199 } |
| 1200 } // namespace safe_browsing | 1200 } // namespace safe_browsing |
| OLD | NEW |