| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 request->CopyFrom(*verdict); | 104 request->CopyFrom(*verdict); |
| 105 ::std::tr1::get<2>(args).Run(true, request.Pass()); | 105 ::std::tr1::get<2>(args).Run(true, request.Pass()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void EmptyUrlCheckCallback(bool processed) { | 108 void EmptyUrlCheckCallback(bool processed) { |
| 109 } | 109 } |
| 110 | 110 |
| 111 class MockClientSideDetectionService : public ClientSideDetectionService { | 111 class MockClientSideDetectionService : public ClientSideDetectionService { |
| 112 public: | 112 public: |
| 113 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} | 113 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} |
| 114 virtual ~MockClientSideDetectionService() {}; | 114 virtual ~MockClientSideDetectionService() {} |
| 115 | 115 |
| 116 MOCK_METHOD2(SendClientReportPhishingRequest, | 116 MOCK_METHOD2(SendClientReportPhishingRequest, |
| 117 void(ClientPhishingRequest*, | 117 void(ClientPhishingRequest*, |
| 118 const ClientReportPhishingRequestCallback&)); | 118 const ClientReportPhishingRequestCallback&)); |
| 119 MOCK_METHOD2(SendClientReportMalwareRequest, | 119 MOCK_METHOD2(SendClientReportMalwareRequest, |
| 120 void(ClientMalwareRequest*, | 120 void(ClientMalwareRequest*, |
| 121 const ClientReportMalwareRequestCallback&)); | 121 const ClientReportMalwareRequestCallback&)); |
| 122 MOCK_CONST_METHOD1(IsPrivateIPAddress, bool(const std::string&)); | 122 MOCK_CONST_METHOD1(IsPrivateIPAddress, bool(const std::string&)); |
| 123 MOCK_METHOD2(GetValidCachedResult, bool(const GURL&, bool*)); | 123 MOCK_METHOD2(GetValidCachedResult, bool(const GURL&, bool*)); |
| 124 MOCK_METHOD1(IsInCache, bool(const GURL&)); | 124 MOCK_METHOD1(IsInCache, bool(const GURL&)); |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckMimeType) { | 982 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckMimeType) { |
| 983 // If the mime type is not one that we support, no IPC should be triggered | 983 // If the mime type is not one that we support, no IPC should be triggered |
| 984 // but all pre-classification checks should run because we might classify | 984 // but all pre-classification checks should run because we might classify |
| 985 // other mime types for malware. | 985 // other mime types for malware. |
| 986 // Note: for this test to work correctly, the new URL must be on the | 986 // Note: for this test to work correctly, the new URL must be on the |
| 987 // same domain as the previous URL, otherwise it will create a new | 987 // same domain as the previous URL, otherwise it will create a new |
| 988 // RenderViewHost that won't have the mime type set. | 988 // RenderViewHost that won't have the mime type set. |
| 989 GURL url("http://host2.com/image.jpg"); | 989 GURL url("http://host2.com/image.jpg"); |
| 990 rvh_tester()->SetContentsMimeType("image/jpeg"); | 990 rvh_tester()->SetContentsMimeType("image/jpeg"); |
| 991 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 991 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| 992 &kFalse, &kFalse,&kFalse, &kFalse); | 992 &kFalse, &kFalse, &kFalse, &kFalse); |
| 993 NavigateAndCommit(url); | 993 NavigateAndCommit(url); |
| 994 WaitAndCheckPreClassificationChecks(); | 994 WaitAndCheckPreClassificationChecks(); |
| 995 | 995 |
| 996 ExpectStartPhishingDetection(NULL); | 996 ExpectStartPhishingDetection(NULL); |
| 997 ExpectShouldClassifyForMalwareResult(true); | 997 ExpectShouldClassifyForMalwareResult(true); |
| 998 } | 998 } |
| 999 | 999 |
| 1000 TEST_F(ClientSideDetectionHostTest, | 1000 TEST_F(ClientSideDetectionHostTest, |
| 1001 TestPreClassificationCheckPrivateIpAddress) { | 1001 TestPreClassificationCheckPrivateIpAddress) { |
| 1002 // If IsPrivateIPAddress returns true, no IPC should be triggered. | 1002 // If IsPrivateIPAddress returns true, no IPC should be triggered. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 EXPECT_EQ(url, resource.url); | 1143 EXPECT_EQ(url, resource.url); |
| 1144 EXPECT_EQ(url, resource.original_url); | 1144 EXPECT_EQ(url, resource.original_url); |
| 1145 | 1145 |
| 1146 ExpectStartPhishingDetection(NULL); | 1146 ExpectStartPhishingDetection(NULL); |
| 1147 | 1147 |
| 1148 // Showing a phishing warning will invalidate all the weak pointers which | 1148 // Showing a phishing warning will invalidate all the weak pointers which |
| 1149 // means we will not extract malware features. | 1149 // means we will not extract malware features. |
| 1150 ExpectShouldClassifyForMalwareResult(false); | 1150 ExpectShouldClassifyForMalwareResult(false); |
| 1151 } | 1151 } |
| 1152 } // namespace safe_browsing | 1152 } // namespace safe_browsing |
| OLD | NEW |