Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/safe_browsing/preference_validation_delegate_unittest.cc

Issue 332053005: Unit test for NULL values in preference validation delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/preference_validation_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 76 }
77 77
78 const std::string kPrefPath_; 78 const std::string kPrefPath_;
79 IncidentVector incidents_; 79 IncidentVector incidents_;
80 scoped_ptr<base::Value> null_value_; 80 scoped_ptr<base::Value> null_value_;
81 base::DictionaryValue dict_value_; 81 base::DictionaryValue dict_value_;
82 std::vector<std::string> invalid_keys_; 82 std::vector<std::string> invalid_keys_;
83 scoped_ptr<TrackedPreferenceValidationDelegate> instance_; 83 scoped_ptr<TrackedPreferenceValidationDelegate> instance_;
84 }; 84 };
85 85
86 // Tests that a NULL value results in an incident with no value.
87 TEST_F(PreferenceValidationDelegateTest, NullValue) {
88 instance_->OnAtomicPreferenceValidation(kPrefPath_,
89 NULL,
90 PrefHashStoreTransaction::CLEARED,
91 TrackedPreferenceHelper::DONT_RESET);
92 safe_browsing::ClientIncidentReport_IncidentData* incident =
93 incidents_.back();
94 EXPECT_FALSE(incident->tracked_preference().has_atomic_value());
95 EXPECT_EQ(
96 safe_browsing::
97 ClientIncidentReport_IncidentData_TrackedPreferenceIncident::CLEARED,
98 incident->tracked_preference().value_state());
99 }
100
86 // Tests that all supported value types can be stringified into an incident. The 101 // Tests that all supported value types can be stringified into an incident. The
87 // parameters for the test are the type of value to test and the expected value 102 // parameters for the test are the type of value to test and the expected value
88 // string. 103 // string.
89 class PreferenceValidationDelegateValues 104 class PreferenceValidationDelegateValues
90 : public PreferenceValidationDelegateTest, 105 : public PreferenceValidationDelegateTest,
91 public testing::WithParamInterface< 106 public testing::WithParamInterface<
92 std::tr1::tuple<base::Value::Type, const char*> > { 107 std::tr1::tuple<base::Value::Type, const char*> > {
93 protected: 108 protected:
94 virtual void SetUp() OVERRIDE { 109 virtual void SetUp() OVERRIDE {
95 PreferenceValidationDelegateTest::SetUp(); 110 PreferenceValidationDelegateTest::SetUp();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 145
131 base::Value::Type value_type_; 146 base::Value::Type value_type_;
132 const char* expected_value_; 147 const char* expected_value_;
133 }; 148 };
134 149
135 TEST_P(PreferenceValidationDelegateValues, Value) { 150 TEST_P(PreferenceValidationDelegateValues, Value) {
136 instance_->OnAtomicPreferenceValidation(kPrefPath_, 151 instance_->OnAtomicPreferenceValidation(kPrefPath_,
137 MakeValue(value_type_).get(), 152 MakeValue(value_type_).get(),
138 PrefHashStoreTransaction::CLEARED, 153 PrefHashStoreTransaction::CLEARED,
139 TrackedPreferenceHelper::DONT_RESET); 154 TrackedPreferenceHelper::DONT_RESET);
155 ASSERT_EQ(1U, incidents_.size());
140 safe_browsing::ClientIncidentReport_IncidentData* incident = 156 safe_browsing::ClientIncidentReport_IncidentData* incident =
141 incidents_.back(); 157 incidents_.back();
142 EXPECT_EQ(std::string(expected_value_), 158 EXPECT_EQ(std::string(expected_value_),
143 incident->tracked_preference().atomic_value()); 159 incident->tracked_preference().atomic_value());
144 } 160 }
145 161
146 INSTANTIATE_TEST_CASE_P( 162 INSTANTIATE_TEST_CASE_P(
147 Values, 163 Values,
148 PreferenceValidationDelegateValues, 164 PreferenceValidationDelegateValues,
149 testing::Values( 165 testing::Values(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 reset_action_ = std::tr1::get<1>(GetParam()); 223 reset_action_ = std::tr1::get<1>(GetParam());
208 } 224 }
209 225
210 PrefHashStoreTransaction::ValueState value_state_; 226 PrefHashStoreTransaction::ValueState value_state_;
211 TrackedPreferenceHelper::ResetAction reset_action_; 227 TrackedPreferenceHelper::ResetAction reset_action_;
212 }; 228 };
213 229
214 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { 230 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) {
215 instance_->OnAtomicPreferenceValidation( 231 instance_->OnAtomicPreferenceValidation(
216 kPrefPath_, null_value_.get(), value_state_, reset_action_); 232 kPrefPath_, null_value_.get(), value_state_, reset_action_);
217 EXPECT_EQ(1U, incidents_.size()); 233 ASSERT_EQ(1U, incidents_.size());
218 safe_browsing::ClientIncidentReport_IncidentData* incident = 234 safe_browsing::ClientIncidentReport_IncidentData* incident =
219 incidents_.back(); 235 incidents_.back();
220 EXPECT_TRUE(incident->has_tracked_preference()); 236 EXPECT_TRUE(incident->has_tracked_preference());
221 const safe_browsing:: 237 const safe_browsing::
222 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = 238 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident =
223 incident->tracked_preference(); 239 incident->tracked_preference();
224 EXPECT_EQ(kPrefPath_, tp_incident.path()); 240 EXPECT_EQ(kPrefPath_, tp_incident.path());
225 EXPECT_EQ(0, tp_incident.split_key_size()); 241 EXPECT_EQ(0, tp_incident.split_key_size());
226 EXPECT_TRUE(tp_incident.has_atomic_value()); 242 EXPECT_TRUE(tp_incident.has_atomic_value());
227 EXPECT_EQ(std::string("null"), tp_incident.atomic_value()); 243 EXPECT_EQ(std::string("null"), tp_incident.atomic_value());
228 EXPECT_TRUE(tp_incident.has_value_state()); 244 EXPECT_TRUE(tp_incident.has_value_state());
229 ExpectValueStatesEquate(value_state_, tp_incident.value_state()); 245 ExpectValueStatesEquate(value_state_, tp_incident.value_state());
230 } 246 }
231 247
232 TEST_P(PreferenceValidationDelegateWithIncident, Split) { 248 TEST_P(PreferenceValidationDelegateWithIncident, Split) {
233 instance_->OnSplitPreferenceValidation( 249 instance_->OnSplitPreferenceValidation(
234 kPrefPath_, &dict_value_, invalid_keys_, value_state_, reset_action_); 250 kPrefPath_, &dict_value_, invalid_keys_, value_state_, reset_action_);
235 EXPECT_EQ(1U, incidents_.size()); 251 ASSERT_EQ(1U, incidents_.size());
236 safe_browsing::ClientIncidentReport_IncidentData* incident = 252 safe_browsing::ClientIncidentReport_IncidentData* incident =
237 incidents_.back(); 253 incidents_.back();
238 EXPECT_TRUE(incident->has_tracked_preference()); 254 EXPECT_TRUE(incident->has_tracked_preference());
239 const safe_browsing:: 255 const safe_browsing::
240 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = 256 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident =
241 incident->tracked_preference(); 257 incident->tracked_preference();
242 EXPECT_EQ(kPrefPath_, tp_incident.path()); 258 EXPECT_EQ(kPrefPath_, tp_incident.path());
243 EXPECT_FALSE(tp_incident.has_atomic_value()); 259 EXPECT_FALSE(tp_incident.has_atomic_value());
244 ExpectKeysEquate(invalid_keys_, tp_incident.split_key()); 260 ExpectKeysEquate(invalid_keys_, tp_incident.split_key());
245 EXPECT_TRUE(tp_incident.has_value_state()); 261 EXPECT_TRUE(tp_incident.has_value_state());
246 ExpectValueStatesEquate(value_state_, tp_incident.value_state()); 262 ExpectValueStatesEquate(value_state_, tp_incident.value_state());
247 } 263 }
248 264
249 INSTANTIATE_TEST_CASE_P( 265 INSTANTIATE_TEST_CASE_P(
250 WithIncident, 266 WithIncident,
251 PreferenceValidationDelegateWithIncident, 267 PreferenceValidationDelegateWithIncident,
252 testing::Combine( 268 testing::Combine(
253 testing::Values(PrefHashStoreTransaction::CLEARED, 269 testing::Values(PrefHashStoreTransaction::CLEARED,
254 PrefHashStoreTransaction::WEAK_LEGACY, 270 PrefHashStoreTransaction::WEAK_LEGACY,
255 PrefHashStoreTransaction::CHANGED, 271 PrefHashStoreTransaction::CHANGED,
256 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), 272 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE),
257 testing::Values(TrackedPreferenceHelper::WANTED_RESET, 273 testing::Values(TrackedPreferenceHelper::WANTED_RESET,
258 TrackedPreferenceHelper::DO_RESET))); 274 TrackedPreferenceHelper::DO_RESET)));
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/preference_validation_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698