| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/public/cpp/pref_service_factory.h" | 5 #include "services/preferences/public/cpp/pref_service_factory.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/test/sequenced_worker_pool_owner.h" | 10 #include "base/test/sequenced_worker_pool_owner.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // base::MessageLoop::DestructionObserver | 118 // base::MessageLoop::DestructionObserver |
| 119 void WillDestroyCurrentMessageLoop() override { worker_pool_owner_.reset(); } | 119 void WillDestroyCurrentMessageLoop() override { worker_pool_owner_.reset(); } |
| 120 | 120 |
| 121 // Create a fully initialized PrefService synchronously. | 121 // Create a fully initialized PrefService synchronously. |
| 122 std::unique_ptr<PrefService> Create() { | 122 std::unique_ptr<PrefService> Create() { |
| 123 std::unique_ptr<PrefService> pref_service; | 123 std::unique_ptr<PrefService> pref_service; |
| 124 base::RunLoop run_loop; | 124 base::RunLoop run_loop; |
| 125 auto pref_registry = make_scoped_refptr(new PrefRegistrySimple()); | 125 auto pref_registry = make_scoped_refptr(new PrefRegistrySimple()); |
| 126 pref_registry->RegisterIntegerPref(kKey, kInitialValue); | 126 pref_registry->RegisterIntegerPref(kKey, kInitialValue); |
| 127 pref_registry->RegisterIntegerPref(kOtherKey, kInitialValue); | 127 pref_registry->RegisterIntegerPref(kOtherKey, kInitialValue); |
| 128 ConnectToPrefService(connector(), pref_registry, | 128 ConnectToPrefService(connector(), pref_registry, {}, |
| 129 base::Bind(&PrefServiceFactoryTest::OnCreate, | 129 base::Bind(&PrefServiceFactoryTest::OnCreate, |
| 130 run_loop.QuitClosure(), &pref_service)); | 130 run_loop.QuitClosure(), &pref_service)); |
| 131 run_loop.Run(); | 131 run_loop.Run(); |
| 132 return pref_service; | 132 return pref_service; |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Wait until first update of the pref |key| in |pref_service| synchronously. | 135 // Wait until first update of the pref |key| in |pref_service| synchronously. |
| 136 void WaitForPrefChange(PrefService* pref_service, const std::string& key) { | 136 void WaitForPrefChange(PrefService* pref_service, const std::string& key) { |
| 137 PrefChangeRegistrar registrar; | 137 PrefChangeRegistrar registrar; |
| 138 registrar.Init(pref_service); | 138 registrar.Init(pref_service); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 base::MakeUnique<base::Value>(2), 0); | 253 base::MakeUnique<base::Value>(2), 0); |
| 254 WaitForPrefChange(pref_service.get(), kKey); | 254 WaitForPrefChange(pref_service.get(), kKey); |
| 255 EXPECT_EQ(2, pref_service->GetInteger(kKey)); | 255 EXPECT_EQ(2, pref_service->GetInteger(kKey)); |
| 256 | 256 |
| 257 pref_service->SetInteger(kKey, 3); | 257 pref_service->SetInteger(kKey, 3); |
| 258 EXPECT_EQ(2, pref_service->GetInteger(kKey)); | 258 EXPECT_EQ(2, pref_service->GetInteger(kKey)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace | 261 } // namespace |
| 262 } // namespace prefs | 262 } // namespace prefs |
| OLD | NEW |