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

Side by Side Diff: chrome/browser/chromeos/preferences_chromeos_browsertest.cc

Issue 2698913005: Re-enable preferences service access for browser+ash (Closed)
Patch Set: . Created 3 years, 10 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 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 #include <stddef.h> 5 #include <stddef.h>
6 #include <sys/types.h> 6 #include <sys/types.h>
7 7
8 #include <set>
9 #include <string>
10
8 #include "ash/shell.h" 11 #include "ash/shell.h"
9 #include "base/command_line.h" 12 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
11 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/run_loop.h"
17 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" 19 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
14 #include "chrome/browser/chromeos/login/login_manager_test.h" 20 #include "chrome/browser/chromeos/login/login_manager_test.h"
15 #include "chrome/browser/chromeos/login/startup_utils.h" 21 #include "chrome/browser/chromeos/login/startup_utils.h"
16 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" 22 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
17 #include "chrome/browser/chromeos/preferences.h" 23 #include "chrome/browser/chromeos/preferences.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 25 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 26 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
21 #include "chrome/browser/chromeos/system/fake_input_device_settings.h" 27 #include "chrome/browser/chromeos/system/fake_input_device_settings.h"
22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 28 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
29 #include "chrome/browser/ui/browser.h"
23 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
31 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chromeos/chromeos_switches.h" 32 #include "chromeos/chromeos_switches.h"
25 #include "components/feedback/tracing_manager.h" 33 #include "components/feedback/tracing_manager.h"
26 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "components/prefs/pref_store.h"
36 #include "components/prefs/writeable_pref_store.h"
27 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
38 #include "content/public/common/service_manager_connection.h"
28 #include "content/public/test/test_utils.h" 39 #include "content/public/test/test_utils.h"
40 #include "services/preferences/public/cpp/pref_client_store.h"
41 #include "services/preferences/public/interfaces/preferences.mojom.h"
42 #include "services/service_manager/public/cpp/connector.h"
29 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
30 #include "ui/base/ime/chromeos/fake_ime_keyboard.h" 44 #include "ui/base/ime/chromeos/fake_ime_keyboard.h"
31 #include "ui/events/event_utils.h" 45 #include "ui/events/event_utils.h"
32 46
33 namespace chromeos { 47 namespace chromeos {
34 48
35 namespace { 49 namespace {
36 50
37 const char* const kTestUsers[] = {"test-user1@gmail.com", 51 const char* const kTestUsers[] = {"test-user1@gmail.com",
38 "test-user2@gmail.com"}; 52 "test-user2@gmail.com"};
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 148
135 std::vector<AccountId> test_users_; 149 std::vector<AccountId> test_users_;
136 150
137 private: 151 private:
138 system::InputDeviceSettings::FakeInterface* input_settings_; 152 system::InputDeviceSettings::FakeInterface* input_settings_;
139 input_method::FakeImeKeyboard* keyboard_; 153 input_method::FakeImeKeyboard* keyboard_;
140 154
141 DISALLOW_COPY_AND_ASSIGN(PreferencesTest); 155 DISALLOW_COPY_AND_ASSIGN(PreferencesTest);
142 }; 156 };
143 157
158 class PreferencesServiceBrowserTest : public InProcessBrowserTest {
159 public:
160 PreferencesServiceBrowserTest() {}
161
162 protected:
163 static service_manager::Connector* connector() {
164 return content::ServiceManagerConnection::GetForProcess()->GetConnector();
165 }
166
167 void WaitForPrefChange(PrefStore* store, const std::string& key) {
168 base::RunLoop run_loop;
169 TestPrefObserver observer(key, run_loop.QuitClosure());
170 store->AddObserver(&observer);
171 run_loop.Run();
172 store->RemoveObserver(&observer);
173 }
174
175 int GetIntegerPrefValue(PrefStore* store, const std::string& key) {
176 int int_value = 0;
177 const base::Value* value = nullptr;
178 EXPECT_TRUE(store->GetValue(key, &value));
sky 2017/02/17 17:44:22 If this returns false, won't the next line crash?
Ken Rockot(use gerrit already) 2017/02/17 18:58:22 Done
179 EXPECT_TRUE(value->GetAsInteger(&int_value));
180 return int_value;
181 }
182
183 private:
184 class TestPrefObserver : public PrefStore::Observer {
185 public:
186 TestPrefObserver(const std::string& pref_name,
187 const base::Closure& callback)
188 : pref_name_(pref_name), callback_(callback) {}
189
190 ~TestPrefObserver() override {}
191
192 // PrefStore::Observer:
193 void OnPrefValueChanged(const std::string& key) override {
194 if (key == pref_name_)
jonross 2017/02/16 21:53:35 Have this be an EXPECT_EQ? That way we fail explic
Ken Rockot(use gerrit already) 2017/02/17 00:00:31 I think the test should tolerate other prefs being
jonross 2017/02/17 02:15:46 SGTM
195 callback_.Run();
196 }
197
198 void OnInitializationCompleted(bool success) override {
199 ASSERT_TRUE(success);
200 }
201
202 private:
203 const std::string pref_name_;
204 const base::Closure callback_;
205
206 DISALLOW_COPY_AND_ASSIGN(TestPrefObserver);
207 };
208
209 DISALLOW_COPY_AND_ASSIGN(PreferencesServiceBrowserTest);
210 };
211
144 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) { 212 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) {
145 RegisterUser(test_users_[0].GetUserEmail()); 213 RegisterUser(test_users_[0].GetUserEmail());
146 RegisterUser(test_users_[1].GetUserEmail()); 214 RegisterUser(test_users_[1].GetUserEmail());
147 chromeos::StartupUtils::MarkOobeCompleted(); 215 chromeos::StartupUtils::MarkOobeCompleted();
148 } 216 }
149 217
150 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) { 218 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) {
151 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 219 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
152 220
153 // Add first user and init its preferences. Check that corresponding 221 // Add first user and init its preferences. Check that corresponding
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 prefs1->SetBoolean(prefs::kTapToClickEnabled, 275 prefs1->SetBoolean(prefs::kTapToClickEnabled,
208 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); 276 !prefs1->GetBoolean(prefs::kTapToClickEnabled));
209 CheckLocalStateCorrespondsToPrefs(prefs1); 277 CheckLocalStateCorrespondsToPrefs(prefs1);
210 278
211 // Switch user back. 279 // Switch user back.
212 user_manager->SwitchActiveUser(test_users_[0]); 280 user_manager->SwitchActiveUser(test_users_[0]);
213 CheckSettingsCorrespondToPrefs(prefs1); 281 CheckSettingsCorrespondToPrefs(prefs1);
214 CheckLocalStateCorrespondsToPrefs(prefs1); 282 CheckLocalStateCorrespondsToPrefs(prefs1);
215 } 283 }
216 284
285 IN_PROC_BROWSER_TEST_F(PreferencesServiceBrowserTest, Basic) {
286 prefs::mojom::PreferencesServiceFactoryPtr factory_a;
287 connector()->BindInterface(prefs::mojom::kServiceName, &factory_a);
288 scoped_refptr<preferences::PrefClientStore> pref_store_a =
289 new preferences::PrefClientStore(std::move(factory_a));
290
291 prefs::mojom::PreferencesServiceFactoryPtr factory_b;
292 connector()->BindInterface(prefs::mojom::kServiceName, &factory_b);
293 scoped_refptr<preferences::PrefClientStore> pref_store_b =
294 new preferences::PrefClientStore(std::move(factory_b));
295
296 constexpr int kInitialValue = 1;
297 PrefService* pref_service = browser()->profile()->GetPrefs();
jonross 2017/02/16 21:53:35 This exposes the test to other preferences being u
Ken Rockot(use gerrit already) 2017/02/17 00:00:31 I started going down this route just to see what i
jonross 2017/02/17 02:15:46 Thanks for the clarification. I'm fine with treati
298 pref_service->SetInteger(prefs::kMouseSensitivity, kInitialValue);
299
300 pref_store_a->Subscribe({prefs::kMouseSensitivity});
301 WaitForPrefChange(pref_store_a.get(), prefs::kMouseSensitivity);
302 EXPECT_EQ(kInitialValue,
303 GetIntegerPrefValue(pref_store_a.get(), prefs::kMouseSensitivity));
304
305 pref_store_b->Subscribe({prefs::kMouseSensitivity});
306 WaitForPrefChange(pref_store_b.get(), prefs::kMouseSensitivity);
307 EXPECT_EQ(kInitialValue,
308 GetIntegerPrefValue(pref_store_b.get(), prefs::kMouseSensitivity));
309
310 const int kTestValue = 42;
311 pref_store_a->SetValue(prefs::kMouseSensitivity,
312 base::MakeUnique<base::FundamentalValue>(kTestValue),
313 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
314
315 WaitForPrefChange(pref_store_b.get(), prefs::kMouseSensitivity);
316 EXPECT_EQ(kTestValue,
317 GetIntegerPrefValue(pref_store_b.get(), prefs::kMouseSensitivity));
318 }
319
217 } // namespace chromeos 320 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698