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/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 // A basic test harness that creates a delegate instance for which it stores all | 17 // A basic test harness that creates a delegate instance for which it stores all |
18 // incidents. Tests can push data to the delegate and verify that the test | 18 // incidents. Tests can push data to the delegate and verify that the test |
19 // instance was provided with the expected data. | 19 // instance was provided with the expected data. |
20 class PreferenceValidationDelegateTest : public testing::Test { | 20 class PreferenceValidationDelegateTest : public testing::Test { |
21 protected: | 21 protected: |
22 typedef ScopedVector<safe_browsing::ClientIncidentReport_IncidentData> | 22 typedef ScopedVector<safe_browsing::ClientIncidentReport_IncidentData> |
23 IncidentVector; | 23 IncidentVector; |
24 | 24 |
25 PreferenceValidationDelegateTest() | 25 PreferenceValidationDelegateTest() |
26 : kPrefPath_("atomic.pref"), | 26 : kPrefPath_("atomic.pref"), |
27 null_value_(base::Value::CreateNullValue()) {} | 27 null_value_(base::Value::CreateNullValue()) {} |
28 | 28 |
29 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() override { |
30 testing::Test::SetUp(); | 30 testing::Test::SetUp(); |
31 invalid_keys_.push_back(std::string("one")); | 31 invalid_keys_.push_back(std::string("one")); |
32 invalid_keys_.push_back(std::string("two")); | 32 invalid_keys_.push_back(std::string("two")); |
33 instance_.reset(new safe_browsing::PreferenceValidationDelegate( | 33 instance_.reset(new safe_browsing::PreferenceValidationDelegate( |
34 base::Bind(&PreferenceValidationDelegateTest::AddIncident, | 34 base::Bind(&PreferenceValidationDelegateTest::AddIncident, |
35 base::Unretained(this)))); | 35 base::Unretained(this)))); |
36 } | 36 } |
37 | 37 |
38 void AddIncident( | 38 void AddIncident( |
39 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> data) { | 39 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> data) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 // Tests that all supported value types can be stringified into an incident. The | 98 // Tests that all supported value types can be stringified into an incident. The |
99 // parameters for the test are the type of value to test and the expected value | 99 // parameters for the test are the type of value to test and the expected value |
100 // string. | 100 // string. |
101 class PreferenceValidationDelegateValues | 101 class PreferenceValidationDelegateValues |
102 : public PreferenceValidationDelegateTest, | 102 : public PreferenceValidationDelegateTest, |
103 public testing::WithParamInterface< | 103 public testing::WithParamInterface< |
104 std::tr1::tuple<base::Value::Type, const char*> > { | 104 std::tr1::tuple<base::Value::Type, const char*> > { |
105 protected: | 105 protected: |
106 virtual void SetUp() OVERRIDE { | 106 virtual void SetUp() override { |
107 PreferenceValidationDelegateTest::SetUp(); | 107 PreferenceValidationDelegateTest::SetUp(); |
108 value_type_ = std::tr1::get<0>(GetParam()); | 108 value_type_ = std::tr1::get<0>(GetParam()); |
109 expected_value_ = std::tr1::get<1>(GetParam()); | 109 expected_value_ = std::tr1::get<1>(GetParam()); |
110 } | 110 } |
111 | 111 |
112 static scoped_ptr<base::Value> MakeValue(base::Value::Type value_type) { | 112 static scoped_ptr<base::Value> MakeValue(base::Value::Type value_type) { |
113 using base::Value; | 113 using base::Value; |
114 switch (value_type) { | 114 switch (value_type) { |
115 case Value::TYPE_NULL: | 115 case Value::TYPE_NULL: |
116 return make_scoped_ptr(Value::CreateNullValue()); | 116 return make_scoped_ptr(Value::CreateNullValue()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 std::tr1::make_tuple(base::Value::TYPE_DICTIONARY, | 176 std::tr1::make_tuple(base::Value::TYPE_DICTIONARY, |
177 const_cast<char*>("{\"forty-seven\":47,\"twenty-two\":22}")), | 177 const_cast<char*>("{\"forty-seven\":47,\"twenty-two\":22}")), |
178 std::tr1::make_tuple(base::Value::TYPE_LIST, | 178 std::tr1::make_tuple(base::Value::TYPE_LIST, |
179 const_cast<char*>("[22,47]")))); | 179 const_cast<char*>("[22,47]")))); |
180 | 180 |
181 // Tests that no incidents are reported for relevant combinations of ValueState. | 181 // Tests that no incidents are reported for relevant combinations of ValueState. |
182 class PreferenceValidationDelegateNoIncident | 182 class PreferenceValidationDelegateNoIncident |
183 : public PreferenceValidationDelegateTest, | 183 : public PreferenceValidationDelegateTest, |
184 public testing::WithParamInterface<PrefHashStoreTransaction::ValueState> { | 184 public testing::WithParamInterface<PrefHashStoreTransaction::ValueState> { |
185 protected: | 185 protected: |
186 virtual void SetUp() OVERRIDE { | 186 virtual void SetUp() override { |
187 PreferenceValidationDelegateTest::SetUp(); | 187 PreferenceValidationDelegateTest::SetUp(); |
188 value_state_ = GetParam(); | 188 value_state_ = GetParam(); |
189 } | 189 } |
190 | 190 |
191 PrefHashStoreTransaction::ValueState value_state_; | 191 PrefHashStoreTransaction::ValueState value_state_; |
192 }; | 192 }; |
193 | 193 |
194 TEST_P(PreferenceValidationDelegateNoIncident, Atomic) { | 194 TEST_P(PreferenceValidationDelegateNoIncident, Atomic) { |
195 instance_->OnAtomicPreferenceValidation(kPrefPath_, | 195 instance_->OnAtomicPreferenceValidation(kPrefPath_, |
196 null_value_.get(), | 196 null_value_.get(), |
(...skipping 19 matching lines...) Expand all Loading... |
216 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE)); | 216 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE)); |
217 | 217 |
218 // Tests that incidents are reported for relevant combinations of ValueState and | 218 // Tests that incidents are reported for relevant combinations of ValueState and |
219 // ResetAction. | 219 // ResetAction. |
220 class PreferenceValidationDelegateWithIncident | 220 class PreferenceValidationDelegateWithIncident |
221 : public PreferenceValidationDelegateTest, | 221 : public PreferenceValidationDelegateTest, |
222 public testing::WithParamInterface< | 222 public testing::WithParamInterface< |
223 std::tr1::tuple<PrefHashStoreTransaction::ValueState, | 223 std::tr1::tuple<PrefHashStoreTransaction::ValueState, |
224 TrackedPreferenceHelper::ResetAction> > { | 224 TrackedPreferenceHelper::ResetAction> > { |
225 protected: | 225 protected: |
226 virtual void SetUp() OVERRIDE { | 226 virtual void SetUp() override { |
227 PreferenceValidationDelegateTest::SetUp(); | 227 PreferenceValidationDelegateTest::SetUp(); |
228 value_state_ = std::tr1::get<0>(GetParam()); | 228 value_state_ = std::tr1::get<0>(GetParam()); |
229 reset_action_ = std::tr1::get<1>(GetParam()); | 229 reset_action_ = std::tr1::get<1>(GetParam()); |
230 } | 230 } |
231 | 231 |
232 PrefHashStoreTransaction::ValueState value_state_; | 232 PrefHashStoreTransaction::ValueState value_state_; |
233 TrackedPreferenceHelper::ResetAction reset_action_; | 233 TrackedPreferenceHelper::ResetAction reset_action_; |
234 }; | 234 }; |
235 | 235 |
236 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { | 236 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 270 |
271 INSTANTIATE_TEST_CASE_P( | 271 INSTANTIATE_TEST_CASE_P( |
272 WithIncident, | 272 WithIncident, |
273 PreferenceValidationDelegateWithIncident, | 273 PreferenceValidationDelegateWithIncident, |
274 testing::Combine( | 274 testing::Combine( |
275 testing::Values(PrefHashStoreTransaction::CLEARED, | 275 testing::Values(PrefHashStoreTransaction::CLEARED, |
276 PrefHashStoreTransaction::CHANGED, | 276 PrefHashStoreTransaction::CHANGED, |
277 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), | 277 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), |
278 testing::Values(TrackedPreferenceHelper::WANTED_RESET, | 278 testing::Values(TrackedPreferenceHelper::WANTED_RESET, |
279 TrackedPreferenceHelper::DO_RESET))); | 279 TrackedPreferenceHelper::DO_RESET))); |
OLD | NEW |