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

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

Issue 270563002: Componentize LoginManagerTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 <sys/types.h> 5 #include <sys/types.h>
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" 12 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
13 #include "chrome/browser/chromeos/login/login_manager_test.h" 13 #include "chrome/browser/chromeos/login/login_manager_test_helper.h"
14 #include "chrome/browser/chromeos/login/startup_utils.h" 14 #include "chrome/browser/chromeos/login/startup_utils.h"
15 #include "chrome/browser/chromeos/login/user_adding_screen.h" 15 #include "chrome/browser/chromeos/login/user_adding_screen.h"
16 #include "chrome/browser/chromeos/preferences.h" 16 #include "chrome/browser/chromeos/preferences.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
19 #include "chrome/browser/chromeos/system/fake_input_device_settings.h" 19 #include "chrome/browser/chromeos/system/fake_input_device_settings.h"
20 #include "chrome/browser/feedback/tracing_manager.h" 20 #include "chrome/browser/feedback/tracing_manager.h"
21 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 21 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
22 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chromeos/chromeos_switches.h" 25 #include "chromeos/chromeos_switches.h"
25 #include "chromeos/ime/fake_ime_keyboard.h" 26 #include "chromeos/ime/fake_ime_keyboard.h"
26 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/events/event_utils.h" 29 #include "ui/events/event_utils.h"
29 30
30 namespace chromeos { 31 namespace chromeos {
31 32
32 namespace { 33 namespace {
33 34
34 const char* kTestUsers[] = {"test-user1@gmail.com", "test-user2@gmail.com"}; 35 const char* kTestUsers[] = {"test-user1@gmail.com", "test-user2@gmail.com"};
35 36
36 } // namespace 37 } // namespace
37 38
38 class PreferencesTest : public LoginManagerTest { 39 class PreferencesTest : public InProcessBrowserTest {
39 public: 40 public:
40 PreferencesTest() 41 PreferencesTest()
41 : LoginManagerTest(true), 42 : login_manager_test_helper_(new LoginManagerTestHelper(true)),
42 input_settings_(NULL), 43 input_settings_(NULL),
43 keyboard_(NULL) {} 44 keyboard_(NULL) {
45 set_exit_when_last_browser_closes(false);
46 }
44 47
45 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 48 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
46 LoginManagerTest::SetUpCommandLine(command_line); 49 login_manager_test_helper_->SetUpCommandLine(command_line);
47 command_line->AppendSwitch(::switches::kMultiProfiles); 50 command_line->AppendSwitch(::switches::kMultiProfiles);
48 command_line->AppendSwitch(switches::kStubCrosSettings); 51 command_line->AppendSwitch(switches::kStubCrosSettings);
49 } 52 }
50 53
51 virtual void SetUpOnMainThread() OVERRIDE { 54 virtual void SetUpOnMainThread() OVERRIDE {
52 LoginManagerTest::SetUpOnMainThread(); 55 login_manager_test_helper_->SetUp();
53 input_settings_ = new system::FakeInputDeviceSettings(); 56 input_settings_ = new system::FakeInputDeviceSettings();
54 system::InputDeviceSettings::SetSettingsForTesting(input_settings_); 57 system::InputDeviceSettings::SetSettingsForTesting(input_settings_);
55 keyboard_ = new input_method::FakeImeKeyboard(); 58 keyboard_ = new input_method::FakeImeKeyboard();
56 static_cast<input_method::InputMethodManagerImpl*>( 59 static_cast<input_method::InputMethodManagerImpl*>(
57 input_method::InputMethodManager::Get()) 60 input_method::InputMethodManager::Get())
58 ->SetImeKeyboardForTesting(keyboard_); 61 ->SetImeKeyboardForTesting(keyboard_);
59 CrosSettings::Get()->SetString(kDeviceOwner, kTestUsers[0]); 62 CrosSettings::Get()->SetString(kDeviceOwner, kTestUsers[0]);
60 } 63 }
61 64
65 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
66 login_manager_test_helper_->SetUpLoginUtils();
67 }
68
69 virtual void CleanUpOnMainThread() OVERRIDE {
70 login_manager_test_helper_->CleanUp();
71 }
72
62 // Sets set of preferences in given |prefs|. Value of prefernece depends of 73 // Sets set of preferences in given |prefs|. Value of prefernece depends of
63 // |variant| value. For opposite |variant| values all preferences receive 74 // |variant| value. For opposite |variant| values all preferences receive
64 // different values. 75 // different values.
65 void SetPrefs(PrefService* prefs, bool variant) { 76 void SetPrefs(PrefService* prefs, bool variant) {
66 prefs->SetBoolean(prefs::kTapToClickEnabled, variant); 77 prefs->SetBoolean(prefs::kTapToClickEnabled, variant);
67 prefs->SetBoolean(prefs::kPrimaryMouseButtonRight, !variant); 78 prefs->SetBoolean(prefs::kPrimaryMouseButtonRight, !variant);
68 prefs->SetBoolean(prefs::kTapDraggingEnabled, variant); 79 prefs->SetBoolean(prefs::kTapDraggingEnabled, variant);
69 prefs->SetBoolean(prefs::kEnableTouchpadThreeFingerClick, !variant); 80 prefs->SetBoolean(prefs::kEnableTouchpadThreeFingerClick, !variant);
70 prefs->SetBoolean(prefs::kNaturalScroll, variant); 81 prefs->SetBoolean(prefs::kNaturalScroll, variant);
71 prefs->SetInteger(prefs::kMouseSensitivity, !variant); 82 prefs->SetInteger(prefs::kMouseSensitivity, !variant);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 129
119 void DisableAnimations() { 130 void DisableAnimations() {
120 // Disable animations for user transitions. 131 // Disable animations for user transitions.
121 chrome::MultiUserWindowManagerChromeOS* manager = 132 chrome::MultiUserWindowManagerChromeOS* manager =
122 static_cast<chrome::MultiUserWindowManagerChromeOS*>( 133 static_cast<chrome::MultiUserWindowManagerChromeOS*>(
123 chrome::MultiUserWindowManager::GetInstance()); 134 chrome::MultiUserWindowManager::GetInstance());
124 manager->SetAnimationSpeedForTest( 135 manager->SetAnimationSpeedForTest(
125 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 136 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
126 } 137 }
127 138
139 protected:
140 scoped_ptr<LoginManagerTestHelper> login_manager_test_helper_;
141
128 private: 142 private:
129 system::FakeInputDeviceSettings* input_settings_; 143 system::FakeInputDeviceSettings* input_settings_;
130 input_method::FakeImeKeyboard* keyboard_; 144 input_method::FakeImeKeyboard* keyboard_;
131 145
132 DISALLOW_COPY_AND_ASSIGN(PreferencesTest); 146 DISALLOW_COPY_AND_ASSIGN(PreferencesTest);
133 }; 147 };
134 148
135 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) { 149 IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) {
136 RegisterUser(kTestUsers[0]); 150 login_manager_test_helper_->RegisterUser(kTestUsers[0]);
137 RegisterUser(kTestUsers[1]); 151 login_manager_test_helper_->RegisterUser(kTestUsers[1]);
138 chromeos::StartupUtils::MarkOobeCompleted(); 152 chromeos::StartupUtils::MarkOobeCompleted();
139 } 153 }
140 154
141 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) { 155 IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) {
142 UserManager* user_manager = UserManager::Get(); 156 UserManager* user_manager = UserManager::Get();
143 157
144 // Add first user and init its preferences. Check that corresponding 158 // Add first user and init its preferences. Check that corresponding
145 // settings has been changed. 159 // settings has been changed.
146 LoginUser(kTestUsers[0]); 160 login_manager_test_helper_->LogInUser(kTestUsers[0]);
147 const User* user1 = user_manager->FindUser(kTestUsers[0]); 161 const User* user1 = user_manager->FindUser(kTestUsers[0]);
148 PrefService* prefs1 = user_manager->GetProfileByUser(user1)->GetPrefs(); 162 PrefService* prefs1 = user_manager->GetProfileByUser(user1)->GetPrefs();
149 SetPrefs(prefs1, false); 163 SetPrefs(prefs1, false);
150 content::RunAllPendingInMessageLoop(); 164 content::RunAllPendingInMessageLoop();
151 CheckSettingsCorrespondToPrefs(prefs1); 165 CheckSettingsCorrespondToPrefs(prefs1);
152 166
153 // Add second user and init its prefs with different values. 167 // Add second user and init its prefs with different values.
154 UserAddingScreen::Get()->Start(); 168 UserAddingScreen::Get()->Start();
155 content::RunAllPendingInMessageLoop(); 169 content::RunAllPendingInMessageLoop();
156 DisableAnimations(); 170 DisableAnimations();
157 AddUser(kTestUsers[1]); 171 login_manager_test_helper_->AddUser(kTestUsers[1]);
158 content::RunAllPendingInMessageLoop(); 172 content::RunAllPendingInMessageLoop();
159 const User* user2 = user_manager->FindUser(kTestUsers[1]); 173 const User* user2 = user_manager->FindUser(kTestUsers[1]);
160 EXPECT_TRUE(user2->is_active()); 174 EXPECT_TRUE(user2->is_active());
161 PrefService* prefs2 = user_manager->GetProfileByUser(user2)->GetPrefs(); 175 PrefService* prefs2 = user_manager->GetProfileByUser(user2)->GetPrefs();
162 SetPrefs(prefs2, true); 176 SetPrefs(prefs2, true);
163 177
164 // Check that settings were changed accordingly. 178 // Check that settings were changed accordingly.
165 EXPECT_TRUE(user2->is_active()); 179 EXPECT_TRUE(user2->is_active());
166 CheckSettingsCorrespondToPrefs(prefs2); 180 CheckSettingsCorrespondToPrefs(prefs2);
167 181
(...skipping 29 matching lines...) Expand all
197 !prefs1->GetBoolean(prefs::kTapToClickEnabled)); 211 !prefs1->GetBoolean(prefs::kTapToClickEnabled));
198 CheckLocalStateCorrespondsToPrefs(prefs1); 212 CheckLocalStateCorrespondsToPrefs(prefs1);
199 213
200 // Switch user back. 214 // Switch user back.
201 user_manager->SwitchActiveUser(kTestUsers[0]); 215 user_manager->SwitchActiveUser(kTestUsers[0]);
202 CheckSettingsCorrespondToPrefs(prefs1); 216 CheckSettingsCorrespondToPrefs(prefs1);
203 CheckLocalStateCorrespondsToPrefs(prefs1); 217 CheckLocalStateCorrespondsToPrefs(prefs1);
204 } 218 }
205 219
206 } // namespace chromeos 220 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698