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

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: new test for clarity 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());
gab 2014/06/16 22:33:27 Optional: instead of returning no serialized value
grt (UTC plus 2) 2014/06/17 02:05:33 value_state() indicates that it was cleared. i've
95 }
96
86 // Tests that all supported value types can be stringified into an incident. The 97 // 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 98 // parameters for the test are the type of value to test and the expected value
88 // string. 99 // string.
89 class PreferenceValidationDelegateValues 100 class PreferenceValidationDelegateValues
90 : public PreferenceValidationDelegateTest, 101 : public PreferenceValidationDelegateTest,
91 public testing::WithParamInterface< 102 public testing::WithParamInterface<
92 std::tr1::tuple<base::Value::Type, const char*> > { 103 std::tr1::tuple<base::Value::Type, const char*> > {
93 protected: 104 protected:
94 virtual void SetUp() OVERRIDE { 105 virtual void SetUp() OVERRIDE {
95 PreferenceValidationDelegateTest::SetUp(); 106 PreferenceValidationDelegateTest::SetUp();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 140 }
130 141
131 base::Value::Type value_type_; 142 base::Value::Type value_type_;
132 const char* expected_value_; 143 const char* expected_value_;
133 }; 144 };
134 145
135 TEST_P(PreferenceValidationDelegateValues, Value) { 146 TEST_P(PreferenceValidationDelegateValues, Value) {
136 instance_->OnAtomicPreferenceValidation(kPrefPath_, 147 instance_->OnAtomicPreferenceValidation(kPrefPath_,
137 MakeValue(value_type_).get(), 148 MakeValue(value_type_).get(),
138 PrefHashStoreTransaction::CLEARED, 149 PrefHashStoreTransaction::CLEARED,
139 TrackedPreferenceHelper::DONT_RESET); 150 TrackedPreferenceHelper::DONT_RESET);
mattm 2014/06/16 19:52:15 add: ASSERT_EQ(1U, incidents_.size())
grt (UTC plus 2) 2014/06/17 02:05:33 Done.
140 safe_browsing::ClientIncidentReport_IncidentData* incident = 151 safe_browsing::ClientIncidentReport_IncidentData* incident =
141 incidents_.back(); 152 incidents_.back();
142 EXPECT_EQ(std::string(expected_value_), 153 EXPECT_EQ(std::string(expected_value_),
143 incident->tracked_preference().atomic_value()); 154 incident->tracked_preference().atomic_value());
144 } 155 }
145 156
146 INSTANTIATE_TEST_CASE_P( 157 INSTANTIATE_TEST_CASE_P(
147 Values, 158 Values,
148 PreferenceValidationDelegateValues, 159 PreferenceValidationDelegateValues,
149 testing::Values( 160 testing::Values(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 reset_action_ = std::tr1::get<1>(GetParam()); 218 reset_action_ = std::tr1::get<1>(GetParam());
208 } 219 }
209 220
210 PrefHashStoreTransaction::ValueState value_state_; 221 PrefHashStoreTransaction::ValueState value_state_;
211 TrackedPreferenceHelper::ResetAction reset_action_; 222 TrackedPreferenceHelper::ResetAction reset_action_;
212 }; 223 };
213 224
214 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) { 225 TEST_P(PreferenceValidationDelegateWithIncident, Atomic) {
215 instance_->OnAtomicPreferenceValidation( 226 instance_->OnAtomicPreferenceValidation(
216 kPrefPath_, null_value_.get(), value_state_, reset_action_); 227 kPrefPath_, null_value_.get(), value_state_, reset_action_);
217 EXPECT_EQ(1U, incidents_.size()); 228 EXPECT_EQ(1U, incidents_.size());
mattm 2014/06/16 19:52:15 Should be ASSERT_EQ (same below)
grt (UTC plus 2) 2014/06/17 02:05:32 Done.
218 safe_browsing::ClientIncidentReport_IncidentData* incident = 229 safe_browsing::ClientIncidentReport_IncidentData* incident =
219 incidents_.back(); 230 incidents_.back();
220 EXPECT_TRUE(incident->has_tracked_preference()); 231 EXPECT_TRUE(incident->has_tracked_preference());
221 const safe_browsing:: 232 const safe_browsing::
222 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident = 233 ClientIncidentReport_IncidentData_TrackedPreferenceIncident& tp_incident =
223 incident->tracked_preference(); 234 incident->tracked_preference();
224 EXPECT_EQ(kPrefPath_, tp_incident.path()); 235 EXPECT_EQ(kPrefPath_, tp_incident.path());
225 EXPECT_EQ(0, tp_incident.split_key_size()); 236 EXPECT_EQ(0, tp_incident.split_key_size());
226 EXPECT_TRUE(tp_incident.has_atomic_value()); 237 EXPECT_TRUE(tp_incident.has_atomic_value());
227 EXPECT_EQ(std::string("null"), tp_incident.atomic_value()); 238 EXPECT_EQ(std::string("null"), tp_incident.atomic_value());
(...skipping 21 matching lines...) Expand all
249 INSTANTIATE_TEST_CASE_P( 260 INSTANTIATE_TEST_CASE_P(
250 WithIncident, 261 WithIncident,
251 PreferenceValidationDelegateWithIncident, 262 PreferenceValidationDelegateWithIncident,
252 testing::Combine( 263 testing::Combine(
253 testing::Values(PrefHashStoreTransaction::CLEARED, 264 testing::Values(PrefHashStoreTransaction::CLEARED,
254 PrefHashStoreTransaction::WEAK_LEGACY, 265 PrefHashStoreTransaction::WEAK_LEGACY,
255 PrefHashStoreTransaction::CHANGED, 266 PrefHashStoreTransaction::CHANGED,
256 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE), 267 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE),
257 testing::Values(TrackedPreferenceHelper::WANTED_RESET, 268 testing::Values(TrackedPreferenceHelper::WANTED_RESET,
258 TrackedPreferenceHelper::DO_RESET))); 269 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