| 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( | 23 ValidationEvent(const std::string& path, |
| 24 const std::string& path, | 24 PrefHashStoreTransaction::ValueState state, |
| 25 PrefHashStoreTransaction::ValueState state, | 25 bool is_personal, |
| 26 PrefHashStoreTransaction::ValueState external_validation_state, | 26 PrefHashFilter::PrefTrackingStrategy tracking_strategy) |
| 27 bool is_personal, | |
| 28 PrefHashFilter::PrefTrackingStrategy tracking_strategy) | |
| 29 : pref_path(path), | 27 : pref_path(path), |
| 30 value_state(state), | 28 value_state(state), |
| 31 external_validation_value_state(external_validation_state), | |
| 32 is_personal(is_personal), | 29 is_personal(is_personal), |
| 33 strategy(tracking_strategy) {} | 30 strategy(tracking_strategy) {} |
| 34 | 31 |
| 35 std::string pref_path; | 32 std::string pref_path; |
| 36 PrefHashStoreTransaction::ValueState value_state; | 33 PrefHashStoreTransaction::ValueState value_state; |
| 37 PrefHashStoreTransaction::ValueState external_validation_value_state; | |
| 38 bool is_personal; | 34 bool is_personal; |
| 39 PrefHashFilter::PrefTrackingStrategy strategy; | 35 PrefHashFilter::PrefTrackingStrategy strategy; |
| 40 }; | 36 }; |
| 41 | 37 |
| 42 MockValidationDelegate(); | 38 MockValidationDelegate(); |
| 43 ~MockValidationDelegate() override; | 39 ~MockValidationDelegate() override; |
| 44 | 40 |
| 45 // Returns the number of recorded validations. | 41 // Returns the number of recorded validations. |
| 46 size_t recorded_validations_count() const { return validations_.size(); } | 42 size_t recorded_validations_count() const { return validations_.size(); } |
| 47 | 43 |
| 48 // Returns the number of validations of a given value state. | 44 // Returns the number of validations of a given value state. |
| 49 size_t CountValidationsOfState( | 45 size_t CountValidationsOfState( |
| 50 PrefHashStoreTransaction::ValueState value_state) const; | 46 PrefHashStoreTransaction::ValueState value_state) const; |
| 51 | 47 |
| 52 // Returns the number of external validations of a given value state. | |
| 53 size_t CountExternalValidationsOfState( | |
| 54 PrefHashStoreTransaction::ValueState value_state) const; | |
| 55 | |
| 56 // Returns the event for the preference with a given path. | 48 // Returns the event for the preference with a given path. |
| 57 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; | 49 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; |
| 58 | 50 |
| 59 // TrackedPreferenceValidationDelegate implementation. | 51 // TrackedPreferenceValidationDelegate implementation. |
| 60 void OnAtomicPreferenceValidation( | 52 void OnAtomicPreferenceValidation( |
| 61 const std::string& pref_path, | 53 const std::string& pref_path, |
| 62 const base::Value* value, | 54 const base::Value* value, |
| 63 PrefHashStoreTransaction::ValueState value_state, | 55 PrefHashStoreTransaction::ValueState value_state, |
| 64 PrefHashStoreTransaction::ValueState external_validation_value_state, | |
| 65 bool is_personal) override; | 56 bool is_personal) override; |
| 66 void OnSplitPreferenceValidation( | 57 void OnSplitPreferenceValidation( |
| 67 const std::string& pref_path, | 58 const std::string& pref_path, |
| 68 const base::DictionaryValue* dict_value, | 59 const base::DictionaryValue* dict_value, |
| 69 const std::vector<std::string>& invalid_keys, | 60 const std::vector<std::string>& invalid_keys, |
| 70 PrefHashStoreTransaction::ValueState value_state, | 61 PrefHashStoreTransaction::ValueState value_state, |
| 71 PrefHashStoreTransaction::ValueState external_validation_value_state, | |
| 72 bool is_personal) override; | 62 bool is_personal) override; |
| 73 | 63 |
| 74 private: | 64 private: |
| 75 // Adds a new validation event. | 65 // Adds a new validation event. |
| 76 void RecordValidation( | 66 void RecordValidation(const std::string& pref_path, |
| 77 const std::string& pref_path, | 67 PrefHashStoreTransaction::ValueState value_state, |
| 78 PrefHashStoreTransaction::ValueState value_state, | 68 bool is_personal, |
| 79 PrefHashStoreTransaction::ValueState external_validation_value_state, | 69 PrefHashFilter::PrefTrackingStrategy strategy); |
| 80 bool is_personal, | |
| 81 PrefHashFilter::PrefTrackingStrategy strategy); | |
| 82 | 70 |
| 83 std::vector<ValidationEvent> validations_; | 71 std::vector<ValidationEvent> validations_; |
| 84 | 72 |
| 85 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); | 73 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); |
| 86 }; | 74 }; |
| 87 | 75 |
| 88 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | 76 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ |
| OLD | NEW |