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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/memory/ptr_util.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 18 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
18 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" | 19 #include "chrome/browser/safe_browsing/incident_reporting/mock_incident_receiver
.h" |
19 #include "components/safe_browsing/csd.pb.h" | 20 #include "components/safe_browsing/csd.pb.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using ::testing::_; | 24 using ::testing::_; |
24 using ::testing::IsNull; | 25 using ::testing::IsNull; |
25 using ::testing::NiceMock; | 26 using ::testing::NiceMock; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void SetUp() override { | 123 void SetUp() override { |
123 PreferenceValidationDelegateTest::SetUp(); | 124 PreferenceValidationDelegateTest::SetUp(); |
124 value_type_ = std::tr1::get<0>(GetParam()); | 125 value_type_ = std::tr1::get<0>(GetParam()); |
125 expected_value_ = std::tr1::get<1>(GetParam()); | 126 expected_value_ = std::tr1::get<1>(GetParam()); |
126 } | 127 } |
127 | 128 |
128 static std::unique_ptr<base::Value> MakeValue(base::Value::Type value_type) { | 129 static std::unique_ptr<base::Value> MakeValue(base::Value::Type value_type) { |
129 using base::Value; | 130 using base::Value; |
130 switch (value_type) { | 131 switch (value_type) { |
131 case Value::Type::NONE: | 132 case Value::Type::NONE: |
132 return Value::CreateNullValue(); | 133 return base::MakeUnique<base::Value>(); |
133 case Value::Type::BOOLEAN: | 134 case Value::Type::BOOLEAN: |
134 return std::unique_ptr<Value>(new base::Value(false)); | 135 return std::unique_ptr<Value>(new base::Value(false)); |
135 case Value::Type::INTEGER: | 136 case Value::Type::INTEGER: |
136 return std::unique_ptr<Value>(new base::Value(47)); | 137 return std::unique_ptr<Value>(new base::Value(47)); |
137 case Value::Type::DOUBLE: | 138 case Value::Type::DOUBLE: |
138 return std::unique_ptr<Value>(new base::Value(0.47)); | 139 return std::unique_ptr<Value>(new base::Value(0.47)); |
139 case Value::Type::STRING: | 140 case Value::Type::STRING: |
140 return std::unique_ptr<Value>(new base::Value("i have a spleen")); | 141 return std::unique_ptr<Value>(new base::Value("i have a spleen")); |
141 case Value::Type::DICTIONARY: { | 142 case Value::Type::DICTIONARY: { |
142 std::unique_ptr<base::DictionaryValue> value( | 143 std::unique_ptr<base::DictionaryValue> value( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 value_state_ = std::tr1::get<0>(GetParam()); | 206 value_state_ = std::tr1::get<0>(GetParam()); |
206 external_validation_value_state_ = std::tr1::get<1>(GetParam()); | 207 external_validation_value_state_ = std::tr1::get<1>(GetParam()); |
207 } | 208 } |
208 | 209 |
209 ValueState value_state_; | 210 ValueState value_state_; |
210 ValueState external_validation_value_state_; | 211 ValueState external_validation_value_state_; |
211 }; | 212 }; |
212 | 213 |
213 TEST_P(PreferenceValidationDelegateNoIncident, Atomic) { | 214 TEST_P(PreferenceValidationDelegateNoIncident, Atomic) { |
214 instance_->OnAtomicPreferenceValidation( | 215 instance_->OnAtomicPreferenceValidation( |
215 kPrefPath, base::Value::CreateNullValue(), value_state_, | 216 kPrefPath, base::MakeUnique<base::Value>(), value_state_, |
216 external_validation_value_state_, false /* is_personal */); | 217 external_validation_value_state_, false /* is_personal */); |
217 EXPECT_EQ(0U, incidents_.size()); | 218 EXPECT_EQ(0U, incidents_.size()); |
218 } | 219 } |
219 | 220 |
220 TEST_P(PreferenceValidationDelegateNoIncident, Split) { | 221 TEST_P(PreferenceValidationDelegateNoIncident, Split) { |
221 instance_->OnSplitPreferenceValidation( | 222 instance_->OnSplitPreferenceValidation( |
222 kPrefPath, invalid_keys_, external_validation_invalid_keys_, value_state_, | 223 kPrefPath, invalid_keys_, external_validation_invalid_keys_, value_state_, |
223 external_validation_value_state_, false /* is_personal */); | 224 external_validation_value_state_, false /* is_personal */); |
224 EXPECT_EQ(0U, incidents_.size()); | 225 EXPECT_EQ(0U, incidents_.size()); |
225 } | 226 } |
(...skipping 22 matching lines...) Expand all Loading... |
248 is_personal_ = std::tr1::get<2>(GetParam()); | 249 is_personal_ = std::tr1::get<2>(GetParam()); |
249 } | 250 } |
250 | 251 |
251 ValueState value_state_; | 252 ValueState value_state_; |
252 ValueState external_validation_value_state_; | 253 ValueState external_validation_value_state_; |
253 bool is_personal_; | 254 bool is_personal_; |
254 }; | 255 }; |
255 | 256 |
256 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { | 257 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { |
257 instance_->OnAtomicPreferenceValidation( | 258 instance_->OnAtomicPreferenceValidation( |
258 kPrefPath, base::Value::CreateNullValue(), value_state_, | 259 kPrefPath, base::MakeUnique<base::Value>(), value_state_, |
259 external_validation_value_state_, is_personal_); | 260 external_validation_value_state_, is_personal_); |
260 ASSERT_EQ(1U, incidents_.size()); | 261 ASSERT_EQ(1U, incidents_.size()); |
261 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | 262 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( |
262 incidents_.back()->TakePayload()); | 263 incidents_.back()->TakePayload()); |
263 EXPECT_TRUE(incident->has_tracked_preference()); | 264 EXPECT_TRUE(incident->has_tracked_preference()); |
264 const safe_browsing:: | 265 const safe_browsing:: |
265 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = | 266 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = |
266 incident->tracked_preference(); | 267 incident->tracked_preference(); |
267 EXPECT_EQ(kPrefPath, tp_incident.path()); | 268 EXPECT_EQ(kPrefPath, tp_incident.path()); |
268 EXPECT_EQ(0, tp_incident.split_key_size()); | 269 EXPECT_EQ(0, tp_incident.split_key_size()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 testing::Bool())); | 329 testing::Bool())); |
329 | 330 |
330 INSTANTIATE_TEST_CASE_P( | 331 INSTANTIATE_TEST_CASE_P( |
331 WithIncidentIgnoreBypass, | 332 WithIncidentIgnoreBypass, |
332 PreferenceValidationDelegateWithIncident, | 333 PreferenceValidationDelegateWithIncident, |
333 testing::Combine(testing::Values(ValueState::CLEARED, | 334 testing::Combine(testing::Values(ValueState::CLEARED, |
334 ValueState::CHANGED, | 335 ValueState::CHANGED, |
335 ValueState::UNTRUSTED_UNKNOWN_VALUE), | 336 ValueState::UNTRUSTED_UNKNOWN_VALUE), |
336 testing::Values(ValueState::CHANGED, ValueState::CLEARED), | 337 testing::Values(ValueState::CHANGED, ValueState::CLEARED), |
337 testing::Bool())); | 338 testing::Bool())); |
OLD | NEW |