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 "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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 database_manager_ = new StrictMock<MockSafeBrowsingDatabaseManager>(); | 215 database_manager_ = new StrictMock<MockSafeBrowsingDatabaseManager>(); |
| 216 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>( | 216 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>( |
| 217 SafeBrowsingService::CreateSafeBrowsingService()); | 217 SafeBrowsingService::CreateSafeBrowsingService()); |
| 218 csd_host_.reset(ClientSideDetectionHost::Create(web_contents())); | 218 csd_host_.reset(ClientSideDetectionHost::Create(web_contents())); |
| 219 csd_host_->set_client_side_detection_service(csd_service_.get()); | 219 csd_host_->set_client_side_detection_service(csd_service_.get()); |
| 220 csd_host_->set_safe_browsing_managers(ui_manager_.get(), | 220 csd_host_->set_safe_browsing_managers(ui_manager_.get(), |
| 221 database_manager_.get()); | 221 database_manager_.get()); |
| 222 // We need to create this here since we don't call DidStopLanding in | 222 // We need to create this here since we don't call DidStopLanding in |
| 223 // this test. | 223 // this test. |
| 224 csd_host_->browse_info_.reset(new BrowseInfo); | 224 csd_host_->browse_info_.reset(new BrowseInfo); |
| 225 ClientSideDetectionHost::IgnoreMimeTypeCheckForTesting(true); | |
| 225 } | 226 } |
| 226 | 227 |
| 227 void TearDown() override { | 228 void TearDown() override { |
| 228 // Delete the host object on the UI thread and release the | 229 // Delete the host object on the UI thread and release the |
| 229 // SafeBrowsingService. | 230 // SafeBrowsingService. |
| 230 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, | 231 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, |
| 231 csd_host_.release()); | 232 csd_host_.release()); |
| 232 database_manager_ = NULL; | 233 database_manager_ = NULL; |
| 233 ui_manager_ = NULL; | 234 ui_manager_ = NULL; |
| 234 base::RunLoop().RunUntilIdle(); | 235 base::RunLoop().RunUntilIdle(); |
| 235 ChromeRenderViewHostTestHarness::TearDown(); | 236 ChromeRenderViewHostTestHarness::TearDown(); |
| 237 ClientSideDetectionHost::IgnoreMimeTypeCheckForTesting(false); | |
| 236 } | 238 } |
| 237 | 239 |
| 238 content::BrowserContext* CreateBrowserContext() override { | 240 content::BrowserContext* CreateBrowserContext() override { |
| 239 // Set custom profile object so that we can mock calls to IsOffTheRecord. | 241 // Set custom profile object so that we can mock calls to IsOffTheRecord. |
| 240 // This needs to happen before we call the parent SetUp() function. We use | 242 // This needs to happen before we call the parent SetUp() function. We use |
| 241 // a nice mock because other parts of the code are calling IsOffTheRecord. | 243 // a nice mock because other parts of the code are calling IsOffTheRecord. |
| 242 mock_profile_ = new NiceMock<MockTestingProfile>(); | 244 mock_profile_ = new NiceMock<MockTestingProfile>(); |
| 243 return mock_profile_; | 245 return mock_profile_; |
| 244 } | 246 } |
| 245 | 247 |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 988 WaitAndCheckPreClassificationChecks(); | 990 WaitAndCheckPreClassificationChecks(); |
| 989 | 991 |
| 990 ExpectStartPhishingDetection(NULL); | 992 ExpectStartPhishingDetection(NULL); |
| 991 ExpectShouldClassifyForMalwareResult(true); | 993 ExpectShouldClassifyForMalwareResult(true); |
| 992 } | 994 } |
| 993 | 995 |
| 994 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckXHTML) { | 996 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckXHTML) { |
| 995 // Check that XHTML is supported, in addition to the default HTML type. | 997 // Check that XHTML is supported, in addition to the default HTML type. |
| 996 GURL url("http://host.com/xhtml"); | 998 GURL url("http://host.com/xhtml"); |
| 997 RenderFrameHostTester::For(web_contents()->GetMainFrame())-> | 999 RenderFrameHostTester::For(web_contents()->GetMainFrame())-> |
| 998 SetContentsMimeType("application/xhtml+xml"); | 1000 SetContentsMimeType("application/xhtml+xml"); |
|
mattm
2017/02/07 20:35:47
(also this one is currently getting ignored, but i
| |
| 999 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 1001 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 1000 &kFalse, &kFalse, &kFalse, &kFalse); | 1002 &kFalse, &kFalse, &kFalse, &kFalse); |
| 1001 NavigateAndCommit(url); | 1003 NavigateAndCommit(url); |
| 1002 WaitAndCheckPreClassificationChecks(); | 1004 WaitAndCheckPreClassificationChecks(); |
| 1003 | 1005 |
| 1004 ExpectStartPhishingDetection(&url); | 1006 ExpectStartPhishingDetection(&url); |
| 1005 ExpectShouldClassifyForMalwareResult(true); | 1007 ExpectShouldClassifyForMalwareResult(true); |
| 1006 } | 1008 } |
| 1007 | 1009 |
| 1008 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckTwoNavigations) { | 1010 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckTwoNavigations) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1026 ExpectShouldClassifyForMalwareResult(true); | 1028 ExpectShouldClassifyForMalwareResult(true); |
| 1027 } | 1029 } |
| 1028 | 1030 |
| 1029 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckMimeType) { | 1031 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckMimeType) { |
| 1030 // If the mime type is not one that we support, no IPC should be triggered | 1032 // If the mime type is not one that we support, no IPC should be triggered |
| 1031 // but all pre-classification checks should run because we might classify | 1033 // but all pre-classification checks should run because we might classify |
| 1032 // other mime types for malware. | 1034 // other mime types for malware. |
| 1033 // Note: for this test to work correctly, the new URL must be on the | 1035 // Note: for this test to work correctly, the new URL must be on the |
| 1034 // same domain as the previous URL, otherwise it will create a new | 1036 // same domain as the previous URL, otherwise it will create a new |
| 1035 // RenderFrameHost that won't have the mime type set. | 1037 // RenderFrameHost that won't have the mime type set. |
| 1038 ClientSideDetectionHost::IgnoreMimeTypeCheckForTesting(false); | |
| 1036 GURL url("http://host2.com/image.jpg"); | 1039 GURL url("http://host2.com/image.jpg"); |
| 1037 RenderFrameHostTester::For(web_contents()->GetMainFrame())-> | 1040 RenderFrameHostTester::For(web_contents()->GetMainFrame())-> |
| 1038 SetContentsMimeType("image/jpeg"); | 1041 SetContentsMimeType("image/jpeg"); |
| 1039 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 1042 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 1040 &kFalse, &kFalse, &kFalse, &kFalse); | 1043 &kFalse, &kFalse, &kFalse, &kFalse); |
| 1041 NavigateAndCommit(url); | 1044 NavigateAndCommit(url); |
| 1042 WaitAndCheckPreClassificationChecks(); | 1045 WaitAndCheckPreClassificationChecks(); |
| 1043 | 1046 |
| 1044 ExpectStartPhishingDetection(NULL); | 1047 ExpectStartPhishingDetection(NULL); |
| 1045 ExpectShouldClassifyForMalwareResult(true); | 1048 ExpectShouldClassifyForMalwareResult(true); |
| 1049 ClientSideDetectionHost::IgnoreMimeTypeCheckForTesting(true); | |
| 1046 } | 1050 } |
| 1047 | 1051 |
| 1048 TEST_F(ClientSideDetectionHostTest, | 1052 TEST_F(ClientSideDetectionHostTest, |
| 1049 TestPreClassificationCheckPrivateIpAddress) { | 1053 TestPreClassificationCheckPrivateIpAddress) { |
| 1050 // If IsPrivateIPAddress returns true, no IPC should be triggered. | 1054 // If IsPrivateIPAddress returns true, no IPC should be triggered. |
| 1051 GURL url("http://host3.com/"); | 1055 GURL url("http://host3.com/"); |
| 1052 ExpectPreClassificationChecks(url, &kTrue, &kFalse, NULL, NULL, NULL, NULL, | 1056 ExpectPreClassificationChecks(url, &kTrue, &kFalse, NULL, NULL, NULL, NULL, |
| 1053 NULL, NULL); | 1057 NULL, NULL); |
| 1054 NavigateAndCommit(url); | 1058 NavigateAndCommit(url); |
| 1055 WaitAndCheckPreClassificationChecks(); | 1059 WaitAndCheckPreClassificationChecks(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 EXPECT_EQ(url, resource.url); | 1195 EXPECT_EQ(url, resource.url); |
| 1192 EXPECT_EQ(url, resource.original_url); | 1196 EXPECT_EQ(url, resource.original_url); |
| 1193 | 1197 |
| 1194 ExpectStartPhishingDetection(NULL); | 1198 ExpectStartPhishingDetection(NULL); |
| 1195 | 1199 |
| 1196 // Showing a phishing warning will invalidate all the weak pointers which | 1200 // Showing a phishing warning will invalidate all the weak pointers which |
| 1197 // means we will not extract malware features. | 1201 // means we will not extract malware features. |
| 1198 ExpectShouldClassifyForMalwareResult(false); | 1202 ExpectShouldClassifyForMalwareResult(false); |
| 1199 } | 1203 } |
| 1200 } // namespace safe_browsing | 1204 } // namespace safe_browsing |
| OLD | NEW |