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

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

Issue 1208963003: Move GN obj files to target-specific dirs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: \ Created 5 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <sys/types.h>
6
7 #include "ash/shell.h"
8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/macros.h"
11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
14 #include "chrome/browser/chromeos/login/login_manager_test.h"
15 #include "chrome/browser/chromeos/login/startup_utils.h"
16 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
17 #include "chrome/browser/chromeos/preferences.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
21 #include "chrome/browser/chromeos/system/fake_input_device_settings.h"
22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
23 #include "chrome/common/pref_names.h"
24 #include "chromeos/chromeos_switches.h"
25 #include "components/feedback/tracing_manager.h"
26 #include "components/user_manager/user_manager.h"
27 #include "content/public/test/test_utils.h"
28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/ime/chromeos/fake_ime_keyboard.h"
30 #include "ui/events/event_utils.h"
31
32 namespace chromeos {
33
34 namespace {
35
36 const char* const kTestUsers[] = {"test-user1@gmail.com",
37 "test-user2@gmail.com"};
38
39 } // namespace
40
41 class PreferencesTest : public LoginManagerTest {
42 public:
43 PreferencesTest()
44 : LoginManagerTest(true),
45 input_settings_(NULL),
46 keyboard_(NULL) {}
47
48 void SetUpCommandLine(base::CommandLine* command_line) override {
49 LoginManagerTest::SetUpCommandLine(command_line);
50 command_line->AppendSwitch(switches::kStubCrosSettings);
51 }
52
53 void SetUpOnMainThread() override {
54 LoginManagerTest::SetUpOnMainThread();
55 input_settings_ = new system::FakeInputDeviceSettings();
56 system::InputDeviceSettings::SetSettingsForTesting(input_settings_);
57 keyboard_ = new input_method::FakeImeKeyboard();
58 static_cast<input_method::InputMethodManagerImpl*>(
59 input_method::InputMethodManager::Get())
60 ->SetImeKeyboardForTesting(keyboard_);
61 CrosSettings::Get()->SetString(kDeviceOwner, kTestUsers[0]);
62 }
63
64 // Sets set of preferences in given |prefs|. Value of prefernece depends of
65 // |variant| value. For opposite |variant| values all preferences receive
66 // different values.
67 void SetPrefs(PrefService* prefs, bool variant) {
68 prefs->SetBoolean(prefs::kTapToClickEnabled, variant);
69 prefs->SetBoolean(prefs::kPrimaryMouseButtonRight, !variant);
70 prefs->SetBoolean(prefs::kTapDraggingEnabled, variant);
71 prefs->SetBoolean(prefs::kEnableTouchpadThreeFingerClick, !variant);
72 prefs->SetBoolean(prefs::kNaturalScroll, variant);
73 prefs->SetInteger(prefs::kMouseSensitivity, !variant);
74 prefs->SetInteger(prefs::kTouchpadSensitivity, variant);
75 prefs->SetBoolean(prefs::kTouchHudProjectionEnabled, !variant);
76 prefs->SetBoolean(prefs::kLanguageXkbAutoRepeatEnabled, variant);
77 prefs->SetInteger(prefs::kLanguageXkbAutoRepeatDelay, variant ? 100 : 500);
78 prefs->SetInteger(prefs::kLanguageXkbAutoRepeatInterval, variant ? 1 : 4);
79 prefs->SetString(prefs::kLanguagePreloadEngines,
80 variant ? "xkb:us::eng,xkb:us:dvorak:eng"
81 : "xkb:us::eng,xkb:ru::rus");
82 }
83
84 void CheckSettingsCorrespondToPrefs(PrefService* prefs) {
85 EXPECT_EQ(prefs->GetBoolean(prefs::kTapToClickEnabled),
86 input_settings_->current_touchpad_settings().GetTapToClick());
87 EXPECT_EQ(prefs->GetBoolean(prefs::kPrimaryMouseButtonRight),
88 input_settings_->current_mouse_settings()
89 .GetPrimaryButtonRight());
90 EXPECT_EQ(prefs->GetBoolean(prefs::kTapDraggingEnabled),
91 input_settings_->current_touchpad_settings().GetTapDragging());
92 EXPECT_EQ(prefs->GetBoolean(prefs::kEnableTouchpadThreeFingerClick),
93 input_settings_->current_touchpad_settings()
94 .GetThreeFingerClick());
95 EXPECT_EQ(prefs->GetInteger(prefs::kMouseSensitivity),
96 input_settings_->current_mouse_settings().GetSensitivity());
97 EXPECT_EQ(prefs->GetInteger(prefs::kTouchpadSensitivity),
98 input_settings_->current_touchpad_settings().GetSensitivity());
99 EXPECT_EQ(prefs->GetBoolean(prefs::kTouchHudProjectionEnabled),
100 ash::Shell::GetInstance()->is_touch_hud_projection_enabled());
101 EXPECT_EQ(prefs->GetBoolean(prefs::kLanguageXkbAutoRepeatEnabled),
102 keyboard_->auto_repeat_is_enabled_);
103 input_method::AutoRepeatRate rate = keyboard_->last_auto_repeat_rate_;
104 EXPECT_EQ(prefs->GetInteger(prefs::kLanguageXkbAutoRepeatDelay),
105 (int)rate.initial_delay_in_ms);
106 EXPECT_EQ(prefs->GetInteger(prefs::kLanguageXkbAutoRepeatInterval),
107 (int)rate.repeat_interval_in_ms);
108 EXPECT_EQ(prefs->GetString(prefs::kLanguageCurrentInputMethod),
109 input_method::InputMethodManager::Get()
110 ->GetActiveIMEState()
111 ->GetCurrentInputMethod()
112 .id());
113 }
114
115 void CheckLocalStateCorrespondsToPrefs(PrefService* prefs) {
116 PrefService* local_state = g_browser_process->local_state();
117 EXPECT_EQ(local_state->GetBoolean(prefs::kOwnerTapToClickEnabled),
118 prefs->GetBoolean(prefs::kTapToClickEnabled));
119 EXPECT_EQ(local_state->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight),
120 prefs->GetBoolean(prefs::kPrimaryMouseButtonRight));
121 }
122
123 void DisableAnimations() {
124 // Disable animations for user transitions.
125 chrome::MultiUserWindowManagerChromeOS* manager =
126 static_cast<chrome::MultiUserWindowManagerChromeOS*>(
127 chrome::MultiUserWindowManager::GetInstance());
128 manager->SetAnimationSpeedForTest(
129 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
130 }
131
132 private:
133 system::FakeInputDeviceSettings* input_settings_;
134 input_method::FakeImeKeyboard* keyboard_;
135
136 DISALLOW_COPY_AND_ASSIGN(PreferencesTest);
137 };
138
139 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) {
140 RegisterUser(kTestUsers[0]);
141 RegisterUser(kTestUsers[1]);
142 chromeos::StartupUtils::MarkOobeCompleted();
143 }
144
145 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) {
146 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
147
148 // Add first user and init its preferences. Check that corresponding
149 // settings has been changed.
150 LoginUser(kTestUsers[0]);
151 const user_manager::User* user1 = user_manager->FindUser(kTestUsers[0]);
152 PrefService* prefs1 =
153 ProfileHelper::Get()->GetProfileByUserUnsafe(user1)->GetPrefs();
154 SetPrefs(prefs1, false);
155 content::RunAllPendingInMessageLoop();
156 CheckSettingsCorrespondToPrefs(prefs1);
157
158 // Add second user and init its prefs with different values.
159 UserAddingScreen::Get()->Start();
160 content::RunAllPendingInMessageLoop();
161 DisableAnimations();
162 AddUser(kTestUsers[1]);
163 content::RunAllPendingInMessageLoop();
164 const user_manager::User* user2 = user_manager->FindUser(kTestUsers[1]);
165 EXPECT_TRUE(user2->is_active());
166 PrefService* prefs2 =
167 ProfileHelper::Get()->GetProfileByUserUnsafe(user2)->GetPrefs();
168 SetPrefs(prefs2, true);
169
170 // Check that settings were changed accordingly.
171 EXPECT_TRUE(user2->is_active());
172 CheckSettingsCorrespondToPrefs(prefs2);
173
174 // Check that changing prefs of the active user doesn't affect prefs of the
175 // inactive user.
176 scoped_ptr<base::DictionaryValue> prefs_backup =
177 prefs1->GetPreferenceValues();
178 SetPrefs(prefs2, false);
179 CheckSettingsCorrespondToPrefs(prefs2);
180 EXPECT_TRUE(prefs_backup->Equals(prefs1->GetPreferenceValues().get()));
181 SetPrefs(prefs2, true);
182 CheckSettingsCorrespondToPrefs(prefs2);
183 EXPECT_TRUE(prefs_backup->Equals(prefs1->GetPreferenceValues().get()));
184
185 // Check that changing prefs of the inactive user doesn't affect prefs of the
186 // active user.
187 prefs_backup = prefs2->GetPreferenceValues();
188 SetPrefs(prefs1, true);
189 CheckSettingsCorrespondToPrefs(prefs2);
190 EXPECT_TRUE(prefs_backup->Equals(prefs2->GetPreferenceValues().get()));
191 SetPrefs(prefs1, false);
192 CheckSettingsCorrespondToPrefs(prefs2);
193 EXPECT_TRUE(prefs_backup->Equals(prefs2->GetPreferenceValues().get()));
194
195 // Check that changing non-owner prefs doesn't change corresponding local
196 // state prefs and vice versa.
197 EXPECT_EQ(user_manager->GetOwnerEmail(), kTestUsers[0]);
198 CheckLocalStateCorrespondsToPrefs(prefs1);
199 prefs2->SetBoolean(prefs::kTapToClickEnabled,
200 !prefs1->GetBoolean(prefs::kTapToClickEnabled));
201 CheckLocalStateCorrespondsToPrefs(prefs1);
202 prefs1->SetBoolean(prefs::kTapToClickEnabled,
203 !prefs1->GetBoolean(prefs::kTapToClickEnabled));
204 CheckLocalStateCorrespondsToPrefs(prefs1);
205
206 // Switch user back.
207 user_manager->SwitchActiveUser(kTestUsers[0]);
208 CheckSettingsCorrespondToPrefs(prefs1);
209 CheckLocalStateCorrespondsToPrefs(prefs1);
210 }
211
212 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698