| OLD | NEW |
| 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 Loading... |
| 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 bool GetIntegerPrefValue(PrefStore* store, |
| 176 const std::string& key, |
| 177 int* out_value) { |
| 178 const base::Value* value = nullptr; |
| 179 if (!store->GetValue(key, &value)) |
| 180 return false; |
| 181 return value->GetAsInteger(out_value); |
| 182 } |
| 183 |
| 184 private: |
| 185 class TestPrefObserver : public PrefStore::Observer { |
| 186 public: |
| 187 TestPrefObserver(const std::string& pref_name, |
| 188 const base::Closure& callback) |
| 189 : pref_name_(pref_name), callback_(callback) {} |
| 190 |
| 191 ~TestPrefObserver() override {} |
| 192 |
| 193 // PrefStore::Observer: |
| 194 void OnPrefValueChanged(const std::string& key) override { |
| 195 if (key == pref_name_) |
| 196 callback_.Run(); |
| 197 } |
| 198 |
| 199 void OnInitializationCompleted(bool success) override { |
| 200 ASSERT_TRUE(success); |
| 201 } |
| 202 |
| 203 private: |
| 204 const std::string pref_name_; |
| 205 const base::Closure callback_; |
| 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(TestPrefObserver); |
| 208 }; |
| 209 |
| 210 DISALLOW_COPY_AND_ASSIGN(PreferencesServiceBrowserTest); |
| 211 }; |
| 212 |
| 144 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) { | 213 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) { |
| 145 RegisterUser(test_users_[0].GetUserEmail()); | 214 RegisterUser(test_users_[0].GetUserEmail()); |
| 146 RegisterUser(test_users_[1].GetUserEmail()); | 215 RegisterUser(test_users_[1].GetUserEmail()); |
| 147 chromeos::StartupUtils::MarkOobeCompleted(); | 216 chromeos::StartupUtils::MarkOobeCompleted(); |
| 148 } | 217 } |
| 149 | 218 |
| 150 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) { | 219 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) { |
| 151 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 220 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 152 | 221 |
| 153 // Add first user and init its preferences. Check that corresponding | 222 // Add first user and init its preferences. Check that corresponding |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 prefs1->SetBoolean(prefs::kTapToClickEnabled, | 276 prefs1->SetBoolean(prefs::kTapToClickEnabled, |
| 208 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); | 277 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); |
| 209 CheckLocalStateCorrespondsToPrefs(prefs1); | 278 CheckLocalStateCorrespondsToPrefs(prefs1); |
| 210 | 279 |
| 211 // Switch user back. | 280 // Switch user back. |
| 212 user_manager->SwitchActiveUser(test_users_[0]); | 281 user_manager->SwitchActiveUser(test_users_[0]); |
| 213 CheckSettingsCorrespondToPrefs(prefs1); | 282 CheckSettingsCorrespondToPrefs(prefs1); |
| 214 CheckLocalStateCorrespondsToPrefs(prefs1); | 283 CheckLocalStateCorrespondsToPrefs(prefs1); |
| 215 } | 284 } |
| 216 | 285 |
| 286 IN_PROC_BROWSER_TEST_F(PreferencesServiceBrowserTest, Basic) { |
| 287 constexpr int kInitialValue = 1; |
| 288 PrefService* pref_service = browser()->profile()->GetPrefs(); |
| 289 pref_service->SetInteger(prefs::kMouseSensitivity, kInitialValue); |
| 290 |
| 291 prefs::mojom::PreferencesServiceFactoryPtr factory_a; |
| 292 connector()->BindInterface(prefs::mojom::kServiceName, &factory_a); |
| 293 scoped_refptr<preferences::PrefClientStore> pref_store_a = |
| 294 new preferences::PrefClientStore(std::move(factory_a)); |
| 295 pref_store_a->Subscribe({prefs::kMouseSensitivity}); |
| 296 WaitForPrefChange(pref_store_a.get(), prefs::kMouseSensitivity); |
| 297 |
| 298 prefs::mojom::PreferencesServiceFactoryPtr factory_b; |
| 299 connector()->BindInterface(prefs::mojom::kServiceName, &factory_b); |
| 300 scoped_refptr<preferences::PrefClientStore> pref_store_b = |
| 301 new preferences::PrefClientStore(std::move(factory_b)); |
| 302 pref_store_b->Subscribe({prefs::kMouseSensitivity}); |
| 303 WaitForPrefChange(pref_store_b.get(), prefs::kMouseSensitivity); |
| 304 |
| 305 int value_a = 0; |
| 306 ASSERT_TRUE(GetIntegerPrefValue(pref_store_a.get(), prefs::kMouseSensitivity, |
| 307 &value_a)); |
| 308 EXPECT_EQ(kInitialValue, value_a); |
| 309 |
| 310 int value_b = 0; |
| 311 ASSERT_TRUE(GetIntegerPrefValue(pref_store_b.get(), prefs::kMouseSensitivity, |
| 312 &value_b)); |
| 313 EXPECT_EQ(kInitialValue, value_b); |
| 314 |
| 315 const int kTestValue = 42; |
| 316 pref_store_a->SetValue(prefs::kMouseSensitivity, |
| 317 base::MakeUnique<base::FundamentalValue>(kTestValue), |
| 318 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 319 WaitForPrefChange(pref_store_b.get(), prefs::kMouseSensitivity); |
| 320 ASSERT_TRUE(GetIntegerPrefValue(pref_store_b.get(), prefs::kMouseSensitivity, |
| 321 &value_b)); |
| 322 EXPECT_EQ(kTestValue, value_b); |
| 323 } |
| 324 |
| 217 } // namespace chromeos | 325 } // namespace chromeos |
| OLD | NEW |