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

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

Issue 2791903003: Pref service: have Mash and Chrome connect to the right pref stores (Closed)
Patch Set: Don't require clients to specify the default store, but allow it 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 (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 30 matching lines...) Expand all
41 service_manager::InterfaceRegistry* registry) override { 41 service_manager::InterfaceRegistry* registry) override {
42 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); 42 registry->AddInterface<service_manager::mojom::ServiceFactory>(this);
43 return true; 43 return true;
44 } 44 }
45 45
46 void CreateService(service_manager::mojom::ServiceRequest request, 46 void CreateService(service_manager::mojom::ServiceRequest request,
47 const std::string& name) override { 47 const std::string& name) override {
48 if (name == prefs::mojom::kServiceName) { 48 if (name == prefs::mojom::kServiceName) {
49 pref_service_context_.reset(new service_manager::ServiceContext( 49 pref_service_context_.reset(new service_manager::ServiceContext(
50 CreatePrefService({PrefValueStore::COMMAND_LINE_STORE, 50 CreatePrefService({PrefValueStore::COMMAND_LINE_STORE,
51 PrefValueStore::RECOMMENDED_STORE}, 51 PrefValueStore::RECOMMENDED_STORE,
52 PrefValueStore::DEFAULT_STORE},
52 worker_pool_), 53 worker_pool_),
53 std::move(request))); 54 std::move(request)));
54 } 55 }
55 } 56 }
56 57
57 void Create(const service_manager::Identity& remote_identity, 58 void Create(const service_manager::Identity& remote_identity,
58 service_manager::mojom::ServiceFactoryRequest request) override { 59 service_manager::mojom::ServiceFactoryRequest request) override {
59 service_factory_bindings_.AddBinding(this, std::move(request)); 60 service_factory_bindings_.AddBinding(this, std::move(request));
60 } 61 }
61 62
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void WillDestroyCurrentMessageLoop() override { worker_pool_owner_.reset(); } 120 void WillDestroyCurrentMessageLoop() override { worker_pool_owner_.reset(); }
120 121
121 // Create a fully initialized PrefService synchronously. 122 // Create a fully initialized PrefService synchronously.
122 std::unique_ptr<PrefService> Create() { 123 std::unique_ptr<PrefService> Create() {
123 std::unique_ptr<PrefService> pref_service; 124 std::unique_ptr<PrefService> pref_service;
124 base::RunLoop run_loop; 125 base::RunLoop run_loop;
125 auto pref_registry = make_scoped_refptr(new PrefRegistrySimple()); 126 auto pref_registry = make_scoped_refptr(new PrefRegistrySimple());
126 pref_registry->RegisterIntegerPref(kKey, kInitialValue); 127 pref_registry->RegisterIntegerPref(kKey, kInitialValue);
127 pref_registry->RegisterIntegerPref(kOtherKey, kInitialValue); 128 pref_registry->RegisterIntegerPref(kOtherKey, kInitialValue);
128 ConnectToPrefService(connector(), pref_registry, 129 ConnectToPrefService(connector(), pref_registry,
130 std::vector<PrefValueStore::PrefStoreType>(),
129 base::Bind(&PrefServiceFactoryTest::OnCreate, 131 base::Bind(&PrefServiceFactoryTest::OnCreate,
130 run_loop.QuitClosure(), &pref_service)); 132 run_loop.QuitClosure(), &pref_service));
131 run_loop.Run(); 133 run_loop.Run();
132 return pref_service; 134 return pref_service;
133 } 135 }
134 136
135 // Wait until first update of the pref |key| in |pref_service| synchronously. 137 // Wait until first update of the pref |key| in |pref_service| synchronously.
136 void WaitForPrefChange(PrefService* pref_service, const std::string& key) { 138 void WaitForPrefChange(PrefService* pref_service, const std::string& key) {
137 PrefChangeRegistrar registrar; 139 PrefChangeRegistrar registrar;
138 registrar.Init(pref_service); 140 registrar.Init(pref_service);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 base::MakeUnique<base::Value>(2), 0); 255 base::MakeUnique<base::Value>(2), 0);
254 WaitForPrefChange(pref_service.get(), kKey); 256 WaitForPrefChange(pref_service.get(), kKey);
255 EXPECT_EQ(2, pref_service->GetInteger(kKey)); 257 EXPECT_EQ(2, pref_service->GetInteger(kKey));
256 258
257 pref_service->SetInteger(kKey, 3); 259 pref_service->SetInteger(kKey, 3);
258 EXPECT_EQ(2, pref_service->GetInteger(kKey)); 260 EXPECT_EQ(2, pref_service->GetInteger(kKey));
259 } 261 }
260 262
261 } // namespace 263 } // namespace
262 } // namespace prefs 264 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698