| 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 #ifndef COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | 5 #ifndef COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ |
| 6 #define COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | 6 #define COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "components/user_prefs/tracked/pref_hash_filter.h" | 15 #include "components/user_prefs/tracked/pref_hash_filter.h" |
| 16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | 16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
| 17 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" | 17 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h
" |
| 18 | 18 |
| 19 // A mock tracked preference validation delegate for use by tests. | 19 // A mock tracked preference validation delegate for use by tests. |
| 20 class MockValidationDelegate : public TrackedPreferenceValidationDelegate { | 20 class MockValidationDelegate : public TrackedPreferenceValidationDelegate { |
| 21 public: | 21 public: |
| 22 struct ValidationEvent { | 22 struct ValidationEvent { |
| 23 ValidationEvent(const std::string& path, | 23 ValidationEvent( |
| 24 PrefHashStoreTransaction::ValueState state, | 24 const std::string& path, |
| 25 bool is_personal, | 25 PrefHashStoreTransaction::ValueState state, |
| 26 PrefHashFilter::PrefTrackingStrategy tracking_strategy) | 26 PrefHashStoreTransaction::ValueState external_validation_state, |
| 27 bool is_personal, |
| 28 PrefHashFilter::PrefTrackingStrategy tracking_strategy) |
| 27 : pref_path(path), | 29 : pref_path(path), |
| 28 value_state(state), | 30 value_state(state), |
| 31 external_validation_value_state(external_validation_state), |
| 29 is_personal(is_personal), | 32 is_personal(is_personal), |
| 30 strategy(tracking_strategy) {} | 33 strategy(tracking_strategy) {} |
| 31 | 34 |
| 32 std::string pref_path; | 35 std::string pref_path; |
| 33 PrefHashStoreTransaction::ValueState value_state; | 36 PrefHashStoreTransaction::ValueState value_state; |
| 37 PrefHashStoreTransaction::ValueState external_validation_value_state; |
| 34 bool is_personal; | 38 bool is_personal; |
| 35 PrefHashFilter::PrefTrackingStrategy strategy; | 39 PrefHashFilter::PrefTrackingStrategy strategy; |
| 36 }; | 40 }; |
| 37 | 41 |
| 38 MockValidationDelegate(); | 42 MockValidationDelegate(); |
| 39 ~MockValidationDelegate() override; | 43 ~MockValidationDelegate() override; |
| 40 | 44 |
| 41 // Returns the number of recorded validations. | 45 // Returns the number of recorded validations. |
| 42 size_t recorded_validations_count() const { return validations_.size(); } | 46 size_t recorded_validations_count() const { return validations_.size(); } |
| 43 | 47 |
| 44 // Returns the number of validations of a given value state. | 48 // Returns the number of validations of a given value state. |
| 45 size_t CountValidationsOfState( | 49 size_t CountValidationsOfState( |
| 46 PrefHashStoreTransaction::ValueState value_state) const; | 50 PrefHashStoreTransaction::ValueState value_state) const; |
| 47 | 51 |
| 52 // Returns the number of external validations of a given value state. |
| 53 size_t CountExternalValidationsOfState( |
| 54 PrefHashStoreTransaction::ValueState value_state) const; |
| 55 |
| 48 // Returns the event for the preference with a given path. | 56 // Returns the event for the preference with a given path. |
| 49 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; | 57 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; |
| 50 | 58 |
| 51 // TrackedPreferenceValidationDelegate implementation. | 59 // TrackedPreferenceValidationDelegate implementation. |
| 52 void OnAtomicPreferenceValidation( | 60 void OnAtomicPreferenceValidation( |
| 53 const std::string& pref_path, | 61 const std::string& pref_path, |
| 54 const base::Value* value, | 62 const base::Value* value, |
| 55 PrefHashStoreTransaction::ValueState value_state, | 63 PrefHashStoreTransaction::ValueState value_state, |
| 64 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 56 bool is_personal) override; | 65 bool is_personal) override; |
| 57 void OnSplitPreferenceValidation( | 66 void OnSplitPreferenceValidation( |
| 58 const std::string& pref_path, | 67 const std::string& pref_path, |
| 59 const base::DictionaryValue* dict_value, | 68 const base::DictionaryValue* dict_value, |
| 60 const std::vector<std::string>& invalid_keys, | 69 const std::vector<std::string>& invalid_keys, |
| 70 const std::vector<std::string>& external_validation_invalid_keys, |
| 61 PrefHashStoreTransaction::ValueState value_state, | 71 PrefHashStoreTransaction::ValueState value_state, |
| 72 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 62 bool is_personal) override; | 73 bool is_personal) override; |
| 63 | 74 |
| 64 private: | 75 private: |
| 65 // Adds a new validation event. | 76 // Adds a new validation event. |
| 66 void RecordValidation(const std::string& pref_path, | 77 void RecordValidation( |
| 67 PrefHashStoreTransaction::ValueState value_state, | 78 const std::string& pref_path, |
| 68 bool is_personal, | 79 PrefHashStoreTransaction::ValueState value_state, |
| 69 PrefHashFilter::PrefTrackingStrategy strategy); | 80 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 81 bool is_personal, |
| 82 PrefHashFilter::PrefTrackingStrategy strategy); |
| 70 | 83 |
| 71 std::vector<ValidationEvent> validations_; | 84 std::vector<ValidationEvent> validations_; |
| 72 | 85 |
| 73 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); | 86 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); |
| 74 }; | 87 }; |
| 75 | 88 |
| 76 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | 89 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ |
| OLD | NEW |