| 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 <sys/types.h> | 5 #include <sys/types.h> |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char* const kTestUsers[] = {"test-user1@gmail.com", | 36 const char* const kTestUsers[] = {"test-user1@gmail.com", |
| 37 "test-user2@gmail.com"}; | 37 "test-user2@gmail.com"}; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 class PreferencesTest : public LoginManagerTest { | 41 class PreferencesTest : public LoginManagerTest { |
| 42 public: | 42 public: |
| 43 PreferencesTest() | 43 PreferencesTest() |
| 44 : LoginManagerTest(true), input_settings_(NULL), keyboard_(NULL) { | 44 : LoginManagerTest(true), |
| 45 for (size_t i = 0; i < arraysize(kTestUsers); ++i) { | 45 input_settings_(NULL), |
| 46 test_users_.push_back(AccountId::FromUserEmail(kTestUsers[i])); | 46 keyboard_(NULL) {} |
| 47 } | |
| 48 } | |
| 49 | 47 |
| 50 void SetUpCommandLine(base::CommandLine* command_line) override { | 48 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 51 LoginManagerTest::SetUpCommandLine(command_line); | 49 LoginManagerTest::SetUpCommandLine(command_line); |
| 52 command_line->AppendSwitch(switches::kStubCrosSettings); | 50 command_line->AppendSwitch(switches::kStubCrosSettings); |
| 53 } | 51 } |
| 54 | 52 |
| 55 void SetUpOnMainThread() override { | 53 void SetUpOnMainThread() override { |
| 56 LoginManagerTest::SetUpOnMainThread(); | 54 LoginManagerTest::SetUpOnMainThread(); |
| 57 input_settings_ = new system::FakeInputDeviceSettings(); | 55 input_settings_ = new system::FakeInputDeviceSettings(); |
| 58 system::InputDeviceSettings::SetSettingsForTesting(input_settings_); | 56 system::InputDeviceSettings::SetSettingsForTesting(input_settings_); |
| 59 keyboard_ = new input_method::FakeImeKeyboard(); | 57 keyboard_ = new input_method::FakeImeKeyboard(); |
| 60 static_cast<input_method::InputMethodManagerImpl*>( | 58 static_cast<input_method::InputMethodManagerImpl*>( |
| 61 input_method::InputMethodManager::Get()) | 59 input_method::InputMethodManager::Get()) |
| 62 ->SetImeKeyboardForTesting(keyboard_); | 60 ->SetImeKeyboardForTesting(keyboard_); |
| 63 CrosSettings::Get()->SetString(kDeviceOwner, test_users_[0].GetUserEmail()); | 61 CrosSettings::Get()->SetString(kDeviceOwner, kTestUsers[0]); |
| 64 } | 62 } |
| 65 | 63 |
| 66 // Sets set of preferences in given |prefs|. Value of prefernece depends of | 64 // Sets set of preferences in given |prefs|. Value of prefernece depends of |
| 67 // |variant| value. For opposite |variant| values all preferences receive | 65 // |variant| value. For opposite |variant| values all preferences receive |
| 68 // different values. | 66 // different values. |
| 69 void SetPrefs(PrefService* prefs, bool variant) { | 67 void SetPrefs(PrefService* prefs, bool variant) { |
| 70 prefs->SetBoolean(prefs::kTapToClickEnabled, variant); | 68 prefs->SetBoolean(prefs::kTapToClickEnabled, variant); |
| 71 prefs->SetBoolean(prefs::kPrimaryMouseButtonRight, !variant); | 69 prefs->SetBoolean(prefs::kPrimaryMouseButtonRight, !variant); |
| 72 prefs->SetBoolean(prefs::kTapDraggingEnabled, variant); | 70 prefs->SetBoolean(prefs::kTapDraggingEnabled, variant); |
| 73 prefs->SetBoolean(prefs::kEnableTouchpadThreeFingerClick, !variant); | 71 prefs->SetBoolean(prefs::kEnableTouchpadThreeFingerClick, !variant); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 122 |
| 125 void DisableAnimations() { | 123 void DisableAnimations() { |
| 126 // Disable animations for user transitions. | 124 // Disable animations for user transitions. |
| 127 chrome::MultiUserWindowManagerChromeOS* manager = | 125 chrome::MultiUserWindowManagerChromeOS* manager = |
| 128 static_cast<chrome::MultiUserWindowManagerChromeOS*>( | 126 static_cast<chrome::MultiUserWindowManagerChromeOS*>( |
| 129 chrome::MultiUserWindowManager::GetInstance()); | 127 chrome::MultiUserWindowManager::GetInstance()); |
| 130 manager->SetAnimationSpeedForTest( | 128 manager->SetAnimationSpeedForTest( |
| 131 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); | 129 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); |
| 132 } | 130 } |
| 133 | 131 |
| 134 std::vector<AccountId> test_users_; | |
| 135 | |
| 136 private: | 132 private: |
| 137 system::FakeInputDeviceSettings* input_settings_; | 133 system::FakeInputDeviceSettings* input_settings_; |
| 138 input_method::FakeImeKeyboard* keyboard_; | 134 input_method::FakeImeKeyboard* keyboard_; |
| 139 | 135 |
| 140 DISALLOW_COPY_AND_ASSIGN(PreferencesTest); | 136 DISALLOW_COPY_AND_ASSIGN(PreferencesTest); |
| 141 }; | 137 }; |
| 142 | 138 |
| 143 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) { | 139 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) { |
| 144 RegisterUser(test_users_[0].GetUserEmail()); | 140 RegisterUser(kTestUsers[0]); |
| 145 RegisterUser(test_users_[1].GetUserEmail()); | 141 RegisterUser(kTestUsers[1]); |
| 146 chromeos::StartupUtils::MarkOobeCompleted(); | 142 chromeos::StartupUtils::MarkOobeCompleted(); |
| 147 } | 143 } |
| 148 | 144 |
| 149 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) { | 145 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) { |
| 150 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 146 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 151 | 147 |
| 152 // Add first user and init its preferences. Check that corresponding | 148 // Add first user and init its preferences. Check that corresponding |
| 153 // settings has been changed. | 149 // settings has been changed. |
| 154 LoginUser(test_users_[0].GetUserEmail()); | 150 LoginUser(kTestUsers[0]); |
| 155 const user_manager::User* user1 = user_manager->FindUser(test_users_[0]); | 151 const user_manager::User* user1 = user_manager->FindUser(kTestUsers[0]); |
| 156 PrefService* prefs1 = | 152 PrefService* prefs1 = |
| 157 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs(); | 153 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs(); |
| 158 SetPrefs(prefs1, false); | 154 SetPrefs(prefs1, false); |
| 159 content::RunAllPendingInMessageLoop(); | 155 content::RunAllPendingInMessageLoop(); |
| 160 CheckSettingsCorrespondToPrefs(prefs1); | 156 CheckSettingsCorrespondToPrefs(prefs1); |
| 161 | 157 |
| 162 // Add second user and init its prefs with different values. | 158 // Add second user and init its prefs with different values. |
| 163 UserAddingScreen::Get()->Start(); | 159 UserAddingScreen::Get()->Start(); |
| 164 content::RunAllPendingInMessageLoop(); | 160 content::RunAllPendingInMessageLoop(); |
| 165 DisableAnimations(); | 161 DisableAnimations(); |
| 166 AddUser(test_users_[1].GetUserEmail()); | 162 AddUser(kTestUsers[1]); |
| 167 content::RunAllPendingInMessageLoop(); | 163 content::RunAllPendingInMessageLoop(); |
| 168 const user_manager::User* user2 = user_manager->FindUser(test_users_[1]); | 164 const user_manager::User* user2 = user_manager->FindUser(kTestUsers[1]); |
| 169 EXPECT_TRUE(user2->is_active()); | 165 EXPECT_TRUE(user2->is_active()); |
| 170 PrefService* prefs2 = | 166 PrefService* prefs2 = |
| 171 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs(); | 167 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs(); |
| 172 SetPrefs(prefs2, true); | 168 SetPrefs(prefs2, true); |
| 173 | 169 |
| 174 // Check that settings were changed accordingly. | 170 // Check that settings were changed accordingly. |
| 175 EXPECT_TRUE(user2->is_active()); | 171 EXPECT_TRUE(user2->is_active()); |
| 176 CheckSettingsCorrespondToPrefs(prefs2); | 172 CheckSettingsCorrespondToPrefs(prefs2); |
| 177 | 173 |
| 178 // Check that changing prefs of the active user doesn't affect prefs of the | 174 // Check that changing prefs of the active user doesn't affect prefs of the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 191 prefs_backup = prefs2->GetPreferenceValues(); | 187 prefs_backup = prefs2->GetPreferenceValues(); |
| 192 SetPrefs(prefs1, true); | 188 SetPrefs(prefs1, true); |
| 193 CheckSettingsCorrespondToPrefs(prefs2); | 189 CheckSettingsCorrespondToPrefs(prefs2); |
| 194 EXPECT_TRUE(prefs_backup->Equals(prefs2->GetPreferenceValues().get())); | 190 EXPECT_TRUE(prefs_backup->Equals(prefs2->GetPreferenceValues().get())); |
| 195 SetPrefs(prefs1, false); | 191 SetPrefs(prefs1, false); |
| 196 CheckSettingsCorrespondToPrefs(prefs2); | 192 CheckSettingsCorrespondToPrefs(prefs2); |
| 197 EXPECT_TRUE(prefs_backup->Equals(prefs2->GetPreferenceValues().get())); | 193 EXPECT_TRUE(prefs_backup->Equals(prefs2->GetPreferenceValues().get())); |
| 198 | 194 |
| 199 // Check that changing non-owner prefs doesn't change corresponding local | 195 // Check that changing non-owner prefs doesn't change corresponding local |
| 200 // state prefs and vice versa. | 196 // state prefs and vice versa. |
| 201 EXPECT_EQ(user_manager->GetOwnerAccountId(), test_users_[0]); | 197 EXPECT_EQ(user_manager->GetOwnerEmail(), kTestUsers[0]); |
| 202 CheckLocalStateCorrespondsToPrefs(prefs1); | 198 CheckLocalStateCorrespondsToPrefs(prefs1); |
| 203 prefs2->SetBoolean(prefs::kTapToClickEnabled, | 199 prefs2->SetBoolean(prefs::kTapToClickEnabled, |
| 204 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); | 200 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); |
| 205 CheckLocalStateCorrespondsToPrefs(prefs1); | 201 CheckLocalStateCorrespondsToPrefs(prefs1); |
| 206 prefs1->SetBoolean(prefs::kTapToClickEnabled, | 202 prefs1->SetBoolean(prefs::kTapToClickEnabled, |
| 207 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); | 203 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); |
| 208 CheckLocalStateCorrespondsToPrefs(prefs1); | 204 CheckLocalStateCorrespondsToPrefs(prefs1); |
| 209 | 205 |
| 210 // Switch user back. | 206 // Switch user back. |
| 211 user_manager->SwitchActiveUser(test_users_[0]); | 207 user_manager->SwitchActiveUser(kTestUsers[0]); |
| 212 CheckSettingsCorrespondToPrefs(prefs1); | 208 CheckSettingsCorrespondToPrefs(prefs1); |
| 213 CheckLocalStateCorrespondsToPrefs(prefs1); | 209 CheckLocalStateCorrespondsToPrefs(prefs1); |
| 214 } | 210 } |
| 215 | 211 |
| 216 } // namespace chromeos | 212 } // namespace chromeos |
| OLD | NEW |