| OLD | NEW |
| 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/login/existing_user_controller.h" | 10 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool is_login_in_progress() const { | 120 bool is_login_in_progress() const { |
| 121 return existing_user_controller()->is_login_in_progress_; | 121 return existing_user_controller()->is_login_in_progress_; |
| 122 } | 122 } |
| 123 void set_is_login_in_progress(bool is_login_in_progress) { | 123 void set_is_login_in_progress(bool is_login_in_progress) { |
| 124 existing_user_controller()->is_login_in_progress_ = is_login_in_progress; | 124 existing_user_controller()->is_login_in_progress_ = is_login_in_progress; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void ConfigureAutoLogin() { | 127 void ConfigureAutoLogin() { |
| 128 existing_user_controller()->ConfigurePublicSessionAutoLogin(); | 128 existing_user_controller()->ConfigureAutoLogin(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 const std::string auto_login_user_id_ = | 131 const std::string auto_login_user_id_ = |
| 132 std::string("public_session_user@localhost"); | 132 std::string("public_session_user@localhost"); |
| 133 | 133 |
| 134 const AccountId auto_login_account_id_ = | 134 const AccountId auto_login_account_id_ = |
| 135 AccountId::FromUserEmail(policy::GenerateDeviceLocalAccountUserId( | 135 AccountId::FromUserEmail(policy::GenerateDeviceLocalAccountUserId( |
| 136 auto_login_user_id_, | 136 auto_login_user_id_, |
| 137 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)); | 137 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)); |
| 138 | 138 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 154 | 154 |
| 155 // |existing_user_controller_| must be destroyed before | 155 // |existing_user_controller_| must be destroyed before |
| 156 // |device_settings_test_helper_|. | 156 // |device_settings_test_helper_|. |
| 157 std::unique_ptr<ExistingUserController> existing_user_controller_; | 157 std::unique_ptr<ExistingUserController> existing_user_controller_; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { | 160 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { |
| 161 // Timer shouldn't start until signin screen is ready. | 161 // Timer shouldn't start until signin screen is ready. |
| 162 set_auto_login_account_id(auto_login_account_id_); | 162 set_auto_login_account_id(auto_login_account_id_); |
| 163 set_auto_login_delay(kAutoLoginDelay2); | 163 set_auto_login_delay(kAutoLoginDelay2); |
| 164 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | 164 existing_user_controller()->StartAutoLoginTimer(); |
| 165 EXPECT_FALSE(auto_login_timer()); | 165 EXPECT_FALSE(auto_login_timer()); |
| 166 | 166 |
| 167 // Timer shouldn't start if the policy isn't set. | 167 // Timer shouldn't start if the policy isn't set. |
| 168 set_auto_login_account_id(EmptyAccountId()); | 168 set_auto_login_account_id(EmptyAccountId()); |
| 169 existing_user_controller()->OnSigninScreenReady(); | 169 existing_user_controller()->OnSigninScreenReady(); |
| 170 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | 170 existing_user_controller()->StartAutoLoginTimer(); |
| 171 EXPECT_FALSE(auto_login_timer()); | 171 EXPECT_FALSE(auto_login_timer()); |
| 172 | 172 |
| 173 // Timer shouldn't fire in the middle of a login attempt. | 173 // Timer shouldn't fire in the middle of a login attempt. |
| 174 set_auto_login_account_id(auto_login_account_id_); | 174 set_auto_login_account_id(auto_login_account_id_); |
| 175 set_is_login_in_progress(true); | 175 set_is_login_in_progress(true); |
| 176 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | 176 existing_user_controller()->StartAutoLoginTimer(); |
| 177 EXPECT_FALSE(auto_login_timer()); | 177 EXPECT_FALSE(auto_login_timer()); |
| 178 | 178 |
| 179 // Otherwise start. | 179 // Otherwise start. |
| 180 set_is_login_in_progress(false); | 180 set_is_login_in_progress(false); |
| 181 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | 181 existing_user_controller()->StartAutoLoginTimer(); |
| 182 ASSERT_TRUE(auto_login_timer()); | 182 ASSERT_TRUE(auto_login_timer()); |
| 183 EXPECT_TRUE(auto_login_timer()->IsRunning()); | 183 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
| 184 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | 184 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), |
| 185 kAutoLoginDelay2); | 185 kAutoLoginDelay2); |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) { | 188 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) { |
| 189 existing_user_controller()->OnSigninScreenReady(); | 189 existing_user_controller()->OnSigninScreenReady(); |
| 190 set_auto_login_account_id(auto_login_account_id_); | 190 set_auto_login_account_id(auto_login_account_id_); |
| 191 set_auto_login_delay(kAutoLoginDelay2); | 191 set_auto_login_delay(kAutoLoginDelay2); |
| 192 | 192 |
| 193 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | 193 existing_user_controller()->StartAutoLoginTimer(); |
| 194 ASSERT_TRUE(auto_login_timer()); | 194 ASSERT_TRUE(auto_login_timer()); |
| 195 EXPECT_TRUE(auto_login_timer()->IsRunning()); | 195 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
| 196 | 196 |
| 197 existing_user_controller()->StopPublicSessionAutoLoginTimer(); | 197 existing_user_controller()->StopAutoLoginTimer(); |
| 198 ASSERT_TRUE(auto_login_timer()); | 198 ASSERT_TRUE(auto_login_timer()); |
| 199 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 199 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) { | 202 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) { |
| 203 existing_user_controller()->OnSigninScreenReady(); | 203 existing_user_controller()->OnSigninScreenReady(); |
| 204 set_auto_login_account_id(auto_login_account_id_); | 204 set_auto_login_account_id(auto_login_account_id_); |
| 205 | 205 |
| 206 // Timer starts off not running. | 206 // Timer starts off not running. |
| 207 EXPECT_FALSE(auto_login_timer()); | 207 EXPECT_FALSE(auto_login_timer()); |
| 208 | 208 |
| 209 // When the timer isn't running, nothing should happen. | 209 // When the timer isn't running, nothing should happen. |
| 210 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); | 210 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); |
| 211 EXPECT_FALSE(auto_login_timer()); | 211 EXPECT_FALSE(auto_login_timer()); |
| 212 | 212 |
| 213 // Start the timer. | 213 // Start the timer. |
| 214 set_auto_login_delay(kAutoLoginDelay2); | 214 set_auto_login_delay(kAutoLoginDelay2); |
| 215 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | 215 existing_user_controller()->StartAutoLoginTimer(); |
| 216 ASSERT_TRUE(auto_login_timer()); | 216 ASSERT_TRUE(auto_login_timer()); |
| 217 EXPECT_TRUE(auto_login_timer()->IsRunning()); | 217 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
| 218 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | 218 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), |
| 219 kAutoLoginDelay2); | 219 kAutoLoginDelay2); |
| 220 | 220 |
| 221 // User activity should restart the timer, so check to see that the | 221 // User activity should restart the timer, so check to see that the |
| 222 // timer delay was modified. | 222 // timer delay was modified. |
| 223 set_auto_login_delay(kAutoLoginDelay1); | 223 set_auto_login_delay(kAutoLoginDelay1); |
| 224 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); | 224 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); |
| 225 ASSERT_TRUE(auto_login_timer()); | 225 ASSERT_TRUE(auto_login_timer()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 ConfigureAutoLogin(); | 269 ConfigureAutoLogin(); |
| 270 ASSERT_TRUE(auto_login_timer()); | 270 ASSERT_TRUE(auto_login_timer()); |
| 271 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 271 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 272 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | 272 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), |
| 273 kAutoLoginDelay2); | 273 kAutoLoginDelay2); |
| 274 EXPECT_EQ(auto_login_account_id(), EmptyAccountId()); | 274 EXPECT_EQ(auto_login_account_id(), EmptyAccountId()); |
| 275 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); | 275 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace chromeos | 278 } // namespace chromeos |
| OLD | NEW |