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 "chrome/browser/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> |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 stored_values_.find(path); | 147 stored_values_.find(path); |
148 if (value != stored_values_.end()) | 148 if (value != stored_values_.end()) |
149 return value->second; | 149 return value->second; |
150 return std::make_pair( | 150 return std::make_pair( |
151 reinterpret_cast<void*>(0xBAD), | 151 reinterpret_cast<void*>(0xBAD), |
152 static_cast<PrefHashFilter::PrefTrackingStrategy>(-1)); | 152 static_cast<PrefHashFilter::PrefTrackingStrategy>(-1)); |
153 } | 153 } |
154 | 154 |
155 // PrefHashStore implementation. | 155 // PrefHashStore implementation. |
156 virtual scoped_ptr<PrefHashStoreTransaction> BeginTransaction( | 156 virtual scoped_ptr<PrefHashStoreTransaction> BeginTransaction( |
157 scoped_ptr<HashStoreContents> storage) OVERRIDE; | 157 scoped_ptr<HashStoreContents> storage) override; |
158 | 158 |
159 private: | 159 private: |
160 // A MockPrefHashStoreTransaction is handed to the caller on | 160 // A MockPrefHashStoreTransaction is handed to the caller on |
161 // MockPrefHashStore::BeginTransaction(). It then stores state in its | 161 // MockPrefHashStore::BeginTransaction(). It then stores state in its |
162 // underlying MockPrefHashStore about calls it receives from that same caller | 162 // underlying MockPrefHashStore about calls it receives from that same caller |
163 // which can later be verified in tests. | 163 // which can later be verified in tests. |
164 class MockPrefHashStoreTransaction : public PrefHashStoreTransaction { | 164 class MockPrefHashStoreTransaction : public PrefHashStoreTransaction { |
165 public: | 165 public: |
166 explicit MockPrefHashStoreTransaction(MockPrefHashStore* outer) | 166 explicit MockPrefHashStoreTransaction(MockPrefHashStore* outer) |
167 : outer_(outer) {} | 167 : outer_(outer) {} |
168 | 168 |
169 virtual ~MockPrefHashStoreTransaction() { | 169 virtual ~MockPrefHashStoreTransaction() { |
170 outer_->transaction_active_ = false; | 170 outer_->transaction_active_ = false; |
171 ++outer_->transactions_performed_; | 171 ++outer_->transactions_performed_; |
172 } | 172 } |
173 | 173 |
174 // PrefHashStoreTransaction implementation. | 174 // PrefHashStoreTransaction implementation. |
175 virtual PrefHashStoreTransaction::ValueState CheckValue( | 175 virtual PrefHashStoreTransaction::ValueState CheckValue( |
176 const std::string& path, const base::Value* value) const OVERRIDE; | 176 const std::string& path, const base::Value* value) const override; |
177 virtual void StoreHash(const std::string& path, | 177 virtual void StoreHash(const std::string& path, |
178 const base::Value* new_value) OVERRIDE; | 178 const base::Value* new_value) override; |
179 virtual PrefHashStoreTransaction::ValueState CheckSplitValue( | 179 virtual PrefHashStoreTransaction::ValueState CheckSplitValue( |
180 const std::string& path, | 180 const std::string& path, |
181 const base::DictionaryValue* initial_split_value, | 181 const base::DictionaryValue* initial_split_value, |
182 std::vector<std::string>* invalid_keys) const OVERRIDE; | 182 std::vector<std::string>* invalid_keys) const override; |
183 virtual void StoreSplitHash( | 183 virtual void StoreSplitHash( |
184 const std::string& path, | 184 const std::string& path, |
185 const base::DictionaryValue* split_value) OVERRIDE; | 185 const base::DictionaryValue* split_value) override; |
186 virtual bool HasHash(const std::string& path) const OVERRIDE; | 186 virtual bool HasHash(const std::string& path) const override; |
187 virtual void ImportHash(const std::string& path, | 187 virtual void ImportHash(const std::string& path, |
188 const base::Value* hash) OVERRIDE; | 188 const base::Value* hash) override; |
189 virtual void ClearHash(const std::string& path) OVERRIDE; | 189 virtual void ClearHash(const std::string& path) override; |
190 virtual bool IsSuperMACValid() const OVERRIDE; | 190 virtual bool IsSuperMACValid() const override; |
191 virtual bool StampSuperMac() OVERRIDE; | 191 virtual bool StampSuperMac() override; |
192 | 192 |
193 private: | 193 private: |
194 MockPrefHashStore* outer_; | 194 MockPrefHashStore* outer_; |
195 | 195 |
196 DISALLOW_COPY_AND_ASSIGN(MockPrefHashStoreTransaction); | 196 DISALLOW_COPY_AND_ASSIGN(MockPrefHashStoreTransaction); |
197 }; | 197 }; |
198 | 198 |
199 // Records a call to this mock's CheckValue/CheckSplitValue methods. | 199 // Records a call to this mock's CheckValue/CheckSplitValue methods. |
200 PrefHashStoreTransaction::ValueState RecordCheckValue( | 200 PrefHashStoreTransaction::ValueState RecordCheckValue( |
201 const std::string& path, | 201 const std::string& path, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 362 } |
363 | 363 |
364 class PrefHashFilterTest | 364 class PrefHashFilterTest |
365 : public testing::TestWithParam<PrefHashFilter::EnforcementLevel> { | 365 : public testing::TestWithParam<PrefHashFilter::EnforcementLevel> { |
366 public: | 366 public: |
367 PrefHashFilterTest() : mock_pref_hash_store_(NULL), | 367 PrefHashFilterTest() : mock_pref_hash_store_(NULL), |
368 pref_store_contents_(new base::DictionaryValue), | 368 pref_store_contents_(new base::DictionaryValue), |
369 last_filter_on_load_modified_prefs_(false), | 369 last_filter_on_load_modified_prefs_(false), |
370 reset_recorded_(false) {} | 370 reset_recorded_(false) {} |
371 | 371 |
372 virtual void SetUp() OVERRIDE { | 372 virtual void SetUp() override { |
373 base::StatisticsRecorder::Initialize(); | 373 base::StatisticsRecorder::Initialize(); |
374 Reset(); | 374 Reset(); |
375 } | 375 } |
376 | 376 |
377 protected: | 377 protected: |
378 // Reset the PrefHashFilter instance. | 378 // Reset the PrefHashFilter instance. |
379 void Reset() { | 379 void Reset() { |
380 // Construct a PrefHashFilter and MockPrefHashStore for the test. | 380 // Construct a PrefHashFilter and MockPrefHashStore for the test. |
381 InitializePrefHashFilter(GetConfiguration(GetParam())); | 381 InitializePrefHashFilter(GetConfiguration(GetParam())); |
382 } | 382 } |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 mock_pref_hash_store_->stored_value(kAtomicPref2).first); | 1050 mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
1051 | 1051 |
1052 VerifyRecordedReset(false); | 1052 VerifyRecordedReset(false); |
1053 } | 1053 } |
1054 } | 1054 } |
1055 | 1055 |
1056 INSTANTIATE_TEST_CASE_P( | 1056 INSTANTIATE_TEST_CASE_P( |
1057 PrefHashFilterTestInstance, PrefHashFilterTest, | 1057 PrefHashFilterTestInstance, PrefHashFilterTest, |
1058 testing::Values(PrefHashFilter::NO_ENFORCEMENT, | 1058 testing::Values(PrefHashFilter::NO_ENFORCEMENT, |
1059 PrefHashFilter::ENFORCE_ON_LOAD)); | 1059 PrefHashFilter::ENFORCE_ON_LOAD)); |
OLD | NEW |