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 <tuple> | 8 #include <tuple> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 17 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/browser/safe_browsing/ui_manager.h" | 20 #include "chrome/browser/safe_browsing/ui_manager.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
23 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 23 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 MATCHER(CallbackIsNull, "") { | 92 MATCHER(CallbackIsNull, "") { |
93 return arg.is_null(); | 93 return arg.is_null(); |
94 } | 94 } |
95 | 95 |
96 ACTION(QuitUIMessageLoop) { | 96 ACTION(QuitUIMessageLoop) { |
97 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
98 base::MessageLoopForUI::current()->QuitWhenIdle(); | 98 base::MessageLoopForUI::current()->QuitWhenIdle(); |
99 } | 99 } |
100 | 100 |
101 ACTION_P(InvokeDoneCallback, verdict) { | 101 ACTION_P(InvokeDoneCallback, verdict) { |
102 scoped_ptr<ClientPhishingRequest> request(::std::tr1::get<1>(args)); | 102 std::unique_ptr<ClientPhishingRequest> request(::std::tr1::get<1>(args)); |
103 request->CopyFrom(*verdict); | 103 request->CopyFrom(*verdict); |
104 ::std::tr1::get<2>(args).Run(true, std::move(request)); | 104 ::std::tr1::get<2>(args).Run(true, std::move(request)); |
105 } | 105 } |
106 | 106 |
107 ACTION_P(InvokeMalwareCallback, verdict) { | 107 ACTION_P(InvokeMalwareCallback, verdict) { |
108 scoped_ptr<ClientMalwareRequest> request(::std::tr1::get<1>(args)); | 108 std::unique_ptr<ClientMalwareRequest> request(::std::tr1::get<1>(args)); |
109 request->CopyFrom(*verdict); | 109 request->CopyFrom(*verdict); |
110 ::std::tr1::get<2>(args).Run(true, std::move(request)); | 110 ::std::tr1::get<2>(args).Run(true, std::move(request)); |
111 } | 111 } |
112 | 112 |
113 void EmptyUrlCheckCallback(bool processed) { | 113 void EmptyUrlCheckCallback(bool processed) { |
114 } | 114 } |
115 | 115 |
116 class MockClientSideDetectionService : public ClientSideDetectionService { | 116 class MockClientSideDetectionService : public ClientSideDetectionService { |
117 public: | 117 public: |
118 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} | 118 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 for (unsigned int i = 0; i < expect.size(); ++i) { | 432 for (unsigned int i = 0; i < expect.size(); ++i) { |
433 EXPECT_EQ(expect[i].url, result[i].url); | 433 EXPECT_EQ(expect[i].url, result[i].url); |
434 EXPECT_EQ(expect[i].method, result[i].method); | 434 EXPECT_EQ(expect[i].method, result[i].method); |
435 EXPECT_EQ(expect[i].referrer, result[i].referrer); | 435 EXPECT_EQ(expect[i].referrer, result[i].referrer); |
436 EXPECT_EQ(expect[i].resource_type, result[i].resource_type); | 436 EXPECT_EQ(expect[i].resource_type, result[i].resource_type); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 protected: | 440 protected: |
441 scoped_ptr<ClientSideDetectionHost> csd_host_; | 441 std::unique_ptr<ClientSideDetectionHost> csd_host_; |
442 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; | 442 std::unique_ptr<StrictMock<MockClientSideDetectionService>> csd_service_; |
443 scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_; | 443 scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_; |
444 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_; | 444 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_; |
445 MockTestingProfile* mock_profile_; // We don't own this object | 445 MockTestingProfile* mock_profile_; // We don't own this object |
446 }; | 446 }; |
447 | 447 |
448 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { | 448 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { |
449 // Case 0: renderer sends an invalid verdict string that we're unable to | 449 // Case 0: renderer sends an invalid verdict string that we're unable to |
450 // parse. | 450 // parse. |
451 MockBrowserFeatureExtractor* mock_extractor = | 451 MockBrowserFeatureExtractor* mock_extractor = |
452 new StrictMock<MockBrowserFeatureExtractor>( | 452 new StrictMock<MockBrowserFeatureExtractor>( |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 EXPECT_EQ(url, resource.url); | 1199 EXPECT_EQ(url, resource.url); |
1200 EXPECT_EQ(url, resource.original_url); | 1200 EXPECT_EQ(url, resource.original_url); |
1201 | 1201 |
1202 ExpectStartPhishingDetection(NULL); | 1202 ExpectStartPhishingDetection(NULL); |
1203 | 1203 |
1204 // Showing a phishing warning will invalidate all the weak pointers which | 1204 // Showing a phishing warning will invalidate all the weak pointers which |
1205 // means we will not extract malware features. | 1205 // means we will not extract malware features. |
1206 ExpectShouldClassifyForMalwareResult(false); | 1206 ExpectShouldClassifyForMalwareResult(false); |
1207 } | 1207 } |
1208 } // namespace safe_browsing | 1208 } // namespace safe_browsing |
OLD | NEW |