| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/prefs/tracked/pref_hash_filter.h" | 5 #include "components/user_prefs/tracked/pref_hash_filter.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/metrics/histogram_base.h" | 20 #include "base/metrics/histogram_base.h" |
| 21 #include "base/metrics/histogram_samples.h" | 21 #include "base/metrics/histogram_samples.h" |
| 22 #include "base/metrics/statistics_recorder.h" | 22 #include "base/metrics/statistics_recorder.h" |
| 23 #include "base/prefs/testing_pref_store.h" | 23 #include "base/prefs/testing_pref_store.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/prefs/tracked/hash_store_contents.h" | 25 #include "components/user_prefs/tracked/hash_store_contents.h" |
| 26 #include "chrome/browser/prefs/tracked/mock_validation_delegate.h" | 26 #include "components/user_prefs/tracked/mock_validation_delegate.h" |
| 27 #include "chrome/browser/prefs/tracked/pref_hash_store.h" | 27 #include "components/user_prefs/tracked/pref_hash_store.h" |
| 28 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | 28 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "components/user_prefs/tracked/pref_names.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const char kAtomicPref[] = "atomic_pref"; | 34 const char kAtomicPref[] = "atomic_pref"; |
| 35 const char kAtomicPref2[] = "atomic_pref2"; | 35 const char kAtomicPref2[] = "atomic_pref2"; |
| 36 const char kAtomicPref3[] = "pref3"; | 36 const char kAtomicPref3[] = "pref3"; |
| 37 const char kAtomicPref4[] = "pref4"; | 37 const char kAtomicPref4[] = "pref4"; |
| 38 const char kReportOnlyPref[] = "report_only"; | 38 const char kReportOnlyPref[] = "report_only"; |
| 39 const char kReportOnlySplitPref[] = "report_only_split_pref"; | 39 const char kReportOnlySplitPref[] = "report_only_split_pref"; |
| 40 const char kSplitPref[] = "split_pref"; | 40 const char kSplitPref[] = "split_pref"; |
| 41 | 41 |
| 42 const PrefHashFilter::TrackedPreferenceMetadata kTestTrackedPrefs[] = { | 42 const PrefHashFilter::TrackedPreferenceMetadata kTestTrackedPrefs[] = { |
| 43 { | 43 {0, |
| 44 0, kAtomicPref, PrefHashFilter::ENFORCE_ON_LOAD, | 44 kAtomicPref, |
| 45 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 45 PrefHashFilter::ENFORCE_ON_LOAD, |
| 46 PrefHashFilter::VALUE_PERSONAL | 46 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 47 }, | 47 PrefHashFilter::VALUE_PERSONAL}, |
| 48 { | 48 {1, |
| 49 1, kReportOnlyPref, PrefHashFilter::NO_ENFORCEMENT, | 49 kReportOnlyPref, |
| 50 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 50 PrefHashFilter::NO_ENFORCEMENT, |
| 51 PrefHashFilter::VALUE_IMPERSONAL | 51 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 52 }, | 52 PrefHashFilter::VALUE_IMPERSONAL}, |
| 53 { | 53 {2, |
| 54 2, kSplitPref, PrefHashFilter::ENFORCE_ON_LOAD, | 54 kSplitPref, |
| 55 PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 55 PrefHashFilter::ENFORCE_ON_LOAD, |
| 56 PrefHashFilter::VALUE_IMPERSONAL | 56 PrefHashFilter::TRACKING_STRATEGY_SPLIT, |
| 57 }, | 57 PrefHashFilter::VALUE_IMPERSONAL}, |
| 58 { | 58 {3, |
| 59 3, kReportOnlySplitPref, PrefHashFilter::NO_ENFORCEMENT, | 59 kReportOnlySplitPref, |
| 60 PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 60 PrefHashFilter::NO_ENFORCEMENT, |
| 61 PrefHashFilter::VALUE_IMPERSONAL | 61 PrefHashFilter::TRACKING_STRATEGY_SPLIT, |
| 62 }, | 62 PrefHashFilter::VALUE_IMPERSONAL}, |
| 63 { | 63 {4, |
| 64 4, kAtomicPref2, PrefHashFilter::ENFORCE_ON_LOAD, | 64 kAtomicPref2, |
| 65 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 65 PrefHashFilter::ENFORCE_ON_LOAD, |
| 66 PrefHashFilter::VALUE_IMPERSONAL | 66 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 67 }, | 67 PrefHashFilter::VALUE_IMPERSONAL}, |
| 68 { | 68 {5, |
| 69 5, kAtomicPref3, PrefHashFilter::ENFORCE_ON_LOAD, | 69 kAtomicPref3, |
| 70 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 70 PrefHashFilter::ENFORCE_ON_LOAD, |
| 71 PrefHashFilter::VALUE_IMPERSONAL | 71 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 72 }, | 72 PrefHashFilter::VALUE_IMPERSONAL}, |
| 73 { | 73 {6, |
| 74 6, kAtomicPref4, PrefHashFilter::ENFORCE_ON_LOAD, | 74 kAtomicPref4, |
| 75 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 75 PrefHashFilter::ENFORCE_ON_LOAD, |
| 76 PrefHashFilter::VALUE_IMPERSONAL | 76 PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 77 }, | 77 PrefHashFilter::VALUE_IMPERSONAL}, |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 // A PrefHashStore that allows simulation of CheckValue results and captures | 82 // A PrefHashStore that allows simulation of CheckValue results and captures |
| 83 // checked and stored values. | 83 // checked and stored values. |
| 84 class MockPrefHashStore : public PrefHashStore { | 84 class MockPrefHashStore : public PrefHashStore { |
| 85 public: | 85 public: |
| 86 typedef std::pair<const void*, PrefHashFilter::PrefTrackingStrategy> | 86 typedef std::pair<const void*, PrefHashFilter::PrefTrackingStrategy> |
| 87 ValuePtrStrategyPair; | 87 ValuePtrStrategyPair; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 115 // Sets the value that will be returned from | 115 // Sets the value that will be returned from |
| 116 // PrefHashStoreTransaction::IsSuperMACValid(). | 116 // PrefHashStoreTransaction::IsSuperMACValid(). |
| 117 void set_is_super_mac_valid_result(bool result) { | 117 void set_is_super_mac_valid_result(bool result) { |
| 118 is_super_mac_valid_result_ = result; | 118 is_super_mac_valid_result_ = result; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Returns the number of transactions that were performed. | 121 // Returns the number of transactions that were performed. |
| 122 size_t transactions_performed() { return transactions_performed_; } | 122 size_t transactions_performed() { return transactions_performed_; } |
| 123 | 123 |
| 124 // Returns the number of paths checked. | 124 // Returns the number of paths checked. |
| 125 size_t checked_paths_count() const { | 125 size_t checked_paths_count() const { return checked_values_.size(); } |
| 126 return checked_values_.size(); | |
| 127 } | |
| 128 | 126 |
| 129 // Returns the number of paths stored. | 127 // Returns the number of paths stored. |
| 130 size_t stored_paths_count() const { | 128 size_t stored_paths_count() const { return stored_values_.size(); } |
| 131 return stored_values_.size(); | |
| 132 } | |
| 133 | 129 |
| 134 // Returns the pointer value and strategy that was passed to | 130 // Returns the pointer value and strategy that was passed to |
| 135 // |CheckHash/CheckSplitHash| for |path|. The returned pointer could since | 131 // |CheckHash/CheckSplitHash| for |path|. The returned pointer could since |
| 136 // have been freed and is thus not safe to dereference. | 132 // have been freed and is thus not safe to dereference. |
| 137 ValuePtrStrategyPair checked_value(const std::string& path) const { | 133 ValuePtrStrategyPair checked_value(const std::string& path) const { |
| 138 std::map<std::string, ValuePtrStrategyPair>::const_iterator value = | 134 std::map<std::string, ValuePtrStrategyPair>::const_iterator value = |
| 139 checked_values_.find(path); | 135 checked_values_.find(path); |
| 140 if (value != checked_values_.end()) | 136 if (value != checked_values_.end()) |
| 141 return value->second; | 137 return value->second; |
| 142 return std::make_pair( | 138 return std::make_pair( |
| 143 reinterpret_cast<void*>(0xBAD), | 139 reinterpret_cast<void*>(0xBAD), |
| 144 static_cast<PrefHashFilter::PrefTrackingStrategy>(-1)); | 140 static_cast<PrefHashFilter::PrefTrackingStrategy>(-1)); |
| 145 } | 141 } |
| 146 | 142 |
| 147 // Returns the pointer value that was passed to |StoreHash/StoreSplitHash| for | 143 // Returns the pointer value that was passed to |StoreHash/StoreSplitHash| for |
| 148 // |path|. The returned pointer could since have been freed and is thus not | 144 // |path|. The returned pointer could since have been freed and is thus not |
| 149 // safe to dereference. | 145 // safe to dereference. |
| 150 ValuePtrStrategyPair stored_value(const std::string& path) const { | 146 ValuePtrStrategyPair stored_value(const std::string& path) const { |
| 151 std::map<std::string, ValuePtrStrategyPair>::const_iterator value = | 147 std::map<std::string, ValuePtrStrategyPair>::const_iterator value = |
| 152 stored_values_.find(path); | 148 stored_values_.find(path); |
| 153 if (value != stored_values_.end()) | 149 if (value != stored_values_.end()) |
| 154 return value->second; | 150 return value->second; |
| 155 return std::make_pair( | 151 return std::make_pair( |
| 156 reinterpret_cast<void*>(0xBAD), | 152 reinterpret_cast<void*>(0xBAD), |
| 157 static_cast<PrefHashFilter::PrefTrackingStrategy>(-1)); | 153 static_cast<PrefHashFilter::PrefTrackingStrategy>(-1)); |
| 158 } | 154 } |
| 159 | 155 |
| 160 // PrefHashStore implementation. | 156 // PrefHashStore implementation. |
| 161 scoped_ptr<PrefHashStoreTransaction> BeginTransaction( | 157 scoped_ptr<PrefHashStoreTransaction> BeginTransaction( |
| 162 scoped_ptr<HashStoreContents> storage) override; | 158 scoped_ptr<HashStoreContents> storage) override; |
| 163 | 159 |
| 164 private: | 160 private: |
| 165 // A MockPrefHashStoreTransaction is handed to the caller on | 161 // A MockPrefHashStoreTransaction is handed to the caller on |
| 166 // MockPrefHashStore::BeginTransaction(). It then stores state in its | 162 // MockPrefHashStore::BeginTransaction(). It then stores state in its |
| 167 // underlying MockPrefHashStore about calls it receives from that same caller | 163 // underlying MockPrefHashStore about calls it receives from that same caller |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 const std::string& path, | 201 const std::string& path, |
| 206 const base::Value* value, | 202 const base::Value* value, |
| 207 PrefHashFilter::PrefTrackingStrategy strategy); | 203 PrefHashFilter::PrefTrackingStrategy strategy); |
| 208 | 204 |
| 209 // Records a call to this mock's StoreHash/StoreSplitHash methods. | 205 // Records a call to this mock's StoreHash/StoreSplitHash methods. |
| 210 void RecordStoreHash(const std::string& path, | 206 void RecordStoreHash(const std::string& path, |
| 211 const base::Value* new_value, | 207 const base::Value* new_value, |
| 212 PrefHashFilter::PrefTrackingStrategy strategy); | 208 PrefHashFilter::PrefTrackingStrategy strategy); |
| 213 | 209 |
| 214 std::map<std::string, PrefHashStoreTransaction::ValueState> check_results_; | 210 std::map<std::string, PrefHashStoreTransaction::ValueState> check_results_; |
| 215 std::map<std::string, std::vector<std::string> > invalid_keys_results_; | 211 std::map<std::string, std::vector<std::string>> invalid_keys_results_; |
| 216 | 212 |
| 217 bool stamp_super_mac_result_; | 213 bool stamp_super_mac_result_; |
| 218 bool is_super_mac_valid_result_; | 214 bool is_super_mac_valid_result_; |
| 219 | 215 |
| 220 std::map<std::string, ValuePtrStrategyPair> checked_values_; | 216 std::map<std::string, ValuePtrStrategyPair> checked_values_; |
| 221 std::map<std::string, ValuePtrStrategyPair> stored_values_; | 217 std::map<std::string, ValuePtrStrategyPair> stored_values_; |
| 222 | 218 |
| 223 // Number of transactions that were performed via this MockPrefHashStore. | 219 // Number of transactions that were performed via this MockPrefHashStore. |
| 224 size_t transactions_performed_; | 220 size_t transactions_performed_; |
| 225 | 221 |
| 226 // Whether a transaction is currently active (only one transaction should be | 222 // Whether a transaction is currently active (only one transaction should be |
| 227 // active at a time). | 223 // active at a time). |
| 228 bool transaction_active_; | 224 bool transaction_active_; |
| 229 | 225 |
| 230 DISALLOW_COPY_AND_ASSIGN(MockPrefHashStore); | 226 DISALLOW_COPY_AND_ASSIGN(MockPrefHashStore); |
| 231 }; | 227 }; |
| 232 | 228 |
| 233 void MockPrefHashStore::SetCheckResult( | 229 void MockPrefHashStore::SetCheckResult( |
| 234 const std::string& path, PrefHashStoreTransaction::ValueState result) { | 230 const std::string& path, |
| 231 PrefHashStoreTransaction::ValueState result) { |
| 235 check_results_.insert(std::make_pair(path, result)); | 232 check_results_.insert(std::make_pair(path, result)); |
| 236 } | 233 } |
| 237 | 234 |
| 238 void MockPrefHashStore::SetInvalidKeysResult( | 235 void MockPrefHashStore::SetInvalidKeysResult( |
| 239 const std::string& path, | 236 const std::string& path, |
| 240 const std::vector<std::string>& invalid_keys_result) { | 237 const std::vector<std::string>& invalid_keys_result) { |
| 241 // Ensure |check_results_| has a CHANGED entry for |path|. | 238 // Ensure |check_results_| has a CHANGED entry for |path|. |
| 242 std::map<std::string, | 239 std::map<std::string, PrefHashStoreTransaction::ValueState>::const_iterator |
| 243 PrefHashStoreTransaction::ValueState>::const_iterator result = | 240 result = check_results_.find(path); |
| 244 check_results_.find(path); | |
| 245 ASSERT_TRUE(result != check_results_.end()); | 241 ASSERT_TRUE(result != check_results_.end()); |
| 246 ASSERT_EQ(PrefHashStoreTransaction::CHANGED, result->second); | 242 ASSERT_EQ(PrefHashStoreTransaction::CHANGED, result->second); |
| 247 | 243 |
| 248 invalid_keys_results_.insert(std::make_pair(path, invalid_keys_result)); | 244 invalid_keys_results_.insert(std::make_pair(path, invalid_keys_result)); |
| 249 } | 245 } |
| 250 | 246 |
| 251 scoped_ptr<PrefHashStoreTransaction> MockPrefHashStore::BeginTransaction( | 247 scoped_ptr<PrefHashStoreTransaction> MockPrefHashStore::BeginTransaction( |
| 252 scoped_ptr<HashStoreContents> storage) { | 248 scoped_ptr<HashStoreContents> storage) { |
| 253 EXPECT_FALSE(transaction_active_); | 249 EXPECT_FALSE(transaction_active_); |
| 254 return scoped_ptr<PrefHashStoreTransaction>( | 250 return scoped_ptr<PrefHashStoreTransaction>( |
| 255 new MockPrefHashStoreTransaction(this)); | 251 new MockPrefHashStoreTransaction(this)); |
| 256 } | 252 } |
| 257 | 253 |
| 258 PrefHashStoreTransaction::ValueState MockPrefHashStore::RecordCheckValue( | 254 PrefHashStoreTransaction::ValueState MockPrefHashStore::RecordCheckValue( |
| 259 const std::string& path, | 255 const std::string& path, |
| 260 const base::Value* value, | 256 const base::Value* value, |
| 261 PrefHashFilter::PrefTrackingStrategy strategy) { | 257 PrefHashFilter::PrefTrackingStrategy strategy) { |
| 262 // Record that |path| was checked and validate that it wasn't previously | 258 // Record that |path| was checked and validate that it wasn't previously |
| 263 // checked. | 259 // checked. |
| 264 EXPECT_TRUE(checked_values_.insert( | 260 EXPECT_TRUE(checked_values_.insert(std::make_pair( |
| 265 std::make_pair(path, std::make_pair(value, strategy))).second); | 261 path, std::make_pair(value, strategy))) |
| 266 std::map<std::string, | 262 .second); |
| 267 PrefHashStoreTransaction::ValueState>::const_iterator result = | 263 std::map<std::string, PrefHashStoreTransaction::ValueState>::const_iterator |
| 268 check_results_.find(path); | 264 result = check_results_.find(path); |
| 269 if (result != check_results_.end()) | 265 if (result != check_results_.end()) |
| 270 return result->second; | 266 return result->second; |
| 271 return PrefHashStoreTransaction::UNCHANGED; | 267 return PrefHashStoreTransaction::UNCHANGED; |
| 272 } | 268 } |
| 273 | 269 |
| 274 void MockPrefHashStore::RecordStoreHash( | 270 void MockPrefHashStore::RecordStoreHash( |
| 275 const std::string& path, | 271 const std::string& path, |
| 276 const base::Value* new_value, | 272 const base::Value* new_value, |
| 277 PrefHashFilter::PrefTrackingStrategy strategy) { | 273 PrefHashFilter::PrefTrackingStrategy strategy) { |
| 278 EXPECT_TRUE(stored_values_.insert( | 274 EXPECT_TRUE( |
| 279 std::make_pair(path, std::make_pair(new_value, strategy))).second); | 275 stored_values_.insert(std::make_pair(path, |
| 276 std::make_pair(new_value, strategy))) |
| 277 .second); |
| 280 } | 278 } |
| 281 | 279 |
| 282 PrefHashStoreTransaction::ValueState | 280 PrefHashStoreTransaction::ValueState |
| 283 MockPrefHashStore::MockPrefHashStoreTransaction::CheckValue( | 281 MockPrefHashStore::MockPrefHashStoreTransaction::CheckValue( |
| 284 const std::string& path, const base::Value* value) const { | 282 const std::string& path, |
| 283 const base::Value* value) const { |
| 285 return outer_->RecordCheckValue(path, value, | 284 return outer_->RecordCheckValue(path, value, |
| 286 PrefHashFilter::TRACKING_STRATEGY_ATOMIC); | 285 PrefHashFilter::TRACKING_STRATEGY_ATOMIC); |
| 287 } | 286 } |
| 288 | 287 |
| 289 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreHash( | 288 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreHash( |
| 290 const std::string& path, | 289 const std::string& path, |
| 291 const base::Value* new_value) { | 290 const base::Value* new_value) { |
| 292 outer_->RecordStoreHash(path, new_value, | 291 outer_->RecordStoreHash(path, new_value, |
| 293 PrefHashFilter::TRACKING_STRATEGY_ATOMIC); | 292 PrefHashFilter::TRACKING_STRATEGY_ATOMIC); |
| 294 } | 293 } |
| 295 | 294 |
| 296 PrefHashStoreTransaction::ValueState | 295 PrefHashStoreTransaction::ValueState |
| 297 MockPrefHashStore::MockPrefHashStoreTransaction::CheckSplitValue( | 296 MockPrefHashStore::MockPrefHashStoreTransaction::CheckSplitValue( |
| 298 const std::string& path, | 297 const std::string& path, |
| 299 const base::DictionaryValue* initial_split_value, | 298 const base::DictionaryValue* initial_split_value, |
| 300 std::vector<std::string>* invalid_keys) const { | 299 std::vector<std::string>* invalid_keys) const { |
| 301 EXPECT_TRUE(invalid_keys && invalid_keys->empty()); | 300 EXPECT_TRUE(invalid_keys && invalid_keys->empty()); |
| 302 | 301 |
| 303 std::map<std::string, std::vector<std::string> >::const_iterator | 302 std::map<std::string, std::vector<std::string>>::const_iterator |
| 304 invalid_keys_result = outer_->invalid_keys_results_.find(path); | 303 invalid_keys_result = outer_->invalid_keys_results_.find(path); |
| 305 if (invalid_keys_result != outer_->invalid_keys_results_.end()) { | 304 if (invalid_keys_result != outer_->invalid_keys_results_.end()) { |
| 306 invalid_keys->insert(invalid_keys->begin(), | 305 invalid_keys->insert(invalid_keys->begin(), |
| 307 invalid_keys_result->second.begin(), | 306 invalid_keys_result->second.begin(), |
| 308 invalid_keys_result->second.end()); | 307 invalid_keys_result->second.end()); |
| 309 } | 308 } |
| 310 | 309 |
| 311 return outer_->RecordCheckValue(path, initial_split_value, | 310 return outer_->RecordCheckValue(path, initial_split_value, |
| 312 PrefHashFilter::TRACKING_STRATEGY_SPLIT); | 311 PrefHashFilter::TRACKING_STRATEGY_SPLIT); |
| 313 } | 312 } |
| 314 | 313 |
| 315 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreSplitHash( | 314 void MockPrefHashStore::MockPrefHashStoreTransaction::StoreSplitHash( |
| 316 const std::string& path, | 315 const std::string& path, |
| 317 const base::DictionaryValue* new_value) { | 316 const base::DictionaryValue* new_value) { |
| 318 outer_->RecordStoreHash(path, new_value, | 317 outer_->RecordStoreHash(path, new_value, |
| 319 PrefHashFilter::TRACKING_STRATEGY_SPLIT); | 318 PrefHashFilter::TRACKING_STRATEGY_SPLIT); |
| 320 } | 319 } |
| 321 | 320 |
| 322 bool MockPrefHashStore::MockPrefHashStoreTransaction::HasHash( | 321 bool MockPrefHashStore::MockPrefHashStoreTransaction::HasHash( |
| 323 const std::string& path) const { | 322 const std::string& path) const { |
| 324 ADD_FAILURE() << "Unexpected call."; | 323 ADD_FAILURE() << "Unexpected call."; |
| 325 return false; | 324 return false; |
| 326 } | 325 } |
| 327 | 326 |
| 328 void MockPrefHashStore::MockPrefHashStoreTransaction::ImportHash( | 327 void MockPrefHashStore::MockPrefHashStoreTransaction::ImportHash( |
| 329 const std::string& path, | 328 const std::string& path, |
| 330 const base::Value* hash) { | 329 const base::Value* hash) { |
| 331 ADD_FAILURE() << "Unexpected call."; | 330 ADD_FAILURE() << "Unexpected call."; |
| 332 } | 331 } |
| 333 | 332 |
| 334 void MockPrefHashStore::MockPrefHashStoreTransaction::ClearHash( | 333 void MockPrefHashStore::MockPrefHashStoreTransaction::ClearHash( |
| 335 const std::string& path) { | 334 const std::string& path) { |
| 336 // Allow this to be called by PrefHashFilter's deprecated tracked prefs | 335 // Allow this to be called by PrefHashFilter's deprecated tracked prefs |
| 337 // cleanup tasks. | 336 // cleanup tasks. |
| 338 } | 337 } |
| 339 | 338 |
| 340 bool MockPrefHashStore::MockPrefHashStoreTransaction::IsSuperMACValid() const { | 339 bool MockPrefHashStore::MockPrefHashStoreTransaction::IsSuperMACValid() const { |
| 341 return outer_->is_super_mac_valid_result_; | 340 return outer_->is_super_mac_valid_result_; |
| 342 } | 341 } |
| 343 | 342 |
| 344 bool MockPrefHashStore::MockPrefHashStoreTransaction::StampSuperMac() { | 343 bool MockPrefHashStore::MockPrefHashStoreTransaction::StampSuperMac() { |
| 345 return outer_->stamp_super_mac_result_; | 344 return outer_->stamp_super_mac_result_; |
| 346 } | 345 } |
| 347 | 346 |
| 348 std::vector<PrefHashFilter::TrackedPreferenceMetadata> GetConfiguration( | 347 std::vector<PrefHashFilter::TrackedPreferenceMetadata> GetConfiguration( |
| 349 PrefHashFilter::EnforcementLevel max_enforcement_level) { | 348 PrefHashFilter::EnforcementLevel max_enforcement_level) { |
| 350 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration( | 349 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration( |
| 351 kTestTrackedPrefs, kTestTrackedPrefs + arraysize(kTestTrackedPrefs)); | 350 kTestTrackedPrefs, kTestTrackedPrefs + arraysize(kTestTrackedPrefs)); |
| 352 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = | 351 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = |
| 353 configuration.begin(); | 352 configuration.begin(); |
| 354 it != configuration.end(); | 353 it != configuration.end(); ++it) { |
| 355 ++it) { | |
| 356 if (it->enforcement_level > max_enforcement_level) | 354 if (it->enforcement_level > max_enforcement_level) |
| 357 it->enforcement_level = max_enforcement_level; | 355 it->enforcement_level = max_enforcement_level; |
| 358 } | 356 } |
| 359 return configuration; | 357 return configuration; |
| 360 } | 358 } |
| 361 | 359 |
| 362 class PrefHashFilterTest | 360 class PrefHashFilterTest |
| 363 : public testing::TestWithParam<PrefHashFilter::EnforcementLevel> { | 361 : public testing::TestWithParam<PrefHashFilter::EnforcementLevel> { |
| 364 public: | 362 public: |
| 365 PrefHashFilterTest() : mock_pref_hash_store_(NULL), | 363 PrefHashFilterTest() |
| 366 pref_store_contents_(new base::DictionaryValue), | 364 : mock_pref_hash_store_(NULL), |
| 367 reset_recorded_(false) {} | 365 pref_store_contents_(new base::DictionaryValue), |
| 366 reset_recorded_(false) {} |
| 368 | 367 |
| 369 void SetUp() override { | 368 void SetUp() override { |
| 370 base::StatisticsRecorder::Initialize(); | 369 base::StatisticsRecorder::Initialize(); |
| 371 Reset(); | 370 Reset(); |
| 372 } | 371 } |
| 373 | 372 |
| 374 protected: | 373 protected: |
| 375 // Reset the PrefHashFilter instance. | 374 // Reset the PrefHashFilter instance. |
| 376 void Reset() { | 375 void Reset() { |
| 377 // Construct a PrefHashFilter and MockPrefHashStore for the test. | 376 // Construct a PrefHashFilter and MockPrefHashStore for the test. |
| 378 InitializePrefHashFilter(GetConfiguration(GetParam())); | 377 InitializePrefHashFilter(GetConfiguration(GetParam())); |
| 379 } | 378 } |
| 380 | 379 |
| 381 // Initializes |pref_hash_filter_| with a PrefHashFilter that uses a | 380 // Initializes |pref_hash_filter_| with a PrefHashFilter that uses a |
| 382 // MockPrefHashStore. The raw pointer to the MockPrefHashStore (owned by the | 381 // MockPrefHashStore. The raw pointer to the MockPrefHashStore (owned by the |
| 383 // PrefHashFilter) is stored in |mock_pref_hash_store_|. | 382 // PrefHashFilter) is stored in |mock_pref_hash_store_|. |
| 384 void InitializePrefHashFilter(const std::vector< | 383 void InitializePrefHashFilter(const std::vector< |
| 385 PrefHashFilter::TrackedPreferenceMetadata>& configuration) { | 384 PrefHashFilter::TrackedPreferenceMetadata>& configuration) { |
| 386 scoped_ptr<MockPrefHashStore> temp_mock_pref_hash_store( | 385 scoped_ptr<MockPrefHashStore> temp_mock_pref_hash_store( |
| 387 new MockPrefHashStore); | 386 new MockPrefHashStore); |
| 388 mock_pref_hash_store_ = temp_mock_pref_hash_store.get(); | 387 mock_pref_hash_store_ = temp_mock_pref_hash_store.get(); |
| 389 pref_hash_filter_.reset(new PrefHashFilter( | 388 pref_hash_filter_.reset(new PrefHashFilter( |
| 390 temp_mock_pref_hash_store.Pass(), | 389 temp_mock_pref_hash_store.Pass(), configuration, |
| 391 configuration, | |
| 392 base::Bind(&PrefHashFilterTest::RecordReset, base::Unretained(this)), | 390 base::Bind(&PrefHashFilterTest::RecordReset, base::Unretained(this)), |
| 393 &mock_validation_delegate_, | 391 &mock_validation_delegate_, arraysize(kTestTrackedPrefs), true)); |
| 394 arraysize(kTestTrackedPrefs), | |
| 395 true)); | |
| 396 } | 392 } |
| 397 | 393 |
| 398 // Verifies whether a reset was reported by the PrefHashFiler. Also verifies | 394 // Verifies whether a reset was reported by the PrefHashFiler. Also verifies |
| 399 // that kPreferenceResetTime was set (or not) accordingly. | 395 // that kPreferenceResetTime was set (or not) accordingly. |
| 400 void VerifyRecordedReset(bool reset_expected) { | 396 void VerifyRecordedReset(bool reset_expected) { |
| 401 EXPECT_EQ(reset_expected, reset_recorded_); | 397 EXPECT_EQ(reset_expected, reset_recorded_); |
| 402 EXPECT_EQ(reset_expected, | 398 EXPECT_EQ(reset_expected, |
| 403 pref_store_contents_->Get(prefs::kPreferenceResetTime, NULL)); | 399 pref_store_contents_->Get( |
| 400 user_prefs::kPreferenceResetTime, NULL)); |
| 404 } | 401 } |
| 405 | 402 |
| 406 // Calls FilterOnLoad() on |pref_hash_Filter_|. |pref_store_contents_| is | 403 // Calls FilterOnLoad() on |pref_hash_Filter_|. |pref_store_contents_| is |
| 407 // handed off, but should be given back to us synchronously through | 404 // handed off, but should be given back to us synchronously through |
| 408 // GetPrefsBack() as there is no FilterOnLoadInterceptor installed on | 405 // GetPrefsBack() as there is no FilterOnLoadInterceptor installed on |
| 409 // |pref_hash_filter_|. | 406 // |pref_hash_filter_|. |
| 410 void DoFilterOnLoad(bool expect_prefs_modifications) { | 407 void DoFilterOnLoad(bool expect_prefs_modifications) { |
| 411 pref_hash_filter_->FilterOnLoad( | 408 pref_hash_filter_->FilterOnLoad( |
| 412 base::Bind(&PrefHashFilterTest::GetPrefsBack, base::Unretained(this), | 409 base::Bind(&PrefHashFilterTest::GetPrefsBack, base::Unretained(this), |
| 413 expect_prefs_modifications), | 410 expect_prefs_modifications), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 TEST_P(PrefHashFilterTest, EmptyAndUnchanged) { | 442 TEST_P(PrefHashFilterTest, EmptyAndUnchanged) { |
| 446 DoFilterOnLoad(false); | 443 DoFilterOnLoad(false); |
| 447 // All paths checked. | 444 // All paths checked. |
| 448 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 445 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 449 mock_pref_hash_store_->checked_paths_count()); | 446 mock_pref_hash_store_->checked_paths_count()); |
| 450 // No paths stored, since they all return |UNCHANGED|. | 447 // No paths stored, since they all return |UNCHANGED|. |
| 451 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 448 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
| 452 // Since there was nothing in |pref_store_contents_| the checked value should | 449 // Since there was nothing in |pref_store_contents_| the checked value should |
| 453 // have been NULL for all tracked preferences. | 450 // have been NULL for all tracked preferences. |
| 454 for (size_t i = 0; i < arraysize(kTestTrackedPrefs); ++i) { | 451 for (size_t i = 0; i < arraysize(kTestTrackedPrefs); ++i) { |
| 455 ASSERT_EQ(NULL, mock_pref_hash_store_->checked_value( | 452 ASSERT_EQ( |
| 456 kTestTrackedPrefs[i].name).first); | 453 NULL, |
| 454 mock_pref_hash_store_->checked_value(kTestTrackedPrefs[i].name).first); |
| 457 } | 455 } |
| 458 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 456 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 459 VerifyRecordedReset(false); | 457 VerifyRecordedReset(false); |
| 460 | 458 |
| 461 // Delegate saw all paths, and all unchanged. | 459 // Delegate saw all paths, and all unchanged. |
| 462 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 460 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 463 mock_validation_delegate_.recorded_validations_count()); | 461 mock_validation_delegate_.recorded_validations_count()); |
| 464 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 462 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 465 mock_validation_delegate_.CountValidationsOfState( | 463 mock_validation_delegate_.CountValidationsOfState( |
| 466 PrefHashStoreTransaction::UNCHANGED)); | 464 PrefHashStoreTransaction::UNCHANGED)); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 root_dict.Set(kSplitPref, dict_value); | 539 root_dict.Set(kSplitPref, dict_value); |
| 542 | 540 |
| 543 // No path should be stored on FilterUpdate. | 541 // No path should be stored on FilterUpdate. |
| 544 pref_hash_filter_->FilterUpdate(kSplitPref); | 542 pref_hash_filter_->FilterUpdate(kSplitPref); |
| 545 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); | 543 ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count()); |
| 546 | 544 |
| 547 // One path should be stored on FilterSerializeData. | 545 // One path should be stored on FilterSerializeData. |
| 548 pref_hash_filter_->FilterSerializeData(&root_dict); | 546 pref_hash_filter_->FilterSerializeData(&root_dict); |
| 549 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); | 547 ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count()); |
| 550 MockPrefHashStore::ValuePtrStrategyPair stored_value = | 548 MockPrefHashStore::ValuePtrStrategyPair stored_value = |
| 551 mock_pref_hash_store_->stored_value(kSplitPref); | 549 mock_pref_hash_store_->stored_value(kSplitPref); |
| 552 ASSERT_EQ(dict_value, stored_value.first); | 550 ASSERT_EQ(dict_value, stored_value.first); |
| 553 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value.second); | 551 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value.second); |
| 554 | 552 |
| 555 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 553 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 556 VerifyRecordedReset(false); | 554 VerifyRecordedReset(false); |
| 557 } | 555 } |
| 558 | 556 |
| 559 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { | 557 TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { |
| 560 base::DictionaryValue root_dict; | 558 base::DictionaryValue root_dict; |
| 561 root_dict.Set("untracked", new base::StringValue("some value")); | 559 root_dict.Set("untracked", new base::StringValue("some value")); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 stored_value_atomic1.second); | 608 stored_value_atomic1.second); |
| 611 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 609 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 612 | 610 |
| 613 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic3 = | 611 MockPrefHashStore::ValuePtrStrategyPair stored_value_atomic3 = |
| 614 mock_pref_hash_store_->stored_value(kAtomicPref3); | 612 mock_pref_hash_store_->stored_value(kAtomicPref3); |
| 615 ASSERT_EQ(int_value5, stored_value_atomic3.first); | 613 ASSERT_EQ(int_value5, stored_value_atomic3.first); |
| 616 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 614 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 617 stored_value_atomic3.second); | 615 stored_value_atomic3.second); |
| 618 | 616 |
| 619 MockPrefHashStore::ValuePtrStrategyPair stored_value_split = | 617 MockPrefHashStore::ValuePtrStrategyPair stored_value_split = |
| 620 mock_pref_hash_store_->stored_value(kSplitPref); | 618 mock_pref_hash_store_->stored_value(kSplitPref); |
| 621 ASSERT_EQ(dict_value, stored_value_split.first); | 619 ASSERT_EQ(dict_value, stored_value_split.first); |
| 622 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value_split.second); | 620 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value_split.second); |
| 623 } | 621 } |
| 624 | 622 |
| 625 TEST_P(PrefHashFilterTest, UnknownNullValue) { | 623 TEST_P(PrefHashFilterTest, UnknownNullValue) { |
| 626 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 624 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 627 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 625 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 628 // NULL values are always trusted by the PrefHashStore. | 626 // NULL values are always trusted by the PrefHashStore. |
| 629 mock_pref_hash_store_->SetCheckResult( | 627 mock_pref_hash_store_->SetCheckResult( |
| 630 kAtomicPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); | 628 kAtomicPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); |
| 631 mock_pref_hash_store_->SetCheckResult( | 629 mock_pref_hash_store_->SetCheckResult( |
| 632 kSplitPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); | 630 kSplitPref, PrefHashStoreTransaction::TRUSTED_NULL_VALUE); |
| 633 DoFilterOnLoad(false); | 631 DoFilterOnLoad(false); |
| 634 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 632 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 635 mock_pref_hash_store_->checked_paths_count()); | 633 mock_pref_hash_store_->checked_paths_count()); |
| 636 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 634 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 637 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 635 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 638 | 636 |
| 639 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 637 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 640 mock_pref_hash_store_->stored_value(kAtomicPref); | 638 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 641 ASSERT_EQ(NULL, stored_atomic_value.first); | 639 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 642 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 640 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 643 stored_atomic_value.second); | 641 stored_atomic_value.second); |
| 644 | 642 |
| 645 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 643 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 646 mock_pref_hash_store_->stored_value(kSplitPref); | 644 mock_pref_hash_store_->stored_value(kSplitPref); |
| 647 ASSERT_EQ(NULL, stored_split_value.first); | 645 ASSERT_EQ(NULL, stored_split_value.first); |
| 648 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 646 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); |
| 649 stored_split_value.second); | |
| 650 | 647 |
| 651 // Delegate saw all prefs, two of which had the expected value_state. | 648 // Delegate saw all prefs, two of which had the expected value_state. |
| 652 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 649 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 653 mock_validation_delegate_.recorded_validations_count()); | 650 mock_validation_delegate_.recorded_validations_count()); |
| 654 ASSERT_EQ(2u, | 651 ASSERT_EQ(2u, mock_validation_delegate_.CountValidationsOfState( |
| 655 mock_validation_delegate_.CountValidationsOfState( | 652 PrefHashStoreTransaction::TRUSTED_NULL_VALUE)); |
| 656 PrefHashStoreTransaction::TRUSTED_NULL_VALUE)); | |
| 657 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 653 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 658 mock_validation_delegate_.CountValidationsOfState( | 654 mock_validation_delegate_.CountValidationsOfState( |
| 659 PrefHashStoreTransaction::UNCHANGED)); | 655 PrefHashStoreTransaction::UNCHANGED)); |
| 660 | 656 |
| 661 const MockValidationDelegate::ValidationEvent* validated_split_pref = | 657 const MockValidationDelegate::ValidationEvent* validated_split_pref = |
| 662 mock_validation_delegate_.GetEventForPath(kSplitPref); | 658 mock_validation_delegate_.GetEventForPath(kSplitPref); |
| 663 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 659 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, |
| 664 validated_split_pref->strategy); | 660 validated_split_pref->strategy); |
| 665 ASSERT_FALSE(validated_split_pref->is_personal); | 661 ASSERT_FALSE(validated_split_pref->is_personal); |
| 666 const MockValidationDelegate::ValidationEvent* validated_atomic_pref = | 662 const MockValidationDelegate::ValidationEvent* validated_atomic_pref = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 690 // If we are enforcing, expect this to report changes. | 686 // If we are enforcing, expect this to report changes. |
| 691 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); | 687 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); |
| 692 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 688 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 693 mock_pref_hash_store_->checked_paths_count()); | 689 mock_pref_hash_store_->checked_paths_count()); |
| 694 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 690 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 695 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 691 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 696 | 692 |
| 697 // Delegate saw all prefs, two of which had the expected value_state. | 693 // Delegate saw all prefs, two of which had the expected value_state. |
| 698 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 694 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 699 mock_validation_delegate_.recorded_validations_count()); | 695 mock_validation_delegate_.recorded_validations_count()); |
| 700 ASSERT_EQ(2u, | 696 ASSERT_EQ(2u, mock_validation_delegate_.CountValidationsOfState( |
| 701 mock_validation_delegate_.CountValidationsOfState( | 697 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE)); |
| 702 PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE)); | |
| 703 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 698 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 704 mock_validation_delegate_.CountValidationsOfState( | 699 mock_validation_delegate_.CountValidationsOfState( |
| 705 PrefHashStoreTransaction::UNCHANGED)); | 700 PrefHashStoreTransaction::UNCHANGED)); |
| 706 | 701 |
| 707 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 702 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 708 mock_pref_hash_store_->stored_value(kAtomicPref); | 703 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 709 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 704 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 710 mock_pref_hash_store_->stored_value(kSplitPref); | 705 mock_pref_hash_store_->stored_value(kSplitPref); |
| 711 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 706 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 712 stored_atomic_value.second); | 707 stored_atomic_value.second); |
| 713 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 708 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); |
| 714 stored_split_value.second); | |
| 715 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { | 709 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { |
| 716 // Ensure the prefs were cleared and the hashes for NULL were restored if | 710 // Ensure the prefs were cleared and the hashes for NULL were restored if |
| 717 // the current enforcement level denies seeding. | 711 // the current enforcement level denies seeding. |
| 718 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 712 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 719 ASSERT_EQ(NULL, stored_atomic_value.first); | 713 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 720 | 714 |
| 721 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 715 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 722 ASSERT_EQ(NULL, stored_split_value.first); | 716 ASSERT_EQ(NULL, stored_split_value.first); |
| 723 | 717 |
| 724 VerifyRecordedReset(true); | 718 VerifyRecordedReset(true); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 kSplitPref, PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE); | 752 kSplitPref, PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE); |
| 759 DoFilterOnLoad(false); | 753 DoFilterOnLoad(false); |
| 760 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 754 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 761 mock_pref_hash_store_->checked_paths_count()); | 755 mock_pref_hash_store_->checked_paths_count()); |
| 762 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 756 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 763 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 757 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 764 | 758 |
| 765 // Delegate saw all prefs, two of which had the expected value_state. | 759 // Delegate saw all prefs, two of which had the expected value_state. |
| 766 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 760 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 767 mock_validation_delegate_.recorded_validations_count()); | 761 mock_validation_delegate_.recorded_validations_count()); |
| 768 ASSERT_EQ(2u, | 762 ASSERT_EQ(2u, mock_validation_delegate_.CountValidationsOfState( |
| 769 mock_validation_delegate_.CountValidationsOfState( | 763 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE)); |
| 770 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE)); | |
| 771 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 764 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 772 mock_validation_delegate_.CountValidationsOfState( | 765 mock_validation_delegate_.CountValidationsOfState( |
| 773 PrefHashStoreTransaction::UNCHANGED)); | 766 PrefHashStoreTransaction::UNCHANGED)); |
| 774 | 767 |
| 775 // Seeding is always allowed for trusted unknown values. | 768 // Seeding is always allowed for trusted unknown values. |
| 776 const base::Value* atomic_value_in_store; | 769 const base::Value* atomic_value_in_store; |
| 777 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); | 770 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); |
| 778 ASSERT_EQ(string_value, atomic_value_in_store); | 771 ASSERT_EQ(string_value, atomic_value_in_store); |
| 779 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 772 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 780 mock_pref_hash_store_->stored_value(kAtomicPref); | 773 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 781 ASSERT_EQ(string_value, stored_atomic_value.first); | 774 ASSERT_EQ(string_value, stored_atomic_value.first); |
| 782 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 775 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 783 stored_atomic_value.second); | 776 stored_atomic_value.second); |
| 784 | 777 |
| 785 const base::Value* split_value_in_store; | 778 const base::Value* split_value_in_store; |
| 786 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 779 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
| 787 ASSERT_EQ(dict_value, split_value_in_store); | 780 ASSERT_EQ(dict_value, split_value_in_store); |
| 788 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 781 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 789 mock_pref_hash_store_->stored_value(kSplitPref); | 782 mock_pref_hash_store_->stored_value(kSplitPref); |
| 790 ASSERT_EQ(dict_value, stored_split_value.first); | 783 ASSERT_EQ(dict_value, stored_split_value.first); |
| 791 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 784 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); |
| 792 stored_split_value.second); | |
| 793 } | 785 } |
| 794 | 786 |
| 795 TEST_P(PrefHashFilterTest, InitialValueChanged) { | 787 TEST_P(PrefHashFilterTest, InitialValueChanged) { |
| 796 // Ownership of this value is transfered to |pref_store_contents_|. | 788 // Ownership of this value is transfered to |pref_store_contents_|. |
| 797 base::Value* int_value = new base::FundamentalValue(1234); | 789 base::Value* int_value = new base::FundamentalValue(1234); |
| 798 pref_store_contents_->Set(kAtomicPref, int_value); | 790 pref_store_contents_->Set(kAtomicPref, int_value); |
| 799 | 791 |
| 800 base::DictionaryValue* dict_value = new base::DictionaryValue; | 792 base::DictionaryValue* dict_value = new base::DictionaryValue; |
| 801 dict_value->SetString("a", "foo"); | 793 dict_value->SetString("a", "foo"); |
| 802 dict_value->SetInteger("b", 1234); | 794 dict_value->SetInteger("b", 1234); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 817 mock_invalid_keys.push_back("c"); | 809 mock_invalid_keys.push_back("c"); |
| 818 mock_pref_hash_store_->SetInvalidKeysResult(kSplitPref, mock_invalid_keys); | 810 mock_pref_hash_store_->SetInvalidKeysResult(kSplitPref, mock_invalid_keys); |
| 819 | 811 |
| 820 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); | 812 DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD); |
| 821 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 813 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 822 mock_pref_hash_store_->checked_paths_count()); | 814 mock_pref_hash_store_->checked_paths_count()); |
| 823 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 815 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 824 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 816 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 825 | 817 |
| 826 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 818 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 827 mock_pref_hash_store_->stored_value(kAtomicPref); | 819 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 828 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 820 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 829 mock_pref_hash_store_->stored_value(kSplitPref); | 821 mock_pref_hash_store_->stored_value(kSplitPref); |
| 830 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 822 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 831 stored_atomic_value.second); | 823 stored_atomic_value.second); |
| 832 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 824 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); |
| 833 stored_split_value.second); | |
| 834 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { | 825 if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) { |
| 835 // Ensure the atomic pref was cleared and the hash for NULL was restored if | 826 // Ensure the atomic pref was cleared and the hash for NULL was restored if |
| 836 // the current enforcement level prevents changes. | 827 // the current enforcement level prevents changes. |
| 837 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 828 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 838 ASSERT_EQ(NULL, stored_atomic_value.first); | 829 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 839 | 830 |
| 840 // The split pref on the other hand should only have been stripped of its | 831 // The split pref on the other hand should only have been stripped of its |
| 841 // invalid keys. | 832 // invalid keys. |
| 842 const base::Value* split_value_in_store; | 833 const base::Value* split_value_in_store; |
| 843 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 834 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 PrefHashStoreTransaction::CLEARED); | 871 PrefHashStoreTransaction::CLEARED); |
| 881 DoFilterOnLoad(false); | 872 DoFilterOnLoad(false); |
| 882 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 873 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 883 mock_pref_hash_store_->checked_paths_count()); | 874 mock_pref_hash_store_->checked_paths_count()); |
| 884 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 875 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 885 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 876 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 886 | 877 |
| 887 // Delegate saw all prefs, two of which had the expected value_state. | 878 // Delegate saw all prefs, two of which had the expected value_state. |
| 888 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 879 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 889 mock_validation_delegate_.recorded_validations_count()); | 880 mock_validation_delegate_.recorded_validations_count()); |
| 890 ASSERT_EQ(2u, | 881 ASSERT_EQ(2u, mock_validation_delegate_.CountValidationsOfState( |
| 891 mock_validation_delegate_.CountValidationsOfState( | 882 PrefHashStoreTransaction::CLEARED)); |
| 892 PrefHashStoreTransaction::CLEARED)); | |
| 893 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 883 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 894 mock_validation_delegate_.CountValidationsOfState( | 884 mock_validation_delegate_.CountValidationsOfState( |
| 895 PrefHashStoreTransaction::UNCHANGED)); | 885 PrefHashStoreTransaction::UNCHANGED)); |
| 896 | 886 |
| 897 // Regardless of the enforcement level, the only thing that should be done is | 887 // Regardless of the enforcement level, the only thing that should be done is |
| 898 // to restore the hash for NULL. The value itself should still be NULL. | 888 // to restore the hash for NULL. The value itself should still be NULL. |
| 899 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); | 889 ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 900 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 890 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 901 mock_pref_hash_store_->stored_value(kAtomicPref); | 891 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 902 ASSERT_EQ(NULL, stored_atomic_value.first); | 892 ASSERT_EQ(NULL, stored_atomic_value.first); |
| 903 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 893 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 904 stored_atomic_value.second); | 894 stored_atomic_value.second); |
| 905 | 895 |
| 906 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); | 896 ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 907 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 897 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 908 mock_pref_hash_store_->stored_value(kSplitPref); | 898 mock_pref_hash_store_->stored_value(kSplitPref); |
| 909 ASSERT_EQ(NULL, stored_split_value.first); | 899 ASSERT_EQ(NULL, stored_split_value.first); |
| 910 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 900 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); |
| 911 stored_split_value.second); | |
| 912 } | 901 } |
| 913 | 902 |
| 914 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { | 903 TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) { |
| 915 // Ownership of these values is transfered to |pref_store_contents_|. | 904 // Ownership of these values is transfered to |pref_store_contents_|. |
| 916 base::StringValue* string_value = new base::StringValue("string value"); | 905 base::StringValue* string_value = new base::StringValue("string value"); |
| 917 pref_store_contents_->Set(kAtomicPref, string_value); | 906 pref_store_contents_->Set(kAtomicPref, string_value); |
| 918 | 907 |
| 919 base::DictionaryValue* dict_value = new base::DictionaryValue; | 908 base::DictionaryValue* dict_value = new base::DictionaryValue; |
| 920 dict_value->SetString("a", "foo"); | 909 dict_value->SetString("a", "foo"); |
| 921 dict_value->SetInteger("b", 1234); | 910 dict_value->SetInteger("b", 1234); |
| 922 pref_store_contents_->Set(kSplitPref, dict_value); | 911 pref_store_contents_->Set(kSplitPref, dict_value); |
| 923 | 912 |
| 924 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); | 913 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL)); |
| 925 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); | 914 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL)); |
| 926 | 915 |
| 927 mock_pref_hash_store_->SetCheckResult( | 916 mock_pref_hash_store_->SetCheckResult( |
| 928 kAtomicPref, PrefHashStoreTransaction::SECURE_LEGACY); | 917 kAtomicPref, PrefHashStoreTransaction::SECURE_LEGACY); |
| 929 mock_pref_hash_store_->SetCheckResult( | 918 mock_pref_hash_store_->SetCheckResult( |
| 930 kSplitPref, PrefHashStoreTransaction::SECURE_LEGACY); | 919 kSplitPref, PrefHashStoreTransaction::SECURE_LEGACY); |
| 931 DoFilterOnLoad(false); | 920 DoFilterOnLoad(false); |
| 932 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 921 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 933 mock_pref_hash_store_->checked_paths_count()); | 922 mock_pref_hash_store_->checked_paths_count()); |
| 934 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 923 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 935 | 924 |
| 936 // Delegate saw all prefs, two of which had the expected value_state. | 925 // Delegate saw all prefs, two of which had the expected value_state. |
| 937 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 926 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 938 mock_validation_delegate_.recorded_validations_count()); | 927 mock_validation_delegate_.recorded_validations_count()); |
| 939 ASSERT_EQ(2u, | 928 ASSERT_EQ(2u, mock_validation_delegate_.CountValidationsOfState( |
| 940 mock_validation_delegate_.CountValidationsOfState( | 929 PrefHashStoreTransaction::SECURE_LEGACY)); |
| 941 PrefHashStoreTransaction::SECURE_LEGACY)); | |
| 942 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, | 930 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 2u, |
| 943 mock_validation_delegate_.CountValidationsOfState( | 931 mock_validation_delegate_.CountValidationsOfState( |
| 944 PrefHashStoreTransaction::UNCHANGED)); | 932 PrefHashStoreTransaction::UNCHANGED)); |
| 945 | 933 |
| 946 // Ensure that both the atomic and split hashes were restored. | 934 // Ensure that both the atomic and split hashes were restored. |
| 947 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); | 935 ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count()); |
| 948 | 936 |
| 949 // In all cases, the values should have remained intact and the hashes should | 937 // In all cases, the values should have remained intact and the hashes should |
| 950 // have been updated to match them. | 938 // have been updated to match them. |
| 951 | 939 |
| 952 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = | 940 MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value = |
| 953 mock_pref_hash_store_->stored_value(kAtomicPref); | 941 mock_pref_hash_store_->stored_value(kAtomicPref); |
| 954 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, | 942 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, |
| 955 stored_atomic_value.second); | 943 stored_atomic_value.second); |
| 956 const base::Value* atomic_value_in_store; | 944 const base::Value* atomic_value_in_store; |
| 957 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); | 945 ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store)); |
| 958 ASSERT_EQ(string_value, atomic_value_in_store); | 946 ASSERT_EQ(string_value, atomic_value_in_store); |
| 959 ASSERT_EQ(string_value, stored_atomic_value.first); | 947 ASSERT_EQ(string_value, stored_atomic_value.first); |
| 960 | 948 |
| 961 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = | 949 MockPrefHashStore::ValuePtrStrategyPair stored_split_value = |
| 962 mock_pref_hash_store_->stored_value(kSplitPref); | 950 mock_pref_hash_store_->stored_value(kSplitPref); |
| 963 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, | 951 ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_split_value.second); |
| 964 stored_split_value.second); | |
| 965 const base::Value* split_value_in_store; | 952 const base::Value* split_value_in_store; |
| 966 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); | 953 ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store)); |
| 967 ASSERT_EQ(dict_value, split_value_in_store); | 954 ASSERT_EQ(dict_value, split_value_in_store); |
| 968 ASSERT_EQ(dict_value, stored_split_value.first); | 955 ASSERT_EQ(dict_value, stored_split_value.first); |
| 969 | 956 |
| 970 VerifyRecordedReset(false); | 957 VerifyRecordedReset(false); |
| 971 } | 958 } |
| 972 | 959 |
| 973 TEST_P(PrefHashFilterTest, DontResetReportOnly) { | 960 TEST_P(PrefHashFilterTest, DontResetReportOnly) { |
| 974 // Ownership of these values is transfered to |pref_store_contents_|. | 961 // Ownership of these values is transfered to |pref_store_contents_|. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1000 // All prefs should be checked and a new hash should be stored for each tested | 987 // All prefs should be checked and a new hash should be stored for each tested |
| 1001 // pref. | 988 // pref. |
| 1002 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 989 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 1003 mock_pref_hash_store_->checked_paths_count()); | 990 mock_pref_hash_store_->checked_paths_count()); |
| 1004 ASSERT_EQ(4u, mock_pref_hash_store_->stored_paths_count()); | 991 ASSERT_EQ(4u, mock_pref_hash_store_->stored_paths_count()); |
| 1005 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); | 992 ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed()); |
| 1006 | 993 |
| 1007 // Delegate saw all prefs, four of which had the expected value_state. | 994 // Delegate saw all prefs, four of which had the expected value_state. |
| 1008 ASSERT_EQ(arraysize(kTestTrackedPrefs), | 995 ASSERT_EQ(arraysize(kTestTrackedPrefs), |
| 1009 mock_validation_delegate_.recorded_validations_count()); | 996 mock_validation_delegate_.recorded_validations_count()); |
| 1010 ASSERT_EQ(4u, | 997 ASSERT_EQ(4u, mock_validation_delegate_.CountValidationsOfState( |
| 1011 mock_validation_delegate_.CountValidationsOfState( | 998 PrefHashStoreTransaction::CHANGED)); |
| 1012 PrefHashStoreTransaction::CHANGED)); | |
| 1013 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 4u, | 999 ASSERT_EQ(arraysize(kTestTrackedPrefs) - 4u, |
| 1014 mock_validation_delegate_.CountValidationsOfState( | 1000 mock_validation_delegate_.CountValidationsOfState( |
| 1015 PrefHashStoreTransaction::UNCHANGED)); | 1001 PrefHashStoreTransaction::UNCHANGED)); |
| 1016 | 1002 |
| 1017 // No matter what the enforcement level is, the report only pref should never | 1003 // No matter what the enforcement level is, the report only pref should never |
| 1018 // be reset. | 1004 // be reset. |
| 1019 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); | 1005 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL)); |
| 1020 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL)); | 1006 ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL)); |
| 1021 ASSERT_EQ(report_only_val, | 1007 ASSERT_EQ(report_only_val, |
| 1022 mock_pref_hash_store_->stored_value(kReportOnlyPref).first); | 1008 mock_pref_hash_store_->stored_value(kReportOnlyPref).first); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1040 ASSERT_EQ(int_value1, | 1026 ASSERT_EQ(int_value1, |
| 1041 mock_pref_hash_store_->stored_value(kAtomicPref).first); | 1027 mock_pref_hash_store_->stored_value(kAtomicPref).first); |
| 1042 ASSERT_EQ(int_value2, value_in_store2); | 1028 ASSERT_EQ(int_value2, value_in_store2); |
| 1043 ASSERT_EQ(int_value2, | 1029 ASSERT_EQ(int_value2, |
| 1044 mock_pref_hash_store_->stored_value(kAtomicPref2).first); | 1030 mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
| 1045 | 1031 |
| 1046 VerifyRecordedReset(false); | 1032 VerifyRecordedReset(false); |
| 1047 } | 1033 } |
| 1048 } | 1034 } |
| 1049 | 1035 |
| 1050 INSTANTIATE_TEST_CASE_P( | 1036 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, |
| 1051 PrefHashFilterTestInstance, PrefHashFilterTest, | 1037 PrefHashFilterTest, |
| 1052 testing::Values(PrefHashFilter::NO_ENFORCEMENT, | 1038 testing::Values(PrefHashFilter::NO_ENFORCEMENT, |
| 1053 PrefHashFilter::ENFORCE_ON_LOAD)); | 1039 PrefHashFilter::ENFORCE_ON_LOAD)); |
| OLD | NEW |