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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller_auto_login_unittest.cc

Issue 2510203002: Implement auto-login for ARC kiosk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kiosk_session
Patch Set: Update names and comments. Created 4 years, 1 month 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.h"
10 #include "chrome/browser/chromeos/login/existing_user_controller.h" 11 #include "chrome/browser/chromeos/login/existing_user_controller.h"
11 #include "chrome/browser/chromeos/login/ui/mock_login_display.h" 12 #include "chrome/browser/chromeos/login/ui/mock_login_display.h"
12 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h" 13 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h"
13 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 14 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
14 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
15 #include "chrome/browser/chromeos/policy/device_local_account.h" 16 #include "chrome/browser/chromeos/policy/device_local_account.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 18 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
18 #include "chrome/test/base/scoped_testing_local_state.h" 19 #include "chrome/test/base/scoped_testing_local_state.h"
19 #include "chrome/test/base/testing_browser_process.h" 20 #include "chrome/test/base/testing_browser_process.h"
(...skipping 22 matching lines...) Expand all
42 protected: 43 protected:
43 ExistingUserControllerAutoLoginTest() 44 ExistingUserControllerAutoLoginTest()
44 : ui_thread_(content::BrowserThread::UI, &message_loop_), 45 : ui_thread_(content::BrowserThread::UI, &message_loop_),
45 local_state_(TestingBrowserProcess::GetGlobal()), 46 local_state_(TestingBrowserProcess::GetGlobal()),
46 mock_user_manager_(new MockUserManager()), 47 mock_user_manager_(new MockUserManager()),
47 scoped_user_manager_(mock_user_manager_) {} 48 scoped_user_manager_(mock_user_manager_) {}
48 49
49 void SetUp() override { 50 void SetUp() override {
50 mock_login_display_host_.reset(new MockLoginDisplayHost); 51 mock_login_display_host_.reset(new MockLoginDisplayHost);
51 mock_login_display_ = new MockLoginDisplay(); 52 mock_login_display_ = new MockLoginDisplay();
53 arc_kiosk_app_manager_.reset(new ArcKioskAppManager());
52 54
53 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 55 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
54 .Times(1) 56 .Times(1)
55 .WillOnce(Return(mock_login_display_)); 57 .WillOnce(Return(mock_login_display_));
56 58
57 EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AnyNumber()); 59 EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AnyNumber());
58 EXPECT_CALL(*mock_user_manager_, FindUser(_)) 60 EXPECT_CALL(*mock_user_manager_, FindUser(_))
59 .WillRepeatedly(ReturnNull()); 61 .WillRepeatedly(ReturnNull());
60 EXPECT_CALL(*mock_user_manager_, FindUser(auto_login_account_id_)) 62 EXPECT_CALL(*mock_user_manager_, FindUser(auto_login_account_id_))
61 .WillRepeatedly(Return(mock_user_manager_->CreatePublicAccountUser( 63 .WillRepeatedly(Return(mock_user_manager_->CreatePublicAccountUser(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 106
105 const AccountId& auto_login_account_id() const { 107 const AccountId& auto_login_account_id() const {
106 return existing_user_controller()->public_session_auto_login_account_id_; 108 return existing_user_controller()->public_session_auto_login_account_id_;
107 } 109 }
108 void set_auto_login_account_id(const AccountId& account_id) { 110 void set_auto_login_account_id(const AccountId& account_id) {
109 existing_user_controller()->public_session_auto_login_account_id_ = 111 existing_user_controller()->public_session_auto_login_account_id_ =
110 account_id; 112 account_id;
111 } 113 }
112 114
113 int auto_login_delay() const { 115 int auto_login_delay() const {
114 return existing_user_controller()->public_session_auto_login_delay_; 116 return existing_user_controller()->auto_login_delay_;
115 } 117 }
116 void set_auto_login_delay(int delay) { 118 void set_auto_login_delay(int delay) {
117 existing_user_controller()->public_session_auto_login_delay_ = delay; 119 existing_user_controller()->auto_login_delay_ = delay;
118 } 120 }
119 121
120 bool is_login_in_progress() const { 122 bool is_login_in_progress() const {
121 return existing_user_controller()->is_login_in_progress_; 123 return existing_user_controller()->is_login_in_progress_;
122 } 124 }
123 void set_is_login_in_progress(bool is_login_in_progress) { 125 void set_is_login_in_progress(bool is_login_in_progress) {
124 existing_user_controller()->is_login_in_progress_ = is_login_in_progress; 126 existing_user_controller()->is_login_in_progress_ = is_login_in_progress;
125 } 127 }
126 128
127 void ConfigureAutoLogin() { 129 void ConfigureAutoLogin() {
128 existing_user_controller()->ConfigurePublicSessionAutoLogin(); 130 existing_user_controller()->ConfigureAutoLogin();
129 } 131 }
130 132
131 const std::string auto_login_user_id_ = 133 const std::string auto_login_user_id_ =
132 std::string("public_session_user@localhost"); 134 std::string("public_session_user@localhost");
133 135
134 const AccountId auto_login_account_id_ = 136 const AccountId auto_login_account_id_ =
135 AccountId::FromUserEmail(policy::GenerateDeviceLocalAccountUserId( 137 AccountId::FromUserEmail(policy::GenerateDeviceLocalAccountUserId(
136 auto_login_user_id_, 138 auto_login_user_id_,
137 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)); 139 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION));
138 140
139 private: 141 private:
140 // |mock_login_display_| is owned by the ExistingUserController, which calls 142 // |mock_login_display_| is owned by the ExistingUserController, which calls
141 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. 143 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
142 MockLoginDisplay* mock_login_display_; 144 MockLoginDisplay* mock_login_display_;
143 145
144 std::unique_ptr<MockLoginDisplayHost> mock_login_display_host_; 146 std::unique_ptr<MockLoginDisplayHost> mock_login_display_host_;
145 base::MessageLoopForUI message_loop_; 147 base::MessageLoopForUI message_loop_;
146 content::TestBrowserThread ui_thread_; 148 content::TestBrowserThread ui_thread_;
147 ScopedTestingLocalState local_state_; 149 ScopedTestingLocalState local_state_;
148 150
149 // Required by ExistingUserController: 151 // Required by ExistingUserController:
150 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 152 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
151 ScopedTestCrosSettings test_cros_settings_; 153 ScopedTestCrosSettings test_cros_settings_;
152 MockUserManager* mock_user_manager_; 154 MockUserManager* mock_user_manager_;
153 ScopedUserManagerEnabler scoped_user_manager_; 155 ScopedUserManagerEnabler scoped_user_manager_;
156 std::unique_ptr<ArcKioskAppManager> arc_kiosk_app_manager_;
154 157
155 // |existing_user_controller_| must be destroyed before 158 // |existing_user_controller_| must be destroyed before
156 // |device_settings_test_helper_|. 159 // |device_settings_test_helper_|.
157 std::unique_ptr<ExistingUserController> existing_user_controller_; 160 std::unique_ptr<ExistingUserController> existing_user_controller_;
158 }; 161 };
159 162
160 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { 163 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) {
161 // Timer shouldn't start until signin screen is ready. 164 // Timer shouldn't start until signin screen is ready.
162 set_auto_login_account_id(auto_login_account_id_); 165 set_auto_login_account_id(auto_login_account_id_);
163 set_auto_login_delay(kAutoLoginDelay2); 166 set_auto_login_delay(kAutoLoginDelay2);
164 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 167 existing_user_controller()->StartAutoLoginTimer();
165 EXPECT_FALSE(auto_login_timer()); 168 EXPECT_FALSE(auto_login_timer());
166 169
167 // Timer shouldn't start if the policy isn't set. 170 // Timer shouldn't start if the policy isn't set.
168 set_auto_login_account_id(EmptyAccountId()); 171 set_auto_login_account_id(EmptyAccountId());
169 existing_user_controller()->OnSigninScreenReady(); 172 existing_user_controller()->OnSigninScreenReady();
170 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 173 existing_user_controller()->StartAutoLoginTimer();
171 EXPECT_FALSE(auto_login_timer()); 174 EXPECT_FALSE(auto_login_timer());
172 175
173 // Timer shouldn't fire in the middle of a login attempt. 176 // Timer shouldn't fire in the middle of a login attempt.
174 set_auto_login_account_id(auto_login_account_id_); 177 set_auto_login_account_id(auto_login_account_id_);
175 set_is_login_in_progress(true); 178 set_is_login_in_progress(true);
176 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 179 existing_user_controller()->StartAutoLoginTimer();
177 EXPECT_FALSE(auto_login_timer()); 180 EXPECT_FALSE(auto_login_timer());
178 181
179 // Otherwise start. 182 // Otherwise start.
180 set_is_login_in_progress(false); 183 set_is_login_in_progress(false);
181 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 184 existing_user_controller()->StartAutoLoginTimer();
182 ASSERT_TRUE(auto_login_timer()); 185 ASSERT_TRUE(auto_login_timer());
183 EXPECT_TRUE(auto_login_timer()->IsRunning()); 186 EXPECT_TRUE(auto_login_timer()->IsRunning());
184 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 187 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
185 kAutoLoginDelay2); 188 kAutoLoginDelay2);
186 } 189 }
187 190
188 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) { 191 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) {
189 existing_user_controller()->OnSigninScreenReady(); 192 existing_user_controller()->OnSigninScreenReady();
190 set_auto_login_account_id(auto_login_account_id_); 193 set_auto_login_account_id(auto_login_account_id_);
191 set_auto_login_delay(kAutoLoginDelay2); 194 set_auto_login_delay(kAutoLoginDelay2);
192 195
193 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 196 existing_user_controller()->StartAutoLoginTimer();
194 ASSERT_TRUE(auto_login_timer()); 197 ASSERT_TRUE(auto_login_timer());
195 EXPECT_TRUE(auto_login_timer()->IsRunning()); 198 EXPECT_TRUE(auto_login_timer()->IsRunning());
196 199
197 existing_user_controller()->StopPublicSessionAutoLoginTimer(); 200 existing_user_controller()->StopAutoLoginTimer();
198 ASSERT_TRUE(auto_login_timer()); 201 ASSERT_TRUE(auto_login_timer());
199 EXPECT_FALSE(auto_login_timer()->IsRunning()); 202 EXPECT_FALSE(auto_login_timer()->IsRunning());
200 } 203 }
201 204
202 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) { 205 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) {
203 existing_user_controller()->OnSigninScreenReady(); 206 existing_user_controller()->OnSigninScreenReady();
204 set_auto_login_account_id(auto_login_account_id_); 207 set_auto_login_account_id(auto_login_account_id_);
205 208
206 // Timer starts off not running. 209 // Timer starts off not running.
207 EXPECT_FALSE(auto_login_timer()); 210 EXPECT_FALSE(auto_login_timer());
208 211
209 // When the timer isn't running, nothing should happen. 212 // When the timer isn't running, nothing should happen.
210 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); 213 existing_user_controller()->ResetAutoLoginTimer();
211 EXPECT_FALSE(auto_login_timer()); 214 EXPECT_FALSE(auto_login_timer());
212 215
213 // Start the timer. 216 // Start the timer.
214 set_auto_login_delay(kAutoLoginDelay2); 217 set_auto_login_delay(kAutoLoginDelay2);
215 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 218 existing_user_controller()->StartAutoLoginTimer();
216 ASSERT_TRUE(auto_login_timer()); 219 ASSERT_TRUE(auto_login_timer());
217 EXPECT_TRUE(auto_login_timer()->IsRunning()); 220 EXPECT_TRUE(auto_login_timer()->IsRunning());
218 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 221 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
219 kAutoLoginDelay2); 222 kAutoLoginDelay2);
220 223
221 // User activity should restart the timer, so check to see that the 224 // User activity should restart the timer, so check to see that the
222 // timer delay was modified. 225 // timer delay was modified.
223 set_auto_login_delay(kAutoLoginDelay1); 226 set_auto_login_delay(kAutoLoginDelay1);
224 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); 227 existing_user_controller()->ResetAutoLoginTimer();
225 ASSERT_TRUE(auto_login_timer()); 228 ASSERT_TRUE(auto_login_timer());
226 EXPECT_TRUE(auto_login_timer()->IsRunning()); 229 EXPECT_TRUE(auto_login_timer()->IsRunning());
227 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 230 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
228 kAutoLoginDelay1); 231 kAutoLoginDelay1);
229 } 232 }
230 233
231 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) { 234 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) {
232 existing_user_controller()->OnSigninScreenReady(); 235 existing_user_controller()->OnSigninScreenReady();
233 236
234 // Timer shouldn't start when the policy is disabled. 237 // Timer shouldn't start when the policy is disabled.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 ConfigureAutoLogin(); 272 ConfigureAutoLogin();
270 ASSERT_TRUE(auto_login_timer()); 273 ASSERT_TRUE(auto_login_timer());
271 EXPECT_FALSE(auto_login_timer()->IsRunning()); 274 EXPECT_FALSE(auto_login_timer()->IsRunning());
272 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 275 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
273 kAutoLoginDelay2); 276 kAutoLoginDelay2);
274 EXPECT_EQ(auto_login_account_id(), EmptyAccountId()); 277 EXPECT_EQ(auto_login_account_id(), EmptyAccountId());
275 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); 278 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2);
276 } 279 }
277 280
278 } // namespace chromeos 281 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698