Chromium Code Reviews| 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/preference_validation_delegate.h" | 5 #include "chrome/browser/safe_browsing/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" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 value->SetInteger("forty-seven", 47); | 116 value->SetInteger("forty-seven", 47); |
| 117 return value.PassAs<Value>(); | 117 return value.PassAs<Value>(); |
| 118 } | 118 } |
| 119 case Value::TYPE_LIST: { | 119 case Value::TYPE_LIST: { |
| 120 scoped_ptr<base::ListValue> value(new base::ListValue()); | 120 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 121 value->AppendInteger(22); | 121 value->AppendInteger(22); |
| 122 value->AppendInteger(47); | 122 value->AppendInteger(47); |
| 123 return value.PassAs<Value>(); | 123 return value.PassAs<Value>(); |
| 124 } | 124 } |
| 125 default: | 125 default: |
| 126 ADD_FAILURE() << "unsupported value type " << value_type; | 126 // An unknown type means a NULL value. |
|
gab
2014/06/16 15:51:41
Specifically put -1 in a constant and handle it ab
| |
| 127 return scoped_ptr<Value>(); | |
| 127 } | 128 } |
| 128 return scoped_ptr<Value>(); | |
| 129 } | 129 } |
| 130 | 130 |
| 131 base::Value::Type value_type_; | 131 base::Value::Type value_type_; |
| 132 const char* expected_value_; | 132 const char* expected_value_; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 TEST_P(PreferenceValidationDelegateValues, Value) { | 135 TEST_P(PreferenceValidationDelegateValues, Value) { |
| 136 instance_->OnAtomicPreferenceValidation(kPrefPath_, | 136 instance_->OnAtomicPreferenceValidation(kPrefPath_, |
| 137 MakeValue(value_type_).get(), | 137 MakeValue(value_type_).get(), |
| 138 PrefHashStoreTransaction::CLEARED, | 138 PrefHashStoreTransaction::CLEARED, |
| 139 TrackedPreferenceHelper::DONT_RESET); | 139 TrackedPreferenceHelper::DONT_RESET); |
| 140 safe_browsing::ClientIncidentReport_IncidentData* incident = | 140 safe_browsing::ClientIncidentReport_IncidentData* incident = |
| 141 incidents_.back(); | 141 incidents_.back(); |
| 142 EXPECT_EQ(std::string(expected_value_), | 142 if (!*expected_value_) { |
|
gab
2014/06/16 15:51:41
This is a fairly obscure way to do "check that the
| |
| 143 incident->tracked_preference().atomic_value()); | 143 EXPECT_FALSE(incident->tracked_preference().has_atomic_value()); |
| 144 } else { | |
| 145 EXPECT_EQ(std::string(expected_value_), | |
| 146 incident->tracked_preference().atomic_value()); | |
| 147 } | |
| 144 } | 148 } |
| 145 | 149 |
| 146 INSTANTIATE_TEST_CASE_P( | 150 INSTANTIATE_TEST_CASE_P( |
| 147 Values, | 151 Values, |
| 148 PreferenceValidationDelegateValues, | 152 PreferenceValidationDelegateValues, |
| 149 testing::Values( | 153 testing::Values( |
| 154 std::tr1::make_tuple(static_cast<base::Value::Type>(-1), ""), | |
|
gab
2014/06/16 15:51:41
"" and NULL value is not the same; I guess this is
| |
| 150 std::tr1::make_tuple(base::Value::TYPE_NULL, "null"), | 155 std::tr1::make_tuple(base::Value::TYPE_NULL, "null"), |
| 151 std::tr1::make_tuple(base::Value::TYPE_BOOLEAN, "false"), | 156 std::tr1::make_tuple(base::Value::TYPE_BOOLEAN, "false"), |
| 152 std::tr1::make_tuple(base::Value::TYPE_INTEGER, "47"), | 157 std::tr1::make_tuple(base::Value::TYPE_INTEGER, "47"), |
| 153 std::tr1::make_tuple(base::Value::TYPE_DOUBLE, "0.47"), | 158 std::tr1::make_tuple(base::Value::TYPE_DOUBLE, "0.47"), |
| 154 std::tr1::make_tuple(base::Value::TYPE_STRING, "i have a spleen"), | 159 std::tr1::make_tuple(base::Value::TYPE_STRING, "i have a spleen"), |
| 155 std::tr1::make_tuple(base::Value::TYPE_DICTIONARY, | 160 std::tr1::make_tuple(base::Value::TYPE_DICTIONARY, |
| 156 "{\"forty-seven\":47,\"twenty-two\":22}"), | 161 "{\"forty-seven\":47,\"twenty-two\":22}"), |
| 157 std::tr1::make_tuple(base::Value::TYPE_LIST, "[22,47]"))); | 162 std::tr1::make_tuple(base::Value::TYPE_LIST, "[22,47]"))); |
| 158 | 163 |
| 159 // Tests that no incidents are reported for relevant combinations of ValueState. | 164 // Tests that no incidents are reported for relevant combinations of ValueState. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 INSTANTIATE_TEST_CASE_P( | 254 INSTANTIATE_TEST_CASE_P( |
| 250 WithIncident, | 255 WithIncident, |
| 251 PreferenceValidationDelegateWithIncident, | 256 PreferenceValidationDelegateWithIncident, |
| 252 testing::Combine( | 257 testing::Combine( |
| 253 testing::Values(PrefHashStoreTransaction::CLEARED, | 258 testing::Values(PrefHashStoreTransaction::CLEARED, |
| 254 PrefHashStoreTransaction::WEAK_LEGACY, | 259 PrefHashStoreTransaction::WEAK_LEGACY, |
| 255 PrefHashStoreTransaction::CHANGED, | 260 PrefHashStoreTransaction::CHANGED, |
| 256 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), | 261 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), |
| 257 testing::Values(TrackedPreferenceHelper::WANTED_RESET, | 262 testing::Values(TrackedPreferenceHelper::WANTED_RESET, |
| 258 TrackedPreferenceHelper::DO_RESET))); | 263 TrackedPreferenceHelper::DO_RESET))); |
| OLD | NEW |