| 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> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 IncidentVector incidents_; | 94 IncidentVector incidents_; |
| 95 std::vector<std::string> invalid_keys_; | 95 std::vector<std::string> invalid_keys_; |
| 96 std::vector<std::string> external_validation_invalid_keys_; | 96 std::vector<std::string> external_validation_invalid_keys_; |
| 97 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> instance_; | 97 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> instance_; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 // Tests that a NULL value results in an incident with no value. | 100 // Tests that a NULL value results in an incident with no value. |
| 101 TEST_F(PreferenceValidationDelegateTest, NullValue) { | 101 TEST_F(PreferenceValidationDelegateTest, NullValue) { |
| 102 instance_->OnAtomicPreferenceValidation(kPrefPath, NULL, ValueState::CLEARED, | 102 instance_->OnAtomicPreferenceValidation( |
| 103 ValueState::UNSUPPORTED, | 103 kPrefPath, base::nullopt, ValueState::CLEARED, ValueState::UNSUPPORTED, |
| 104 false /* is_personal */); | 104 false /* is_personal */); |
| 105 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | 105 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( |
| 106 incidents_.back()->TakePayload()); | 106 incidents_.back()->TakePayload()); |
| 107 EXPECT_FALSE(incident->tracked_preference().has_atomic_value()); | 107 EXPECT_FALSE(incident->tracked_preference().has_atomic_value()); |
| 108 EXPECT_EQ( | 108 EXPECT_EQ( |
| 109 safe_browsing:: | 109 safe_browsing:: |
| 110 ClientIncidentReport_IncidentData_TrackedPreferenceIncident::CLEARED, | 110 ClientIncidentReport_IncidentData_TrackedPreferenceIncident::CLEARED, |
| 111 incident->tracked_preference().value_state()); | 111 incident->tracked_preference().value_state()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Tests that all supported value types can be stringified into an incident. The | 114 // Tests that all supported value types can be stringified into an incident. The |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 return std::unique_ptr<Value>(); | 157 return std::unique_ptr<Value>(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 base::Value::Type value_type_; | 160 base::Value::Type value_type_; |
| 161 const char* expected_value_; | 161 const char* expected_value_; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 TEST_P(PreferenceValidationDelegateValues, Value) { | 164 TEST_P(PreferenceValidationDelegateValues, Value) { |
| 165 instance_->OnAtomicPreferenceValidation( | 165 instance_->OnAtomicPreferenceValidation( |
| 166 kPrefPath, MakeValue(value_type_), ValueState::CLEARED, | 166 kPrefPath, *MakeValue(value_type_), ValueState::CLEARED, |
| 167 ValueState::UNSUPPORTED, false /* is_personal */); | 167 ValueState::UNSUPPORTED, false /* is_personal */); |
| 168 ASSERT_EQ(1U, incidents_.size()); | 168 ASSERT_EQ(1U, incidents_.size()); |
| 169 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | 169 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( |
| 170 incidents_.back()->TakePayload()); | 170 incidents_.back()->TakePayload()); |
| 171 EXPECT_EQ(std::string(expected_value_), | 171 EXPECT_EQ(std::string(expected_value_), |
| 172 incident->tracked_preference().atomic_value()); | 172 incident->tracked_preference().atomic_value()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 INSTANTIATE_TEST_CASE_P( | 175 INSTANTIATE_TEST_CASE_P( |
| 176 Values, | 176 Values, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 205 value_state_ = std::tr1::get<0>(GetParam()); | 205 value_state_ = std::tr1::get<0>(GetParam()); |
| 206 external_validation_value_state_ = std::tr1::get<1>(GetParam()); | 206 external_validation_value_state_ = std::tr1::get<1>(GetParam()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 ValueState value_state_; | 209 ValueState value_state_; |
| 210 ValueState external_validation_value_state_; | 210 ValueState external_validation_value_state_; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 TEST_P(PreferenceValidationDelegateNoIncident, Atomic) { | 213 TEST_P(PreferenceValidationDelegateNoIncident, Atomic) { |
| 214 instance_->OnAtomicPreferenceValidation( | 214 instance_->OnAtomicPreferenceValidation( |
| 215 kPrefPath, base::Value::CreateNullValue(), value_state_, | 215 kPrefPath, *base::Value::CreateNullValue(), value_state_, |
| 216 external_validation_value_state_, false /* is_personal */); | 216 external_validation_value_state_, false /* is_personal */); |
| 217 EXPECT_EQ(0U, incidents_.size()); | 217 EXPECT_EQ(0U, incidents_.size()); |
| 218 } | 218 } |
| 219 | 219 |
| 220 TEST_P(PreferenceValidationDelegateNoIncident, Split) { | 220 TEST_P(PreferenceValidationDelegateNoIncident, Split) { |
| 221 instance_->OnSplitPreferenceValidation( | 221 instance_->OnSplitPreferenceValidation( |
| 222 kPrefPath, invalid_keys_, external_validation_invalid_keys_, value_state_, | 222 kPrefPath, invalid_keys_, external_validation_invalid_keys_, value_state_, |
| 223 external_validation_value_state_, false /* is_personal */); | 223 external_validation_value_state_, false /* is_personal */); |
| 224 EXPECT_EQ(0U, incidents_.size()); | 224 EXPECT_EQ(0U, incidents_.size()); |
| 225 } | 225 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 248 is_personal_ = std::tr1::get<2>(GetParam()); | 248 is_personal_ = std::tr1::get<2>(GetParam()); |
| 249 } | 249 } |
| 250 | 250 |
| 251 ValueState value_state_; | 251 ValueState value_state_; |
| 252 ValueState external_validation_value_state_; | 252 ValueState external_validation_value_state_; |
| 253 bool is_personal_; | 253 bool is_personal_; |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { | 256 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { |
| 257 instance_->OnAtomicPreferenceValidation( | 257 instance_->OnAtomicPreferenceValidation( |
| 258 kPrefPath, base::Value::CreateNullValue(), value_state_, | 258 kPrefPath, *base::Value::CreateNullValue(), value_state_, |
| 259 external_validation_value_state_, is_personal_); | 259 external_validation_value_state_, is_personal_); |
| 260 ASSERT_EQ(1U, incidents_.size()); | 260 ASSERT_EQ(1U, incidents_.size()); |
| 261 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | 261 std::unique_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( |
| 262 incidents_.back()->TakePayload()); | 262 incidents_.back()->TakePayload()); |
| 263 EXPECT_TRUE(incident->has_tracked_preference()); | 263 EXPECT_TRUE(incident->has_tracked_preference()); |
| 264 const safe_browsing:: | 264 const safe_browsing:: |
| 265 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = | 265 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = |
| 266 incident->tracked_preference(); | 266 incident->tracked_preference(); |
| 267 EXPECT_EQ(kPrefPath, tp_incident.path()); | 267 EXPECT_EQ(kPrefPath, tp_incident.path()); |
| 268 EXPECT_EQ(0, tp_incident.split_key_size()); | 268 EXPECT_EQ(0, tp_incident.split_key_size()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 testing::Bool())); | 328 testing::Bool())); |
| 329 | 329 |
| 330 INSTANTIATE_TEST_CASE_P( | 330 INSTANTIATE_TEST_CASE_P( |
| 331 WithIncidentIgnoreBypass, | 331 WithIncidentIgnoreBypass, |
| 332 PreferenceValidationDelegateWithIncident, | 332 PreferenceValidationDelegateWithIncident, |
| 333 testing::Combine(testing::Values(ValueState::CLEARED, | 333 testing::Combine(testing::Values(ValueState::CLEARED, |
| 334 ValueState::CHANGED, | 334 ValueState::CHANGED, |
| 335 ValueState::UNTRUSTED_UNKNOWN_VALUE), | 335 ValueState::UNTRUSTED_UNKNOWN_VALUE), |
| 336 testing::Values(ValueState::CHANGED, ValueState::CLEARED), | 336 testing::Values(ValueState::CHANGED, ValueState::CLEARED), |
| 337 testing::Bool())); | 337 testing::Bool())); |
| OLD | NEW |