OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" |
6 #include "base/command_line.h" | 10 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 11 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/location.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" |
| 18 #include "base/stl_util.h" |
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 19 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
10 #include "chrome/browser/chromeos/cros/cros_mock.h" | 20 #include "chrome/browser/chromeos/cros/cros_mock.h" |
11 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 21 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
| 22 #include "chrome/browser/chromeos/login/authenticator.h" |
12 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 23 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
13 #include "chrome/browser/chromeos/login/helper.h" | 24 #include "chrome/browser/chromeos/login/helper.h" |
14 #include "chrome/browser/chromeos/login/login_display.h" | |
15 #include "chrome/browser/chromeos/login/login_display_host.h" | |
16 #include "chrome/browser/chromeos/login/login_performer.h" | |
17 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 25 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
18 #include "chrome/browser/chromeos/login/login_utils.h" | |
19 #include "chrome/browser/chromeos/login/mock_authenticator.h" | 26 #include "chrome/browser/chromeos/login/mock_authenticator.h" |
| 27 #include "chrome/browser/chromeos/login/mock_login_display.h" |
| 28 #include "chrome/browser/chromeos/login/mock_login_display_host.h" |
20 #include "chrome/browser/chromeos/login/mock_login_utils.h" | 29 #include "chrome/browser/chromeos/login/mock_login_utils.h" |
21 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 30 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
22 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 31 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 32 #include "chrome/browser/chromeos/login/user_manager.h" |
23 #include "chrome/browser/chromeos/login/wizard_controller.h" | 33 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 34 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| 35 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
| 36 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 37 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 38 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 39 #include "chrome/browser/policy/browser_policy_connector.h" |
| 40 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 41 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
| 42 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 43 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| 44 #include "chrome/browser/policy/cloud/policy_builder.h" |
| 45 #include "chrome/common/chrome_notification_types.h" |
| 46 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/test/base/testing_browser_process.h" |
25 #include "chrome/test/base/testing_profile.h" | 49 #include "chrome/test/base/testing_profile.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 50 #include "chrome/test/base/ui_test_utils.h" |
| 51 #include "chromeos/dbus/fake_session_manager_client.h" |
27 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 52 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
28 #include "chromeos/dbus/mock_session_manager_client.h" | 53 #include "chromeos/dbus/mock_session_manager_client.h" |
29 #include "chromeos/dbus/mock_shill_manager_client.h" | 54 #include "chromeos/dbus/mock_shill_manager_client.h" |
30 #include "chromeos/dbus/mock_update_engine_client.h" | 55 #include "chromeos/dbus/mock_update_engine_client.h" |
| 56 #include "content/public/browser/notification_details.h" |
| 57 #include "content/public/test/mock_notification_observer.h" |
| 58 #include "content/public/test/test_utils.h" |
| 59 #include "crypto/rsa_private_key.h" |
31 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 60 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
32 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 62 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 63 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "ui/base/l10n/l10n_util.h" | 64 #include "ui/base/l10n/l10n_util.h" |
36 | 65 |
37 using ::testing::_; | 66 using ::testing::_; |
38 using ::testing::AnyNumber; | 67 using ::testing::AnyNumber; |
39 using ::testing::AnyOf; | 68 using ::testing::AnyOf; |
40 using ::testing::Invoke; | 69 using ::testing::Invoke; |
41 using ::testing::InvokeWithoutArgs; | 70 using ::testing::InvokeWithoutArgs; |
42 using ::testing::Return; | 71 using ::testing::Return; |
43 using ::testing::ReturnNull; | 72 using ::testing::ReturnNull; |
44 using ::testing::Sequence; | 73 using ::testing::Sequence; |
45 using ::testing::WithArg; | 74 using ::testing::WithArg; |
46 | 75 |
| 76 namespace em = enterprise_management; |
| 77 |
47 namespace chromeos { | 78 namespace chromeos { |
48 | 79 |
49 namespace { | 80 namespace { |
50 | 81 |
51 const char kUsername[] = "test_user@gmail.com"; | 82 const char kUsername[] = "test_user@gmail.com"; |
52 const char kNewUsername[] = "test_new_user@gmail.com"; | 83 const char kNewUsername[] = "test_new_user@gmail.com"; |
53 const char kPassword[] = "test_password"; | 84 const char kPassword[] = "test_password"; |
54 | 85 |
55 class MockLoginDisplay : public LoginDisplay { | 86 const char kAutoLoginUsername[] = "public_session_user@localhost"; |
56 public: | 87 const int kAutoLoginNoDelay = 0; |
57 MockLoginDisplay() | 88 const int kAutoLoginShortDelay = 1; |
58 : LoginDisplay(NULL, gfx::Rect()) { | 89 const int kAutoLoginLongDelay = 10000; |
59 } | |
60 | |
61 MOCK_METHOD4(Init, void(const UserList&, bool, bool, bool)); | |
62 MOCK_METHOD0(OnPreferencesChanged, void(void)); | |
63 MOCK_METHOD1(OnUserImageChanged, void(const User&)); | |
64 MOCK_METHOD0(OnFadeOut, void(void)); | |
65 MOCK_METHOD1(OnLoginSuccess, void(const std::string&)); | |
66 MOCK_METHOD1(SetUIEnabled, void(bool)); | |
67 MOCK_METHOD1(SelectPod, void(int)); | |
68 MOCK_METHOD3(ShowError, void(int, int, HelpAppLauncher::HelpTopic)); | |
69 MOCK_METHOD1(ShowErrorScreen, void(LoginDisplay::SigninError)); | |
70 MOCK_METHOD1(ShowGaiaPasswordChanged, void(const std::string&)); | |
71 MOCK_METHOD1(ShowPasswordChangedDialog, void(bool)); | |
72 MOCK_METHOD1(ShowSigninUI, void(const std::string&)); | |
73 MOCK_METHOD1(OnBeforeUserRemoved, void(const std::string&)); | |
74 MOCK_METHOD1(OnUserRemoved, void(const std::string&)); | |
75 | |
76 private: | |
77 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplay); | |
78 }; | |
79 | |
80 class MockLoginDisplayHost : public LoginDisplayHost { | |
81 public: | |
82 MockLoginDisplayHost() { | |
83 } | |
84 | |
85 MOCK_METHOD1(CreateLoginDisplay, LoginDisplay*(LoginDisplay::Delegate*)); | |
86 MOCK_CONST_METHOD0(GetNativeWindow, gfx::NativeWindow(void)); | |
87 MOCK_CONST_METHOD0(GetWidget, views::Widget*(void)); | |
88 MOCK_METHOD0(BeforeSessionStart, void(void)); | |
89 MOCK_METHOD0(OnSessionStart, void(void)); | |
90 MOCK_METHOD0(OnCompleteLogin, void(void)); | |
91 MOCK_METHOD0(OpenProxySettings, void(void)); | |
92 MOCK_METHOD1(SetOobeProgressBarVisible, void(bool)); | |
93 MOCK_METHOD1(SetShutdownButtonEnabled, void(bool)); | |
94 MOCK_METHOD1(SetStatusAreaVisible, void(bool)); | |
95 MOCK_METHOD0(ShowBackground, void(void)); | |
96 MOCK_METHOD0(CheckForAutoEnrollment, void(void)); | |
97 MOCK_METHOD2(StartWizard, void(const std::string&, DictionaryValue*)); | |
98 MOCK_METHOD0(StartSignInScreen, void(void)); | |
99 MOCK_METHOD0(ResumeSignInScreen, void(void)); | |
100 MOCK_METHOD0(OnPreferencesChanged, void(void)); | |
101 | |
102 private: | |
103 DISALLOW_COPY_AND_ASSIGN(MockLoginDisplayHost); | |
104 }; | |
105 | 90 |
106 scoped_refptr<Authenticator> CreateAuthenticator( | 91 scoped_refptr<Authenticator> CreateAuthenticator( |
107 LoginStatusConsumer* consumer) { | 92 LoginStatusConsumer* consumer) { |
108 return new MockAuthenticator(consumer, kUsername, kPassword); | 93 return new MockAuthenticator(consumer, kUsername, kPassword); |
109 } | 94 } |
110 | 95 |
111 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( | 96 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( |
112 LoginStatusConsumer* consumer) { | 97 LoginStatusConsumer* consumer) { |
113 return new MockAuthenticator(consumer, kNewUsername, kPassword); | 98 return new MockAuthenticator(consumer, kNewUsername, kPassword); |
114 } | 99 } |
115 | 100 |
| 101 scoped_refptr<Authenticator> CreateAuthenticatorForPublicSession( |
| 102 LoginStatusConsumer* consumer) { |
| 103 return new MockAuthenticator(consumer, kAutoLoginUsername, ""); |
| 104 } |
| 105 |
| 106 // Observes a specific notification type and quits the message loop once a |
| 107 // condition holds. |
| 108 class NotificationWatcher : public content::NotificationObserver { |
| 109 public: |
| 110 // Callback invoked on notifications. Should return true when the condition |
| 111 // that the caller is waiting for is satisfied. |
| 112 typedef base::Callback<bool(void)> ConditionTestCallback; |
| 113 |
| 114 explicit NotificationWatcher(int notification_type, |
| 115 const ConditionTestCallback& callback) |
| 116 : type_(notification_type), |
| 117 callback_(callback) {} |
| 118 |
| 119 void Run() { |
| 120 if (callback_.Run()) |
| 121 return; |
| 122 |
| 123 content::NotificationRegistrar registrar; |
| 124 registrar.Add(this, type_, content::NotificationService::AllSources()); |
| 125 run_loop_.Run(); |
| 126 } |
| 127 |
| 128 // content::NotificationObserver: |
| 129 virtual void Observe(int type, |
| 130 const content::NotificationSource& source, |
| 131 const content::NotificationDetails& details) OVERRIDE { |
| 132 if (callback_.Run()) |
| 133 run_loop_.Quit(); |
| 134 } |
| 135 |
| 136 private: |
| 137 int type_; |
| 138 ConditionTestCallback callback_; |
| 139 base::RunLoop run_loop_; |
| 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); |
| 142 }; |
| 143 |
116 } // namespace | 144 } // namespace |
117 | 145 |
118 class ExistingUserControllerTest : public CrosInProcessBrowserTest { | 146 class ExistingUserControllerTest : public CrosInProcessBrowserTest { |
119 protected: | 147 protected: |
120 ExistingUserControllerTest() | 148 ExistingUserControllerTest() |
121 : mock_network_library_(NULL), | 149 : mock_network_library_(NULL), |
122 mock_login_display_(NULL), | 150 mock_login_display_(NULL), |
123 mock_login_display_host_(NULL), | 151 mock_login_display_host_(NULL), |
124 testing_profile_(NULL) { | 152 testing_profile_(NULL) { |
125 } | 153 } |
126 | 154 |
127 ExistingUserController* existing_user_controller() { | 155 ExistingUserController* existing_user_controller() { |
128 return ExistingUserController::current_controller(); | 156 return ExistingUserController::current_controller(); |
129 } | 157 } |
130 | 158 |
| 159 const ExistingUserController* existing_user_controller() const { |
| 160 return ExistingUserController::current_controller(); |
| 161 } |
| 162 |
131 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 163 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
132 MockDBusThreadManager* mock_dbus_thread_manager = | 164 MockDBusThreadManager* mock_dbus_thread_manager = |
133 new MockDBusThreadManager; | 165 new MockDBusThreadManager; |
134 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | 166 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) |
135 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 167 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
136 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) | 168 EXPECT_CALL(*mock_dbus_thread_manager, GetIBusInputContextClient()) |
137 .WillRepeatedly( | 169 .WillRepeatedly( |
138 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); | 170 Return(reinterpret_cast<IBusInputContextClient*>(NULL))); |
139 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 171 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), |
140 GetProperties(_)) | 172 GetProperties(_)) |
141 .Times(AnyNumber()); | 173 .Times(AnyNumber()); |
142 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 174 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), |
143 AddPropertyChangedObserver(_)) | 175 AddPropertyChangedObserver(_)) |
144 .Times(AnyNumber()); | 176 .Times(AnyNumber()); |
145 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), | 177 EXPECT_CALL(*mock_dbus_thread_manager->mock_shill_manager_client(), |
146 RemovePropertyChangedObserver(_)) | 178 RemovePropertyChangedObserver(_)) |
147 .Times(AnyNumber()); | 179 .Times(AnyNumber()); |
148 EXPECT_CALL(*mock_dbus_thread_manager->mock_update_engine_client(), | 180 EXPECT_CALL(*mock_dbus_thread_manager->mock_update_engine_client(), |
149 GetLastStatus()) | 181 GetLastStatus()) |
150 .Times(1) | 182 .Times(1) |
151 .WillOnce(Return(MockUpdateEngineClient::Status())); | 183 .WillOnce(Return(MockUpdateEngineClient::Status())); |
| 184 |
| 185 SetUpSessionManager(mock_dbus_thread_manager); |
| 186 |
152 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 187 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
153 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 188 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
154 cros_mock_->InitStatusAreaMocks(); | 189 cros_mock_->InitStatusAreaMocks(); |
155 cros_mock_->SetStatusAreaMocksExpectations(); | 190 cros_mock_->SetStatusAreaMocksExpectations(); |
156 | 191 |
157 mock_network_library_ = cros_mock_->mock_network_library(); | 192 mock_network_library_ = cros_mock_->mock_network_library(); |
158 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) | 193 EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) |
159 .Times(AnyNumber()); | 194 .Times(AnyNumber()); |
160 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) | 195 EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _)) |
161 .WillRepeatedly(Return(true)); | 196 .WillRepeatedly(Return(true)); |
162 | 197 |
163 MockSessionManagerClient* mock_session_manager_client = | |
164 mock_dbus_thread_manager->mock_session_manager_client(); | |
165 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) | |
166 .Times(1); | |
167 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) | |
168 .Times(AnyNumber()); | |
169 | |
170 mock_login_utils_ = new MockLoginUtils(); | 198 mock_login_utils_ = new MockLoginUtils(); |
171 LoginUtils::Set(mock_login_utils_); | 199 LoginUtils::Set(mock_login_utils_); |
172 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) | 200 EXPECT_CALL(*mock_login_utils_, PrewarmAuthentication()) |
173 .Times(AnyNumber()); | 201 .Times(AnyNumber()); |
174 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) | 202 EXPECT_CALL(*mock_login_utils_, StopBackgroundFetchers()) |
175 .Times(AnyNumber()); | 203 .Times(AnyNumber()); |
176 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) | 204 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) |
177 .Times(1); | 205 .Times(1); |
178 | 206 |
179 mock_login_display_host_.reset(new MockLoginDisplayHost()); | 207 mock_login_display_host_.reset(new MockLoginDisplayHost()); |
| 208 mock_login_display_ = new MockLoginDisplay(); |
| 209 SetUpLoginDisplay(); |
| 210 } |
180 | 211 |
181 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kUsername)) | 212 virtual void SetUpSessionManager( |
| 213 MockDBusThreadManager* mock_dbus_thread_manager) { |
| 214 mock_user_manager_.reset(new ScopedMockUserManagerEnabler); |
| 215 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kUsername)) |
182 .Times(AnyNumber()) | 216 .Times(AnyNumber()) |
183 .WillRepeatedly(Return(true)); | 217 .WillRepeatedly(Return(true)); |
184 EXPECT_CALL(*mock_user_manager_.user_manager(), IsKnownUser(kNewUsername)) | 218 EXPECT_CALL(*mock_user_manager_->user_manager(), IsKnownUser(kNewUsername)) |
185 .Times(AnyNumber()) | 219 .Times(AnyNumber()) |
186 .WillRepeatedly(Return(false)); | 220 .WillRepeatedly(Return(false)); |
187 EXPECT_CALL(*mock_user_manager_.user_manager(), IsUserLoggedIn()) | 221 EXPECT_CALL(*mock_user_manager_->user_manager(), IsUserLoggedIn()) |
188 .Times(AnyNumber()) | 222 .Times(AnyNumber()) |
189 .WillRepeatedly(Return(false)); | 223 .WillRepeatedly(Return(false)); |
190 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsGuest()) | 224 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsGuest()) |
191 .Times(AnyNumber()) | 225 .Times(AnyNumber()) |
192 .WillRepeatedly(Return(false)); | 226 .WillRepeatedly(Return(false)); |
193 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsDemoUser()) | 227 EXPECT_CALL(*mock_user_manager_->user_manager(), IsLoggedInAsDemoUser()) |
194 .Times(AnyNumber()) | 228 .Times(AnyNumber()) |
195 .WillRepeatedly(Return(false)); | 229 .WillRepeatedly(Return(false)); |
196 EXPECT_CALL(*mock_user_manager_.user_manager(), IsLoggedInAsPublicAccount()) | 230 EXPECT_CALL(*mock_user_manager_->user_manager(), |
| 231 IsLoggedInAsPublicAccount()) |
197 .Times(AnyNumber()) | 232 .Times(AnyNumber()) |
198 .WillRepeatedly(Return(false)); | 233 .WillRepeatedly(Return(false)); |
199 EXPECT_CALL(*mock_user_manager_.user_manager(), IsSessionStarted()) | 234 EXPECT_CALL(*mock_user_manager_->user_manager(), IsSessionStarted()) |
200 .Times(AnyNumber()) | 235 .Times(AnyNumber()) |
201 .WillRepeatedly(Return(false)); | 236 .WillRepeatedly(Return(false)); |
| 237 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
| 238 .Times(AnyNumber()) |
| 239 .WillRepeatedly(Return(false)); |
| 240 EXPECT_CALL(*mock_user_manager_->user_manager(), Shutdown()) |
| 241 .Times(1); |
202 | 242 |
203 // |mock_login_display_| is owned by the ExistingUserController, which calls | 243 MockSessionManagerClient* mock_session_manager_client = |
204 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. | 244 mock_dbus_thread_manager->mock_session_manager_client(); |
205 mock_login_display_ = new MockLoginDisplay(); | 245 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) |
| 246 .Times(1); |
| 247 EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) |
| 248 .Times(AnyNumber()); |
| 249 } |
| 250 |
| 251 virtual void SetUpLoginDisplay() { |
206 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 252 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
207 .Times(1) | 253 .Times(1) |
208 .WillOnce(Return(mock_login_display_)); | 254 .WillOnce(Return(mock_login_display_)); |
209 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 255 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
210 .Times(1) | 256 .Times(1) |
211 .WillOnce(ReturnNull()); | 257 .WillOnce(ReturnNull()); |
212 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 258 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
213 .Times(1); | 259 .Times(1); |
214 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) | 260 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) |
215 .Times(1); | 261 .Times(1); |
216 } | 262 } |
217 | 263 |
218 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 264 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
219 command_line->AppendSwitch(switches::kLoginManager); | 265 command_line->AppendSwitch(switches::kLoginManager); |
220 } | 266 } |
221 | 267 |
222 virtual void SetUpOnMainThread() OVERRIDE { | 268 virtual void SetUpOnMainThread() OVERRIDE { |
223 testing_profile_.reset(new TestingProfile()); | 269 testing_profile_.reset(new TestingProfile()); |
224 existing_user_controller_.reset( | 270 existing_user_controller_.reset( |
225 new ExistingUserController(mock_login_display_host_.get())); | 271 new ExistingUserController(mock_login_display_host_.get())); |
226 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); | 272 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); |
227 existing_user_controller_->Init(UserList()); | 273 existing_user_controller_->Init(UserList()); |
228 profile_prepared_cb_ = | 274 profile_prepared_cb_ = |
229 base::Bind(&ExistingUserController::OnProfilePrepared, | 275 base::Bind(&ExistingUserController::OnProfilePrepared, |
230 base::Unretained(existing_user_controller()), | 276 base::Unretained(existing_user_controller()), |
231 testing_profile_.get()); | 277 testing_profile_.get()); |
232 } | 278 } |
233 | 279 |
234 virtual void CleanUpOnMainThread() OVERRIDE { | 280 virtual void CleanUpOnMainThread() OVERRIDE { |
| 281 // ExistingUserController must be deleted before the thread is cleaned up: |
| 282 // If there is an outstanding login attempt when ExistingUserController is |
| 283 // deleted, its LoginPerformer instance will be deleted, which in turn |
| 284 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must |
| 285 // be deleted on the UI thread. |
| 286 existing_user_controller_.reset(); |
235 CrosInProcessBrowserTest::CleanUpOnMainThread(); | 287 CrosInProcessBrowserTest::CleanUpOnMainThread(); |
236 testing_profile_.reset(NULL); | 288 testing_profile_.reset(NULL); |
237 } | 289 } |
238 | 290 |
239 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 291 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
240 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 292 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
241 DBusThreadManager::Shutdown(); | 293 DBusThreadManager::Shutdown(); |
242 } | 294 } |
243 | 295 |
| 296 // ExistingUserController private member accessors. |
| 297 base::OneShotTimer<ExistingUserController>* auto_login_timer() { |
| 298 return existing_user_controller()->auto_login_timer_.get(); |
| 299 } |
| 300 |
| 301 const std::string& auto_login_username() const { |
| 302 return existing_user_controller()->public_session_auto_login_username_; |
| 303 } |
| 304 |
| 305 int auto_login_delay() const { |
| 306 return existing_user_controller()->public_session_auto_login_delay_; |
| 307 } |
| 308 |
| 309 bool is_login_in_progress() const { |
| 310 return existing_user_controller()->is_login_in_progress_; |
| 311 } |
| 312 |
244 scoped_ptr<ExistingUserController> existing_user_controller_; | 313 scoped_ptr<ExistingUserController> existing_user_controller_; |
245 | 314 |
246 // These mocks are owned by CrosLibrary class. | 315 // These mocks are owned by CrosLibrary class. |
247 MockNetworkLibrary* mock_network_library_; | 316 MockNetworkLibrary* mock_network_library_; |
248 | 317 |
| 318 // |mock_login_display_| is owned by the ExistingUserController, which calls |
| 319 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. |
249 MockLoginDisplay* mock_login_display_; | 320 MockLoginDisplay* mock_login_display_; |
250 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; | 321 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; |
251 | 322 |
252 ScopedMockUserManagerEnabler mock_user_manager_; | 323 scoped_ptr<ScopedMockUserManagerEnabler> mock_user_manager_; |
253 | 324 |
254 // Owned by LoginUtilsWrapper. | 325 // Owned by LoginUtilsWrapper. |
255 MockLoginUtils* mock_login_utils_; | 326 MockLoginUtils* mock_login_utils_; |
256 | 327 |
257 scoped_ptr<TestingProfile> testing_profile_; | 328 scoped_ptr<TestingProfile> testing_profile_; |
258 | 329 |
259 // Mock URLFetcher. | 330 // Mock URLFetcher. |
260 MockURLFetcherFactory<SuccessFetcher> factory_; | 331 MockURLFetcherFactory<SuccessFetcher> factory_; |
261 | 332 |
262 base::Callback<void(void)> profile_prepared_cb_; | 333 base::Callback<void(void)> profile_prepared_cb_; |
(...skipping 21 matching lines...) Expand all Loading... |
284 .Times(1); | 355 .Times(1); |
285 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) | 356 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) |
286 .Times(1); | 357 .Times(1); |
287 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 358 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
288 .Times(1); | 359 .Times(1); |
289 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 360 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
290 .Times(1); | 361 .Times(1); |
291 EXPECT_CALL(*mock_login_display_host_, | 362 EXPECT_CALL(*mock_login_display_host_, |
292 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) | 363 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) |
293 .Times(0); | 364 .Times(0); |
294 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) | 365 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
295 .Times(AnyNumber()) | 366 .Times(AnyNumber()) |
296 .WillRepeatedly(Return(false)); | 367 .WillRepeatedly(Return(false)); |
297 existing_user_controller()->Login(kUsername, kPassword); | 368 existing_user_controller()->Login(kUsername, kPassword); |
298 content::RunAllPendingInMessageLoop(); | 369 content::RunAllPendingInMessageLoop(); |
299 } | 370 } |
300 | 371 |
301 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { | 372 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, AutoEnrollAfterSignIn) { |
302 EXPECT_CALL(*mock_login_display_host_, | 373 EXPECT_CALL(*mock_login_display_host_, |
303 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) | 374 StartWizard(WizardController::kEnterpriseEnrollmentScreenName, _)) |
304 .Times(1); | 375 .Times(1); |
305 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 376 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
306 .Times(1); | 377 .Times(1); |
307 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) | 378 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) |
308 .Times(1); | 379 .Times(1); |
309 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) | 380 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
310 .Times(AnyNumber()) | 381 .Times(AnyNumber()) |
311 .WillRepeatedly(Return(false)); | 382 .WillRepeatedly(Return(false)); |
312 // The order of these expected calls matters: the UI if first disabled | 383 // The order of these expected calls matters: the UI if first disabled |
313 // during the login sequence, and is enabled again for the enrollment screen. | 384 // during the login sequence, and is enabled again for the enrollment screen. |
314 Sequence uiEnabledSequence; | 385 Sequence uiEnabledSequence; |
315 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 386 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
316 .Times(1) | 387 .Times(1) |
317 .InSequence(uiEnabledSequence); | 388 .InSequence(uiEnabledSequence); |
318 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 389 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
319 .Times(1) | 390 .Times(1) |
(...skipping 24 matching lines...) Expand all Loading... |
344 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) | 415 PrepareProfile(kNewUsername, _, kPassword, _, _, _)) |
345 .Times(1) | 416 .Times(1) |
346 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 417 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
347 &base::Callback<void(void)>::Run)); | 418 &base::Callback<void(void)>::Run)); |
348 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) | 419 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) |
349 .Times(1); | 420 .Times(1); |
350 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 421 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
351 .Times(1); | 422 .Times(1); |
352 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) | 423 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) |
353 .Times(1); | 424 .Times(1); |
354 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserNew()) | 425 EXPECT_CALL(*mock_user_manager_->user_manager(), IsCurrentUserNew()) |
355 .Times(AnyNumber()) | 426 .Times(AnyNumber()) |
356 .WillRepeatedly(Return(true)); | 427 .WillRepeatedly(Return(true)); |
357 | 428 |
358 // The order of these expected calls matters: the UI if first disabled | 429 // The order of these expected calls matters: the UI if first disabled |
359 // during the login sequence, and is enabled again after login completion. | 430 // during the login sequence, and is enabled again after login completion. |
360 Sequence uiEnabledSequence; | 431 Sequence uiEnabledSequence; |
361 // This is disabled twice: once right after signin but before checking for | 432 // This is disabled twice: once right after signin but before checking for |
362 // auto-enrollment, and again after doing an ownership status check. | 433 // auto-enrollment, and again after doing an ownership status check. |
363 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 434 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
364 .Times(2) | 435 .Times(2) |
365 .InSequence(uiEnabledSequence); | 436 .InSequence(uiEnabledSequence); |
366 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 437 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
367 .Times(1) | 438 .Times(1) |
368 .InSequence(uiEnabledSequence); | 439 .InSequence(uiEnabledSequence); |
369 | 440 |
370 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); | 441 existing_user_controller()->CompleteLogin(kNewUsername, kPassword); |
371 content::RunAllPendingInMessageLoop(); | 442 content::RunAllPendingInMessageLoop(); |
372 } | 443 } |
373 | 444 |
| 445 MATCHER_P(HasDetails, expected, "") { |
| 446 return expected == *content::Details<const std::string>(arg).ptr(); |
| 447 } |
| 448 |
| 449 class ExistingUserControllerPublicSessionTest |
| 450 : public ExistingUserControllerTest { |
| 451 protected: |
| 452 ExistingUserControllerPublicSessionTest() { |
| 453 } |
| 454 |
| 455 virtual void SetUpOnMainThread() OVERRIDE { |
| 456 ExistingUserControllerTest::SetUpOnMainThread(); |
| 457 |
| 458 // Wait for the public session user to be created. |
| 459 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { |
| 460 NotificationWatcher( |
| 461 chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 462 base::Bind(&chromeos::UserManager::IsKnownUser, |
| 463 base::Unretained(chromeos::UserManager::Get()), |
| 464 kAutoLoginUsername)).Run(); |
| 465 } |
| 466 |
| 467 // Wait for the device local account policy to be installed. |
| 468 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> |
| 469 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> |
| 470 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); |
| 471 if (!store->has_policy()) { |
| 472 policy::MockCloudPolicyStoreObserver observer; |
| 473 scoped_refptr<content::MessageLoopRunner> runner = |
| 474 new content::MessageLoopRunner; |
| 475 store->AddObserver(&observer); |
| 476 EXPECT_CALL(observer, OnStoreLoaded(store)) |
| 477 .Times(1) |
| 478 .WillOnce(InvokeWithoutArgs(runner.get(), |
| 479 &content::MessageLoopRunner::Quit)); |
| 480 runner->Run(); |
| 481 store->RemoveObserver(&observer); |
| 482 } |
| 483 } |
| 484 |
| 485 virtual void SetUpSessionManager( |
| 486 MockDBusThreadManager* mock_dbus_thread_manager) OVERRIDE { |
| 487 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient()) |
| 488 .WillRepeatedly(Return(&session_manager_client_)); |
| 489 |
| 490 // Install the owner key. |
| 491 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 492 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key"); |
| 493 std::vector<uint8> owner_key_bits; |
| 494 ASSERT_TRUE(device_policy_.signing_key()->ExportPublicKey(&owner_key_bits)); |
| 495 ASSERT_EQ( |
| 496 file_util::WriteFile( |
| 497 owner_key_file, |
| 498 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), |
| 499 owner_key_bits.size()), |
| 500 static_cast<int>(owner_key_bits.size())); |
| 501 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file)); |
| 502 |
| 503 // Setup the device policy. |
| 504 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); |
| 505 proto.mutable_device_local_accounts()->add_account()->set_id( |
| 506 kAutoLoginUsername); |
| 507 RefreshDevicePolicy(); |
| 508 |
| 509 // Setup the device local account policy. |
| 510 policy::UserPolicyBuilder device_local_account_policy; |
| 511 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); |
| 512 device_local_account_policy.policy_data().set_policy_type( |
| 513 policy::dm_protocol::kChromePublicAccountPolicyType); |
| 514 device_local_account_policy.policy_data().set_settings_entity_id( |
| 515 kAutoLoginUsername); |
| 516 device_local_account_policy.Build(); |
| 517 session_manager_client_.set_device_local_account_policy( |
| 518 kAutoLoginUsername, |
| 519 device_local_account_policy.GetBlob()); |
| 520 } |
| 521 |
| 522 virtual void SetUpLoginDisplay() OVERRIDE { |
| 523 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 524 .Times(1) |
| 525 .WillOnce(Return(mock_login_display_)); |
| 526 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 527 .Times(AnyNumber()) |
| 528 .WillRepeatedly(ReturnNull()); |
| 529 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
| 530 .Times(AnyNumber()); |
| 531 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) |
| 532 .Times(AnyNumber()); |
| 533 } |
| 534 |
| 535 void ExpectSuccessfulLogin(const std::string& username, |
| 536 const std::string& password, |
| 537 scoped_refptr<Authenticator> create_authenticator( |
| 538 LoginStatusConsumer* consumer)) { |
| 539 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 540 .Times(AnyNumber()); |
| 541 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
| 542 .Times(1) |
| 543 .WillOnce(WithArg<0>(Invoke(create_authenticator))); |
| 544 EXPECT_CALL(*mock_login_utils_, |
| 545 PrepareProfile(username, _, password, _, _, _)) |
| 546 .Times(1) |
| 547 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
| 548 &base::Callback<void(void)>::Run)); |
| 549 EXPECT_CALL(*mock_login_utils_, |
| 550 DoBrowserLaunch(testing_profile_.get(), |
| 551 mock_login_display_host_.get())) |
| 552 .Times(1); |
| 553 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username)) |
| 554 .Times(1); |
| 555 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
| 556 .Times(1); |
| 557 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
| 558 .Times(1); |
| 559 EXPECT_CALL(*mock_login_display_host_, |
| 560 StartWizard(WizardController::kTermsOfServiceScreenName, NULL)) |
| 561 .Times(0); |
| 562 } |
| 563 |
| 564 scoped_refptr<content::MessageLoopRunner> CreateSettingsObserverRunLoop( |
| 565 content::MockNotificationObserver& observer, const char* setting) { |
| 566 scoped_refptr<content::MessageLoopRunner> runner = |
| 567 new content::MessageLoopRunner; |
| 568 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, |
| 569 _, HasDetails(setting))) |
| 570 .Times(1) |
| 571 .WillOnce(InvokeWithoutArgs(runner.get(), |
| 572 &content::MessageLoopRunner::Quit)); |
| 573 CrosSettings::Get()->AddSettingsObserver(setting, &observer); |
| 574 return runner; |
| 575 } |
| 576 |
| 577 void RefreshDevicePolicy() { |
| 578 // Reset the key to its original state. |
| 579 device_policy_.set_signing_key( |
| 580 policy::PolicyBuilder::CreateTestSigningKey()); |
| 581 device_policy_.Build(); |
| 582 // Trick the device into thinking it's enterprise-enrolled by |
| 583 // removing the local private key. This will allow it to accept |
| 584 // cloud policy for device owner settings. |
| 585 device_policy_.set_signing_key( |
| 586 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); |
| 587 device_policy_.set_new_signing_key( |
| 588 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); |
| 589 session_manager_client_.set_device_policy(device_policy_.GetBlob()); |
| 590 session_manager_client_.OnPropertyChangeComplete(true); |
| 591 } |
| 592 |
| 593 void SetAutoLoginPolicy(const std::string& username, int delay) { |
| 594 // Wait until ExistingUserController has finished auto-login |
| 595 // configuration by observing the same settings that trigger |
| 596 // ConfigurePublicSessionAutoLogin. |
| 597 content::MockNotificationObserver observer; |
| 598 |
| 599 em::ChromeDeviceSettingsProto& proto(device_policy_.payload()); |
| 600 |
| 601 // If both settings have changed we need to wait for both to |
| 602 // propagate, so check the new values against the old ones. |
| 603 scoped_refptr<content::MessageLoopRunner> runner1 = NULL; |
| 604 if (!proto.has_device_local_accounts() || |
| 605 !proto.device_local_accounts().has_auto_login_id() || |
| 606 proto.device_local_accounts().auto_login_id() != username) { |
| 607 runner1 = CreateSettingsObserverRunLoop( |
| 608 observer, kAccountsPrefDeviceLocalAccountAutoLoginId); |
| 609 } |
| 610 scoped_refptr<content::MessageLoopRunner> runner2 = NULL; |
| 611 if (!proto.has_device_local_accounts() || |
| 612 !proto.device_local_accounts().has_auto_login_delay() || |
| 613 proto.device_local_accounts().auto_login_delay() != delay) { |
| 614 runner2 = CreateSettingsObserverRunLoop( |
| 615 observer, kAccountsPrefDeviceLocalAccountAutoLoginDelay); |
| 616 } |
| 617 |
| 618 // Update the policy. |
| 619 proto.mutable_device_local_accounts()->set_auto_login_id(username); |
| 620 proto.mutable_device_local_accounts()->set_auto_login_delay(delay); |
| 621 RefreshDevicePolicy(); |
| 622 |
| 623 // Wait for ExistingUserController to read the updated settings. |
| 624 if (runner1) |
| 625 runner1->Run(); |
| 626 if (runner2) |
| 627 runner2->Run(); |
| 628 |
| 629 // Clean up. |
| 630 CrosSettings::Get()->RemoveSettingsObserver( |
| 631 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 632 &observer); |
| 633 CrosSettings::Get()->RemoveSettingsObserver( |
| 634 kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| 635 &observer); |
| 636 } |
| 637 |
| 638 void ConfigureAutoLogin() { |
| 639 existing_user_controller()->ConfigurePublicSessionAutoLogin(); |
| 640 } |
| 641 |
| 642 void FireAutoLogin() { |
| 643 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); |
| 644 } |
| 645 |
| 646 // Mock out policy loads/stores from/to the device. |
| 647 FakeSessionManagerClient session_manager_client_; |
| 648 |
| 649 // Stores the device owner key. |
| 650 base::ScopedTempDir temp_dir_; |
| 651 |
| 652 // Carries Chrome OS device policies for tests. |
| 653 policy::DevicePolicyBuilder device_policy_; |
| 654 |
| 655 private: |
| 656 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); |
| 657 }; |
| 658 |
| 659 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 660 ConfigureAutoLoginUsingPolicy) { |
| 661 existing_user_controller()->OnSigninScreenReady(); |
| 662 EXPECT_EQ("", auto_login_username()); |
| 663 EXPECT_EQ(0, auto_login_delay()); |
| 664 EXPECT_FALSE(auto_login_timer()); |
| 665 |
| 666 // Set the policy. |
| 667 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 668 EXPECT_EQ(kAutoLoginUsername, auto_login_username()); |
| 669 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); |
| 670 ASSERT_TRUE(auto_login_timer()); |
| 671 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
| 672 |
| 673 // Unset the policy. |
| 674 SetAutoLoginPolicy("", 0); |
| 675 EXPECT_EQ("", auto_login_username()); |
| 676 EXPECT_EQ(0, auto_login_delay()); |
| 677 ASSERT_TRUE(auto_login_timer()); |
| 678 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 679 } |
| 680 |
| 681 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 682 AutoLoginNoDelay) { |
| 683 // Set up mocks to check login success. |
| 684 ExpectSuccessfulLogin(kAutoLoginUsername, "", |
| 685 CreateAuthenticatorForPublicSession); |
| 686 existing_user_controller()->OnSigninScreenReady(); |
| 687 |
| 688 // Start auto-login and wait for login tasks to complete. |
| 689 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay); |
| 690 content::RunAllPendingInMessageLoop(); |
| 691 } |
| 692 |
| 693 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 694 AutoLoginShortDelay) { |
| 695 // Set up mocks to check login success. |
| 696 ExpectSuccessfulLogin(kAutoLoginUsername, "", |
| 697 CreateAuthenticatorForPublicSession); |
| 698 existing_user_controller()->OnSigninScreenReady(); |
| 699 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay); |
| 700 ASSERT_TRUE(auto_login_timer()); |
| 701 // Don't assert that timer is running: with the short delay sometimes |
| 702 // the trigger happens before the assert. We've already tested that |
| 703 // the timer starts when it should. |
| 704 |
| 705 // Wait for the timer to fire. |
| 706 scoped_refptr<content::MessageLoopRunner> runner |
| 707 = new content::MessageLoopRunner; |
| 708 base::OneShotTimer<content::MessageLoopRunner> timer; |
| 709 timer.Start(FROM_HERE, |
| 710 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), |
| 711 base::Bind(&content::MessageLoopRunner::Quit, runner)); |
| 712 runner->Run(); |
| 713 |
| 714 // Wait for login tasks to complete. |
| 715 content::RunAllPendingInMessageLoop(); |
| 716 } |
| 717 |
| 718 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 719 LoginStopsAutoLogin) { |
| 720 // Set up mocks to check login success. |
| 721 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); |
| 722 |
| 723 existing_user_controller()->OnSigninScreenReady(); |
| 724 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 725 ASSERT_TRUE(auto_login_timer()); |
| 726 |
| 727 // Login and check that it stopped the timer. |
| 728 existing_user_controller()->Login(kUsername, kPassword); |
| 729 EXPECT_TRUE(is_login_in_progress()); |
| 730 ASSERT_TRUE(auto_login_timer()); |
| 731 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 732 |
| 733 // Wait for login tasks to complete. |
| 734 content::RunAllPendingInMessageLoop(); |
| 735 |
| 736 // Timer should still be stopped after login completes. |
| 737 ASSERT_TRUE(auto_login_timer()); |
| 738 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 739 } |
| 740 |
| 741 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 742 GuestModeLoginStopsAutoLogin) { |
| 743 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 744 .Times(1); |
| 745 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
| 746 .Times(1) |
| 747 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator))); |
| 748 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_)) |
| 749 .Times(1); |
| 750 |
| 751 existing_user_controller()->OnSigninScreenReady(); |
| 752 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 753 ASSERT_TRUE(auto_login_timer()); |
| 754 |
| 755 // Login and check that it stopped the timer. |
| 756 existing_user_controller()->LoginAsGuest(); |
| 757 EXPECT_TRUE(is_login_in_progress()); |
| 758 ASSERT_TRUE(auto_login_timer()); |
| 759 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 760 |
| 761 // Wait for login tasks to complete. |
| 762 content::RunAllPendingInMessageLoop(); |
| 763 |
| 764 // Timer should still be stopped after login completes. |
| 765 ASSERT_TRUE(auto_login_timer()); |
| 766 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 767 } |
| 768 |
| 769 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 770 CompleteLoginStopsAutoLogin) { |
| 771 // Set up mocks to check login success. |
| 772 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); |
| 773 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) |
| 774 .Times(1); |
| 775 |
| 776 existing_user_controller()->OnSigninScreenReady(); |
| 777 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 778 ASSERT_TRUE(auto_login_timer()); |
| 779 |
| 780 // Check that login completes and stops the timer. |
| 781 existing_user_controller()->CompleteLogin(kUsername, kPassword); |
| 782 ASSERT_TRUE(auto_login_timer()); |
| 783 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 784 |
| 785 // Wait for login tasks to complete. |
| 786 content::RunAllPendingInMessageLoop(); |
| 787 |
| 788 // Timer should still be stopped after login completes. |
| 789 ASSERT_TRUE(auto_login_timer()); |
| 790 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 791 } |
| 792 |
| 793 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 794 PublicSessionLoginStopsAutoLogin) { |
| 795 // Set up mocks to check login success. |
| 796 ExpectSuccessfulLogin(kAutoLoginUsername, "", |
| 797 CreateAuthenticatorForPublicSession); |
| 798 existing_user_controller()->OnSigninScreenReady(); |
| 799 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); |
| 800 ASSERT_TRUE(auto_login_timer()); |
| 801 |
| 802 // Login and check that it stopped the timer. |
| 803 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername); |
| 804 EXPECT_TRUE(is_login_in_progress()); |
| 805 ASSERT_TRUE(auto_login_timer()); |
| 806 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 807 |
| 808 // Wait for login tasks to complete. |
| 809 content::RunAllPendingInMessageLoop(); |
| 810 |
| 811 // Timer should still be stopped after login completes. |
| 812 ASSERT_TRUE(auto_login_timer()); |
| 813 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 814 } |
| 815 |
374 } // namespace chromeos | 816 } // namespace chromeos |
OLD | NEW |