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