OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/incident_reporting/preference_validation_
delegate.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 14 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
| 15 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" |
15 #include "chrome/common/safe_browsing/csd.pb.h" | 16 #include "chrome/common/safe_browsing/csd.pb.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
| 20 using ::testing::_; |
| 21 using ::testing::IsNull; |
| 22 using ::testing::NiceMock; |
| 23 using ::testing::WithArg; |
| 24 |
18 // A basic test harness that creates a delegate instance for which it stores all | 25 // A basic test harness that creates a delegate instance for which it stores all |
19 // incidents. Tests can push data to the delegate and verify that the test | 26 // incidents. Tests can push data to the delegate and verify that the test |
20 // instance was provided with the expected data. | 27 // instance was provided with the expected data. |
21 class PreferenceValidationDelegateTest : public testing::Test { | 28 class PreferenceValidationDelegateTest : public testing::Test { |
22 protected: | 29 protected: |
23 typedef ScopedVector<safe_browsing::Incident> IncidentVector; | 30 typedef ScopedVector<safe_browsing::Incident> IncidentVector; |
24 | 31 |
25 PreferenceValidationDelegateTest() | 32 PreferenceValidationDelegateTest() |
26 : kPrefPath_("atomic.pref"), | 33 : kPrefPath_("atomic.pref"), |
27 null_value_(base::Value::CreateNullValue()) {} | 34 null_value_(base::Value::CreateNullValue()) {} |
28 | 35 |
29 void SetUp() override { | 36 void SetUp() override { |
30 testing::Test::SetUp(); | 37 testing::Test::SetUp(); |
31 invalid_keys_.push_back(std::string("one")); | 38 invalid_keys_.push_back(std::string("one")); |
32 invalid_keys_.push_back(std::string("two")); | 39 invalid_keys_.push_back(std::string("two")); |
| 40 scoped_ptr<safe_browsing::MockIncidentReceiver> receiver( |
| 41 new NiceMock<safe_browsing::MockIncidentReceiver>()); |
| 42 ON_CALL(*receiver, DoAddIncidentForProfile(IsNull(), _)) |
| 43 .WillByDefault(WithArg<1>(TakeIncidentToVector(&incidents_))); |
33 instance_.reset(new safe_browsing::PreferenceValidationDelegate( | 44 instance_.reset(new safe_browsing::PreferenceValidationDelegate( |
34 base::Bind(&PreferenceValidationDelegateTest::AddIncident, | 45 nullptr, receiver.Pass())); |
35 base::Unretained(this)))); | |
36 } | |
37 | |
38 void AddIncident(scoped_ptr<safe_browsing::Incident> incident) { | |
39 incidents_.push_back(incident.release()); | |
40 } | 46 } |
41 | 47 |
42 static void ExpectValueStatesEquate( | 48 static void ExpectValueStatesEquate( |
43 PrefHashStoreTransaction::ValueState store_state, | 49 PrefHashStoreTransaction::ValueState store_state, |
44 safe_browsing:: | 50 safe_browsing:: |
45 ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState | 51 ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState |
46 incident_state) { | 52 incident_state) { |
47 typedef safe_browsing:: | 53 typedef safe_browsing:: |
48 ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; | 54 ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; |
49 switch (store_state) { | 55 switch (store_state) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 280 } |
275 | 281 |
276 INSTANTIATE_TEST_CASE_P( | 282 INSTANTIATE_TEST_CASE_P( |
277 WithIncident, | 283 WithIncident, |
278 PreferenceValidationDelegateWithIncident, | 284 PreferenceValidationDelegateWithIncident, |
279 testing::Combine( | 285 testing::Combine( |
280 testing::Values(PrefHashStoreTransaction::CLEARED, | 286 testing::Values(PrefHashStoreTransaction::CLEARED, |
281 PrefHashStoreTransaction::CHANGED, | 287 PrefHashStoreTransaction::CHANGED, |
282 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), | 288 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), |
283 testing::Bool())); | 289 testing::Bool())); |
OLD | NEW |