Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1012)

Side by Side Diff: services/preferences/persistent_pref_store_impl_unittest.cc

Issue 2778643002: Pref service: Filter updates from read-only pref stores. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "services/preferences/persistent_pref_store_impl.h" 5 #include "services/preferences/persistent_pref_store_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 auto backing_pref_store = 151 auto backing_pref_store =
152 make_scoped_refptr(new InitializationMockPersistentPrefStore( 152 make_scoped_refptr(new InitializationMockPersistentPrefStore(
153 false, PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE, true)); 153 false, PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE, true));
154 CreateImpl(backing_pref_store); 154 CreateImpl(backing_pref_store);
155 EXPECT_FALSE(pref_store()->IsInitializationComplete()); 155 EXPECT_FALSE(pref_store()->IsInitializationComplete());
156 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE, 156 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE,
157 pref_store()->GetReadError()); 157 pref_store()->GetReadError());
158 EXPECT_TRUE(pref_store()->ReadOnly()); 158 EXPECT_TRUE(pref_store()->ReadOnly());
159 } 159 }
160 160
161 class TestReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate {
162 public:
163 TestReadErrorDelegate(PersistentPrefStore::PrefReadError* storage,
164 const base::Closure& quit)
165 : storage_(storage), quit_(quit) {
166 DCHECK(storage_);
167 DCHECK(quit_);
168 }
169
170 void OnError(PersistentPrefStore::PrefReadError error) override {
171 *storage_ = error;
172 quit_.Run();
173 }
174
175 private:
176 PersistentPrefStore::PrefReadError* const storage_;
177 const base::Closure quit_;
178 };
179
180 TEST_F(PersistentPrefStoreImplTest, InitialValue) { 161 TEST_F(PersistentPrefStoreImplTest, InitialValue) {
181 auto backing_pref_store = make_scoped_refptr(new InMemoryPrefStore()); 162 auto backing_pref_store = make_scoped_refptr(new InMemoryPrefStore());
182 const base::Value value("value"); 163 const base::Value value("value");
183 backing_pref_store->SetValue(kKey, value.CreateDeepCopy(), 0); 164 backing_pref_store->SetValue(kKey, value.CreateDeepCopy(), 0);
184 CreateImpl(backing_pref_store); 165 CreateImpl(backing_pref_store);
185 EXPECT_TRUE(pref_store()->IsInitializationComplete()); 166 EXPECT_TRUE(pref_store()->IsInitializationComplete());
186 const base::Value* output = nullptr; 167 const base::Value* output = nullptr;
187 ASSERT_TRUE(pref_store()->GetValue(kKey, &output)); 168 ASSERT_TRUE(pref_store()->GetValue(kKey, &output));
188 EXPECT_TRUE(value.Equals(output)); 169 EXPECT_TRUE(value.Equals(output));
189 } 170 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 EXPECT_CALL(*backing_store, ClearMutableValues()) 361 EXPECT_CALL(*backing_store, ClearMutableValues())
381 .Times(1) 362 .Times(1)
382 .WillOnce(WithoutArgs(Invoke([&run_loop]() { run_loop.Quit(); }))); 363 .WillOnce(WithoutArgs(Invoke([&run_loop]() { run_loop.Quit(); })));
383 EXPECT_CALL(*backing_store, CommitPendingWrite()).Times(1); 364 EXPECT_CALL(*backing_store, CommitPendingWrite()).Times(1);
384 pref_store()->ClearMutableValues(); 365 pref_store()->ClearMutableValues();
385 run_loop.Run(); 366 run_loop.Run();
386 } 367 }
387 368
388 } // namespace 369 } // namespace
389 } // namespace prefs 370 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698