| 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 "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" |
| 18 |
| 19 class MockValidationDelegate; |
| 18 | 20 |
| 19 // A mock tracked preference validation delegate for use by tests. | 21 // A mock tracked preference validation delegate for use by tests. |
| 20 class MockValidationDelegate : public TrackedPreferenceValidationDelegate { | 22 class MockValidationDelegateRecord |
| 23 : public base::RefCounted<MockValidationDelegateRecord> { |
| 21 public: | 24 public: |
| 22 struct ValidationEvent { | 25 struct ValidationEvent { |
| 23 ValidationEvent( | 26 ValidationEvent( |
| 24 const std::string& path, | 27 const std::string& path, |
| 25 PrefHashStoreTransaction::ValueState state, | 28 PrefHashStoreTransaction::ValueState state, |
| 26 PrefHashStoreTransaction::ValueState external_validation_state, | 29 PrefHashStoreTransaction::ValueState external_validation_state, |
| 27 bool is_personal, | 30 bool is_personal, |
| 28 PrefHashFilter::PrefTrackingStrategy tracking_strategy) | 31 PrefHashFilter::PrefTrackingStrategy tracking_strategy) |
| 29 : pref_path(path), | 32 : pref_path(path), |
| 30 value_state(state), | 33 value_state(state), |
| 31 external_validation_value_state(external_validation_state), | 34 external_validation_value_state(external_validation_state), |
| 32 is_personal(is_personal), | 35 is_personal(is_personal), |
| 33 strategy(tracking_strategy) {} | 36 strategy(tracking_strategy) {} |
| 34 | 37 |
| 35 std::string pref_path; | 38 std::string pref_path; |
| 36 PrefHashStoreTransaction::ValueState value_state; | 39 PrefHashStoreTransaction::ValueState value_state; |
| 37 PrefHashStoreTransaction::ValueState external_validation_value_state; | 40 PrefHashStoreTransaction::ValueState external_validation_value_state; |
| 38 bool is_personal; | 41 bool is_personal; |
| 39 PrefHashFilter::PrefTrackingStrategy strategy; | 42 PrefHashFilter::PrefTrackingStrategy strategy; |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 MockValidationDelegate(); | 45 MockValidationDelegateRecord(); |
| 43 ~MockValidationDelegate() override; | |
| 44 | 46 |
| 45 // Returns the number of recorded validations. | 47 // Returns the number of recorded validations. |
| 46 size_t recorded_validations_count() const { return validations_.size(); } | 48 size_t recorded_validations_count() const { return validations_.size(); } |
| 47 | 49 |
| 48 // Returns the number of validations of a given value state. | 50 // Returns the number of validations of a given value state. |
| 49 size_t CountValidationsOfState( | 51 size_t CountValidationsOfState( |
| 50 PrefHashStoreTransaction::ValueState value_state) const; | 52 PrefHashStoreTransaction::ValueState value_state) const; |
| 51 | 53 |
| 52 // Returns the number of external validations of a given value state. | 54 // Returns the number of external validations of a given value state. |
| 53 size_t CountExternalValidationsOfState( | 55 size_t CountExternalValidationsOfState( |
| 54 PrefHashStoreTransaction::ValueState value_state) const; | 56 PrefHashStoreTransaction::ValueState value_state) const; |
| 55 | 57 |
| 56 // Returns the event for the preference with a given path. | 58 // Returns the event for the preference with a given path. |
| 57 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; | 59 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; |
| 58 | 60 |
| 61 private: |
| 62 friend class MockValidationDelegate; |
| 63 friend class base::RefCounted<MockValidationDelegateRecord>; |
| 64 |
| 65 ~MockValidationDelegateRecord(); |
| 66 |
| 67 // Adds a new validation event. |
| 68 void RecordValidation( |
| 69 const std::string& pref_path, |
| 70 PrefHashStoreTransaction::ValueState value_state, |
| 71 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 72 bool is_personal, |
| 73 PrefHashFilter::PrefTrackingStrategy strategy); |
| 74 |
| 75 std::vector<ValidationEvent> validations_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegateRecord); |
| 78 }; |
| 79 |
| 80 class MockValidationDelegate |
| 81 : public prefs::mojom::TrackedPreferenceValidationDelegate { |
| 82 public: |
| 83 explicit MockValidationDelegate( |
| 84 scoped_refptr<MockValidationDelegateRecord> record); |
| 85 ~MockValidationDelegate() override; |
| 86 |
| 59 // TrackedPreferenceValidationDelegate implementation. | 87 // TrackedPreferenceValidationDelegate implementation. |
| 60 void OnAtomicPreferenceValidation( | 88 void OnAtomicPreferenceValidation( |
| 61 const std::string& pref_path, | 89 const std::string& pref_path, |
| 62 const base::Value* value, | 90 std::unique_ptr<base::Value> value, |
| 63 PrefHashStoreTransaction::ValueState value_state, | 91 PrefHashStoreTransaction::ValueState value_state, |
| 64 PrefHashStoreTransaction::ValueState external_validation_value_state, | 92 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 65 bool is_personal) override; | 93 bool is_personal) override; |
| 66 void OnSplitPreferenceValidation( | 94 void OnSplitPreferenceValidation( |
| 67 const std::string& pref_path, | 95 const std::string& pref_path, |
| 68 const base::DictionaryValue* dict_value, | |
| 69 const std::vector<std::string>& invalid_keys, | 96 const std::vector<std::string>& invalid_keys, |
| 70 const std::vector<std::string>& external_validation_invalid_keys, | 97 const std::vector<std::string>& external_validation_invalid_keys, |
| 71 PrefHashStoreTransaction::ValueState value_state, | 98 PrefHashStoreTransaction::ValueState value_state, |
| 72 PrefHashStoreTransaction::ValueState external_validation_value_state, | 99 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 73 bool is_personal) override; | 100 bool is_personal) override; |
| 74 | 101 |
| 75 private: | 102 private: |
| 76 // Adds a new validation event. | 103 // Adds a new validation event. |
| 77 void RecordValidation( | 104 void RecordValidation( |
| 78 const std::string& pref_path, | 105 const std::string& pref_path, |
| 79 PrefHashStoreTransaction::ValueState value_state, | 106 PrefHashStoreTransaction::ValueState value_state, |
| 80 PrefHashStoreTransaction::ValueState external_validation_value_state, | 107 PrefHashStoreTransaction::ValueState external_validation_value_state, |
| 81 bool is_personal, | 108 bool is_personal, |
| 82 PrefHashFilter::PrefTrackingStrategy strategy); | 109 PrefHashFilter::PrefTrackingStrategy strategy); |
| 83 | 110 |
| 84 std::vector<ValidationEvent> validations_; | 111 scoped_refptr<MockValidationDelegateRecord> record_; |
| 85 | 112 |
| 86 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); | 113 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); |
| 87 }; | 114 }; |
| 88 | 115 |
| 89 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | 116 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ |
| OLD | NEW |