Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/memory/scoped_ptr.h" | |
|
bartfab (slow)
2013/03/07 12:17:23
This is included by "existing_user_controller.h" a
dconnelly
2013/03/07 14:45:19
Done.
| |
| 6 #include "base/message_loop.h" | |
| 7 #include "chrome/browser/chromeos/login/existing_user_controller.h" | |
| 8 #include "chrome/browser/chromeos/login/login_display.h" | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 9 #include "chrome/browser/chromeos/login/login_display_host.h" | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 10 #include "chrome/browser/chromeos/login/login_utils.h" | |
|
bartfab (slow)
2013/03/07 12:17:23
This is included by "existing_user_controller.h" a
dconnelly
2013/03/07 14:45:19
Done.
| |
| 11 #include "chrome/browser/chromeos/login/mock_login_display.h" | |
| 12 #include "chrome/browser/chromeos/login/mock_login_display_host.h" | |
| 13 #include "chrome/browser/chromeos/login/mock_login_utils.h" | |
| 14 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 15 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | |
| 16 #include "chrome/test/base/scoped_testing_local_state.h" | |
| 17 #include "chrome/test/base/testing_browser_process.h" | |
| 18 #include "content/public/test/test_browser_thread.h" | |
| 19 #include "testing/gmock/include/gmock/gmock.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 using testing::AnyNumber; | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 23 using testing::AtLeast; | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 24 using testing::Mock; | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 25 using testing::Return; | |
| 26 using testing::ReturnNull; | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 27 using testing::SaveArg; | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 28 using testing::_; | |
| 29 | |
| 30 namespace chromeos { | |
| 31 | |
| 32 namespace { | |
| 33 | |
| 34 const char kAutoLoginUsername[] = "public_session_user@localhost"; | |
| 35 const int kAutoLoginNoDelay = 0; | |
|
bartfab (slow)
2013/03/07 12:17:23
This is not used anywhere.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 36 const int kAutoLoginShortDelay = 1; | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: Add an "Ms" suffix to make it clear that this
dconnelly
2013/03/07 14:45:19
Done.
| |
| 37 const int kAutoLoginLongDelay = 10000; | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: Add an "Ms" suffix to make it clear that this
dconnelly
2013/03/07 14:45:19
Done.
| |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 class ExistingUserControllerAutoLoginTest : public ::testing::Test { | |
| 42 protected: | |
| 43 ExistingUserControllerAutoLoginTest() | |
| 44 : message_loop_(MessageLoop::TYPE_UI), | |
| 45 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
| 46 local_state_(TestingBrowserProcess::GetGlobal()) { | |
| 47 } | |
| 48 | |
| 49 virtual void SetUp() { | |
| 50 mock_login_display_host_.reset(new MockLoginDisplayHost); | |
| 51 mock_login_display_ = new MockLoginDisplay(); | |
| 52 mock_login_utils_ = new MockLoginUtils(); | |
| 53 LoginUtils::Set(mock_login_utils_); | |
| 54 | |
| 55 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | |
| 56 .Times(1) | |
| 57 .WillOnce(Return(mock_login_display_)); | |
| 58 | |
| 59 existing_user_controller_.reset( | |
| 60 new ExistingUserController(mock_login_display_host_.get())); | |
| 61 | |
| 62 CrosSettings::Get()->RemoveSettingsObserver( | |
|
bartfab (slow)
2013/03/07 12:17:23
Why do you not want the ExistingUserController to
dconnelly
2013/03/07 14:45:19
Done.
| |
| 63 kAccountsPrefDeviceLocalAccountAutoLoginId, | |
|
bartfab (slow)
2013/03/07 12:17:23
#include "chrome/browser/chromeos/settings/cros_se
dconnelly
2013/03/07 14:45:19
Done.
| |
| 64 existing_user_controller()); | |
| 65 CrosSettings::Get()->RemoveSettingsObserver( | |
| 66 kAccountsPrefDeviceLocalAccountAutoLoginDelay, | |
| 67 existing_user_controller()); | |
| 68 } | |
| 69 | |
| 70 ExistingUserController* existing_user_controller() { | |
| 71 return ExistingUserController::current_controller(); | |
| 72 } | |
| 73 | |
| 74 void SetAutoLoginSettings(const std::string& username, int delay) { | |
| 75 CrosSettings::Get()->SetString( | |
| 76 kAccountsPrefDeviceLocalAccountAutoLoginId, | |
| 77 username); | |
| 78 CrosSettings::Get()->SetInteger( | |
| 79 kAccountsPrefDeviceLocalAccountAutoLoginDelay, | |
| 80 delay); | |
| 81 } | |
| 82 | |
| 83 // ExistingUserController private member accessors. | |
| 84 base::OneShotTimer<ExistingUserController>* auto_login_timer() { | |
| 85 return existing_user_controller()->auto_login_timer_.get(); | |
| 86 } | |
| 87 | |
| 88 std::string auto_login_username() { | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: const
Nit: Return const std::string&
dconnelly
2013/03/07 14:45:19
Done.
| |
| 89 return existing_user_controller()->public_session_auto_login_username_; | |
| 90 } | |
| 91 void set_auto_login_username(const std::string& username) { | |
| 92 existing_user_controller()->public_session_auto_login_username_ = username; | |
| 93 } | |
| 94 | |
| 95 int auto_login_delay() { | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: const
dconnelly
2013/03/07 14:45:19
Done.
| |
| 96 return existing_user_controller()->public_session_auto_login_delay_; | |
| 97 } | |
| 98 void set_auto_login_delay(int delay) { | |
| 99 existing_user_controller()->public_session_auto_login_delay_ = delay; | |
| 100 } | |
| 101 | |
| 102 bool is_login_in_progress() { | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: const
dconnelly
2013/03/07 14:45:19
Done.
| |
| 103 return existing_user_controller()->is_login_in_progress_; | |
| 104 } | |
| 105 void set_is_login_in_progress(bool is_login_in_progress) { | |
| 106 existing_user_controller()->is_login_in_progress_ = is_login_in_progress; | |
| 107 } | |
| 108 | |
| 109 void ConfigureAutoLogin() { | |
| 110 existing_user_controller()->ConfigurePublicSessionAutoLogin(); | |
| 111 } | |
| 112 | |
| 113 private: | |
| 114 // Owned by LoginUtilsWrapper | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: Period at the end of the line.
dconnelly
2013/03/07 14:45:19
Done.
| |
| 115 MockLoginUtils* mock_login_utils_; | |
| 116 | |
| 117 // |mock_login_display_| is owned by the ExistingUserController, which calls | |
| 118 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. | |
| 119 MockLoginDisplay* mock_login_display_; | |
| 120 | |
| 121 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; | |
| 122 scoped_ptr<ExistingUserController> existing_user_controller_; | |
| 123 MessageLoop message_loop_; | |
| 124 content::TestBrowserThread ui_thread_; | |
| 125 ScopedTestingLocalState local_state_; | |
| 126 ScopedDeviceSettingsTestHelper device_settings_test_helper_; | |
| 127 }; | |
| 128 | |
| 129 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { | |
| 130 // Timer shouldn't start until signin screen is ready. | |
| 131 set_auto_login_username(kAutoLoginUsername); | |
| 132 set_auto_login_delay(kAutoLoginLongDelay); | |
| 133 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | |
| 134 EXPECT_FALSE(auto_login_timer()); | |
| 135 | |
| 136 // Timer shouldn't start if the policy isn't set. | |
| 137 set_auto_login_username(""); | |
| 138 existing_user_controller()->OnSigninScreenReady(); | |
| 139 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | |
| 140 EXPECT_FALSE(auto_login_timer()); | |
| 141 | |
| 142 // Timer shouldn't fire in the middle of a login attempt. | |
| 143 set_auto_login_username(kAutoLoginUsername); | |
| 144 set_is_login_in_progress(true); | |
| 145 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | |
| 146 EXPECT_FALSE(auto_login_timer()); | |
| 147 | |
| 148 // Otherwise start. | |
| 149 set_is_login_in_progress(false); | |
| 150 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | |
| 151 ASSERT_TRUE(auto_login_timer()); | |
| 152 EXPECT_TRUE(auto_login_timer()->IsRunning()); | |
| 153 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | |
| 154 kAutoLoginLongDelay); | |
| 155 } | |
| 156 | |
| 157 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) { | |
| 158 existing_user_controller()->OnSigninScreenReady(); | |
| 159 set_auto_login_username(kAutoLoginUsername); | |
| 160 set_auto_login_delay(kAutoLoginLongDelay); | |
| 161 | |
| 162 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | |
| 163 ASSERT_TRUE(auto_login_timer()); | |
| 164 EXPECT_TRUE(auto_login_timer()->IsRunning()); | |
| 165 | |
| 166 existing_user_controller()->StopPublicSessionAutoLoginTimer(); | |
| 167 ASSERT_TRUE(auto_login_timer()); | |
| 168 EXPECT_FALSE(auto_login_timer()->IsRunning()); | |
| 169 } | |
| 170 | |
| 171 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) { | |
| 172 existing_user_controller()->OnSigninScreenReady(); | |
| 173 set_auto_login_username(kAutoLoginUsername); | |
| 174 | |
| 175 // Timer starts off not running. | |
| 176 EXPECT_FALSE(auto_login_timer()); | |
| 177 | |
| 178 // When the timer isn't running, nothing should happen. | |
| 179 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); | |
| 180 EXPECT_FALSE(auto_login_timer()); | |
| 181 | |
| 182 // Start the timer. | |
| 183 set_auto_login_delay(kAutoLoginLongDelay); | |
| 184 existing_user_controller()->StartPublicSessionAutoLoginTimer(); | |
| 185 ASSERT_TRUE(auto_login_timer()); | |
| 186 EXPECT_TRUE(auto_login_timer()->IsRunning()); | |
| 187 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | |
| 188 kAutoLoginLongDelay); | |
| 189 | |
| 190 // User activity should restart the timer, so check to see that the | |
| 191 // timer delay was modified. | |
| 192 set_auto_login_delay(kAutoLoginShortDelay); | |
| 193 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); | |
| 194 ASSERT_TRUE(auto_login_timer()); | |
| 195 EXPECT_TRUE(auto_login_timer()->IsRunning()); | |
| 196 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | |
| 197 kAutoLoginShortDelay); | |
| 198 } | |
| 199 | |
| 200 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) { | |
| 201 existing_user_controller()->OnSigninScreenReady(); | |
| 202 | |
| 203 // Timer shouldn't start when the policy is disabled. | |
|
bartfab (slow)
2013/03/07 12:17:23
You are not really disabling the policy here, you
dconnelly
2013/03/07 14:45:19
Yes. This is redundant. It seemed more clear to do
| |
| 204 SetAutoLoginSettings("", 0); | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: Use kAutoLoginNoDelay
dconnelly
2013/03/07 14:45:19
Done.
| |
| 205 ConfigureAutoLogin(); | |
| 206 EXPECT_FALSE(auto_login_timer()); | |
| 207 EXPECT_EQ(auto_login_delay(), 0); | |
|
bartfab (slow)
2013/03/07 12:17:23
Nit: Use kAutoLoginNoDelay
dconnelly
2013/03/07 14:45:19
Done.
| |
| 208 EXPECT_EQ(auto_login_username(), ""); | |
| 209 | |
| 210 // Timer shouldn't start when the delay alone is set. | |
| 211 SetAutoLoginSettings("", kAutoLoginShortDelay); | |
| 212 ConfigureAutoLogin(); | |
| 213 EXPECT_FALSE(auto_login_timer()); | |
| 214 EXPECT_EQ(auto_login_delay(), kAutoLoginShortDelay); | |
| 215 EXPECT_EQ(auto_login_username(), ""); | |
| 216 | |
| 217 // Timer should start when the username is set. | |
| 218 SetAutoLoginSettings(kAutoLoginUsername, kAutoLoginShortDelay); | |
| 219 ConfigureAutoLogin(); | |
| 220 ASSERT_TRUE(auto_login_timer()); | |
| 221 EXPECT_TRUE(auto_login_timer()->IsRunning()); | |
| 222 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | |
| 223 kAutoLoginShortDelay); | |
| 224 EXPECT_EQ(auto_login_delay(), kAutoLoginShortDelay); | |
| 225 EXPECT_EQ(auto_login_username(), kAutoLoginUsername); | |
| 226 | |
| 227 // Timer should restart when the delay is changed. | |
| 228 SetAutoLoginSettings(kAutoLoginUsername, kAutoLoginLongDelay); | |
| 229 ConfigureAutoLogin(); | |
| 230 ASSERT_TRUE(auto_login_timer()); | |
| 231 EXPECT_TRUE(auto_login_timer()->IsRunning()); | |
| 232 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | |
| 233 kAutoLoginLongDelay); | |
| 234 EXPECT_EQ(auto_login_delay(), kAutoLoginLongDelay); | |
| 235 EXPECT_EQ(auto_login_username(), kAutoLoginUsername); | |
| 236 | |
| 237 // Timer should stop when the username is unset. | |
| 238 SetAutoLoginSettings("", kAutoLoginLongDelay); | |
| 239 ConfigureAutoLogin(); | |
| 240 ASSERT_TRUE(auto_login_timer()); | |
| 241 EXPECT_FALSE(auto_login_timer()->IsRunning()); | |
| 242 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), | |
| 243 kAutoLoginLongDelay); | |
| 244 EXPECT_EQ(auto_login_username(), ""); | |
| 245 EXPECT_EQ(auto_login_delay(), kAutoLoginLongDelay); | |
| 246 } | |
| 247 | |
| 248 } // namespace chromeos | |
| OLD | NEW |