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

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

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Update after review. Created 5 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 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/existing_user_controller.h" 9 #include "chrome/browser/chromeos/login/existing_user_controller.h"
10 #include "chrome/browser/chromeos/login/ui/mock_login_display.h" 10 #include "chrome/browser/chromeos/login/ui/mock_login_display.h"
(...skipping 12 matching lines...) Expand all
23 23
24 using testing::AnyNumber; 24 using testing::AnyNumber;
25 using testing::Return; 25 using testing::Return;
26 using testing::ReturnNull; 26 using testing::ReturnNull;
27 using testing::_; 27 using testing::_;
28 28
29 namespace chromeos { 29 namespace chromeos {
30 30
31 namespace { 31 namespace {
32 32
33 const char kAutoLoginAccountId[] = "public_session_user@localhost";
34 // These values are only used to test the configuration. They don't 33 // These values are only used to test the configuration. They don't
35 // delay the test. 34 // delay the test.
36 const int kAutoLoginDelay1 = 60000; 35 const int kAutoLoginDelay1 = 60000;
37 const int kAutoLoginDelay2 = 180000; 36 const int kAutoLoginDelay2 = 180000;
38 37
39 } // namespace 38 } // namespace
40 39
41 class ExistingUserControllerAutoLoginTest : public ::testing::Test { 40 class ExistingUserControllerAutoLoginTest : public ::testing::Test {
42 protected: 41 protected:
43 ExistingUserControllerAutoLoginTest() 42 ExistingUserControllerAutoLoginTest()
44 : auto_login_user_id_(policy::GenerateDeviceLocalAccountUserId( 43 : ui_thread_(content::BrowserThread::UI, &message_loop_),
45 kAutoLoginAccountId,
46 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
47 ui_thread_(content::BrowserThread::UI, &message_loop_),
48 local_state_(TestingBrowserProcess::GetGlobal()), 44 local_state_(TestingBrowserProcess::GetGlobal()),
49 mock_user_manager_(new MockUserManager()), 45 mock_user_manager_(new MockUserManager()),
50 scoped_user_manager_(mock_user_manager_) { 46 scoped_user_manager_(mock_user_manager_) {}
51 }
52 47
53 void SetUp() override { 48 void SetUp() override {
54 mock_login_display_host_.reset(new MockLoginDisplayHost); 49 mock_login_display_host_.reset(new MockLoginDisplayHost);
55 mock_login_display_ = new MockLoginDisplay(); 50 mock_login_display_ = new MockLoginDisplay();
56 51
57 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 52 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
58 .Times(1) 53 .Times(1)
59 .WillOnce(Return(mock_login_display_)); 54 .WillOnce(Return(mock_login_display_));
60 55
61 EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AnyNumber()); 56 EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AnyNumber());
62 EXPECT_CALL(*mock_user_manager_, FindUser(_)) 57 EXPECT_CALL(*mock_user_manager_, FindUser(_))
63 .WillRepeatedly(ReturnNull()); 58 .WillRepeatedly(ReturnNull());
64 EXPECT_CALL(*mock_user_manager_, FindUser(auto_login_user_id_)) 59 EXPECT_CALL(*mock_user_manager_, FindUser(auto_login_account_id_))
65 .WillRepeatedly(Return( 60 .WillRepeatedly(Return(mock_user_manager_->CreatePublicAccountUser(
66 mock_user_manager_->CreatePublicAccountUser(auto_login_user_id_))); 61 auto_login_account_id_)));
67 62
68 existing_user_controller_.reset( 63 existing_user_controller_.reset(
69 new ExistingUserController(mock_login_display_host_.get())); 64 new ExistingUserController(mock_login_display_host_.get()));
70 65
71 scoped_ptr<base::DictionaryValue> account(new base::DictionaryValue); 66 scoped_ptr<base::DictionaryValue> account(new base::DictionaryValue);
72 account->SetStringWithoutPathExpansion( 67 account->SetStringWithoutPathExpansion(
73 kAccountsPrefDeviceLocalAccountsKeyId, 68 kAccountsPrefDeviceLocalAccountsKeyId,
74 kAutoLoginAccountId); 69 auto_login_account_id_.GetUserEmail());
75 account->SetIntegerWithoutPathExpansion( 70 account->SetIntegerWithoutPathExpansion(
76 kAccountsPrefDeviceLocalAccountsKeyType, 71 kAccountsPrefDeviceLocalAccountsKeyType,
77 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION); 72 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION);
78 base::ListValue accounts; 73 base::ListValue accounts;
79 accounts.Append(account.release()); 74 accounts.Append(account.release());
80 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, accounts); 75 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, accounts);
81 76
82 // Prevent settings changes from auto-starting the timer. 77 // Prevent settings changes from auto-starting the timer.
83 existing_user_controller_-> 78 existing_user_controller_->
84 local_account_auto_login_id_subscription_.reset(); 79 local_account_auto_login_id_subscription_.reset();
85 existing_user_controller_-> 80 existing_user_controller_->
86 local_account_auto_login_delay_subscription_.reset(); 81 local_account_auto_login_delay_subscription_.reset();
87 } 82 }
88 83
89 const ExistingUserController* existing_user_controller() const { 84 const ExistingUserController* existing_user_controller() const {
90 return ExistingUserController::current_controller(); 85 return ExistingUserController::current_controller();
91 } 86 }
92 87
93 ExistingUserController* existing_user_controller() { 88 ExistingUserController* existing_user_controller() {
94 return ExistingUserController::current_controller(); 89 return ExistingUserController::current_controller();
95 } 90 }
96 91
97 void SetAutoLoginSettings(const std::string& account_id, int delay) { 92 void SetAutoLoginSettings(const AccountId& account_id, int delay) {
98 CrosSettings::Get()->SetString( 93 CrosSettings::Get()->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId,
99 kAccountsPrefDeviceLocalAccountAutoLoginId, 94 account_id.GetUserEmail());
100 account_id);
101 CrosSettings::Get()->SetInteger( 95 CrosSettings::Get()->SetInteger(
102 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 96 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
103 delay); 97 delay);
104 } 98 }
105 99
106 // ExistingUserController private member accessors. 100 // ExistingUserController private member accessors.
107 base::OneShotTimer* auto_login_timer() { 101 base::OneShotTimer* auto_login_timer() {
108 return existing_user_controller()->auto_login_timer_.get(); 102 return existing_user_controller()->auto_login_timer_.get();
109 } 103 }
110 104
(...skipping 15 matching lines...) Expand all
126 return existing_user_controller()->is_login_in_progress_; 120 return existing_user_controller()->is_login_in_progress_;
127 } 121 }
128 void set_is_login_in_progress(bool is_login_in_progress) { 122 void set_is_login_in_progress(bool is_login_in_progress) {
129 existing_user_controller()->is_login_in_progress_ = is_login_in_progress; 123 existing_user_controller()->is_login_in_progress_ = is_login_in_progress;
130 } 124 }
131 125
132 void ConfigureAutoLogin() { 126 void ConfigureAutoLogin() {
133 existing_user_controller()->ConfigurePublicSessionAutoLogin(); 127 existing_user_controller()->ConfigurePublicSessionAutoLogin();
134 } 128 }
135 129
136 const std::string auto_login_user_id_; 130 const AccountId auto_login_account_id_ =
131 AccountId::FromUserEmail(policy::GenerateDeviceLocalAccountUserId(
132 "public_session_user@localhost",
133 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION));
137 134
138 private: 135 private:
139 // |mock_login_display_| is owned by the ExistingUserController, which calls 136 // |mock_login_display_| is owned by the ExistingUserController, which calls
140 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. 137 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
141 MockLoginDisplay* mock_login_display_; 138 MockLoginDisplay* mock_login_display_;
142 139
143 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; 140 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
144 base::MessageLoopForUI message_loop_; 141 base::MessageLoopForUI message_loop_;
145 content::TestBrowserThread ui_thread_; 142 content::TestBrowserThread ui_thread_;
146 ScopedTestingLocalState local_state_; 143 ScopedTestingLocalState local_state_;
147 144
148 // Required by ExistingUserController: 145 // Required by ExistingUserController:
149 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 146 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
150 ScopedTestCrosSettings test_cros_settings_; 147 ScopedTestCrosSettings test_cros_settings_;
151 MockUserManager* mock_user_manager_; 148 MockUserManager* mock_user_manager_;
152 ScopedUserManagerEnabler scoped_user_manager_; 149 ScopedUserManagerEnabler scoped_user_manager_;
153 150
154 // |existing_user_controller_| must be destroyed before 151 // |existing_user_controller_| must be destroyed before
155 // |device_settings_test_helper_|. 152 // |device_settings_test_helper_|.
156 scoped_ptr<ExistingUserController> existing_user_controller_; 153 scoped_ptr<ExistingUserController> existing_user_controller_;
157 }; 154 };
158 155
159 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) { 156 TEST_F(ExistingUserControllerAutoLoginTest, StartAutoLoginTimer) {
160 // Timer shouldn't start until signin screen is ready. 157 // Timer shouldn't start until signin screen is ready.
161 set_auto_login_username(auto_login_user_id_); 158 set_auto_login_username(auto_login_account_id_.GetUserEmail());
162 set_auto_login_delay(kAutoLoginDelay2); 159 set_auto_login_delay(kAutoLoginDelay2);
163 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 160 existing_user_controller()->StartPublicSessionAutoLoginTimer();
164 EXPECT_FALSE(auto_login_timer()); 161 EXPECT_FALSE(auto_login_timer());
165 162
166 // Timer shouldn't start if the policy isn't set. 163 // Timer shouldn't start if the policy isn't set.
167 set_auto_login_username(""); 164 set_auto_login_username("");
168 existing_user_controller()->OnSigninScreenReady(); 165 existing_user_controller()->OnSigninScreenReady();
169 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 166 existing_user_controller()->StartPublicSessionAutoLoginTimer();
170 EXPECT_FALSE(auto_login_timer()); 167 EXPECT_FALSE(auto_login_timer());
171 168
172 // Timer shouldn't fire in the middle of a login attempt. 169 // Timer shouldn't fire in the middle of a login attempt.
173 set_auto_login_username(auto_login_user_id_); 170 set_auto_login_username(auto_login_account_id_.GetUserEmail());
174 set_is_login_in_progress(true); 171 set_is_login_in_progress(true);
175 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 172 existing_user_controller()->StartPublicSessionAutoLoginTimer();
176 EXPECT_FALSE(auto_login_timer()); 173 EXPECT_FALSE(auto_login_timer());
177 174
178 // Otherwise start. 175 // Otherwise start.
179 set_is_login_in_progress(false); 176 set_is_login_in_progress(false);
180 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 177 existing_user_controller()->StartPublicSessionAutoLoginTimer();
181 ASSERT_TRUE(auto_login_timer()); 178 ASSERT_TRUE(auto_login_timer());
182 EXPECT_TRUE(auto_login_timer()->IsRunning()); 179 EXPECT_TRUE(auto_login_timer()->IsRunning());
183 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 180 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
184 kAutoLoginDelay2); 181 kAutoLoginDelay2);
185 } 182 }
186 183
187 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) { 184 TEST_F(ExistingUserControllerAutoLoginTest, StopAutoLoginTimer) {
188 existing_user_controller()->OnSigninScreenReady(); 185 existing_user_controller()->OnSigninScreenReady();
189 set_auto_login_username(auto_login_user_id_); 186 set_auto_login_username(auto_login_account_id_.GetUserEmail());
190 set_auto_login_delay(kAutoLoginDelay2); 187 set_auto_login_delay(kAutoLoginDelay2);
191 188
192 existing_user_controller()->StartPublicSessionAutoLoginTimer(); 189 existing_user_controller()->StartPublicSessionAutoLoginTimer();
193 ASSERT_TRUE(auto_login_timer()); 190 ASSERT_TRUE(auto_login_timer());
194 EXPECT_TRUE(auto_login_timer()->IsRunning()); 191 EXPECT_TRUE(auto_login_timer()->IsRunning());
195 192
196 existing_user_controller()->StopPublicSessionAutoLoginTimer(); 193 existing_user_controller()->StopPublicSessionAutoLoginTimer();
197 ASSERT_TRUE(auto_login_timer()); 194 ASSERT_TRUE(auto_login_timer());
198 EXPECT_FALSE(auto_login_timer()->IsRunning()); 195 EXPECT_FALSE(auto_login_timer()->IsRunning());
199 } 196 }
200 197
201 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) { 198 TEST_F(ExistingUserControllerAutoLoginTest, ResetAutoLoginTimer) {
202 existing_user_controller()->OnSigninScreenReady(); 199 existing_user_controller()->OnSigninScreenReady();
203 set_auto_login_username(auto_login_user_id_); 200 set_auto_login_username(auto_login_account_id_.GetUserEmail());
204 201
205 // Timer starts off not running. 202 // Timer starts off not running.
206 EXPECT_FALSE(auto_login_timer()); 203 EXPECT_FALSE(auto_login_timer());
207 204
208 // When the timer isn't running, nothing should happen. 205 // When the timer isn't running, nothing should happen.
209 existing_user_controller()->ResetPublicSessionAutoLoginTimer(); 206 existing_user_controller()->ResetPublicSessionAutoLoginTimer();
210 EXPECT_FALSE(auto_login_timer()); 207 EXPECT_FALSE(auto_login_timer());
211 208
212 // Start the timer. 209 // Start the timer.
213 set_auto_login_delay(kAutoLoginDelay2); 210 set_auto_login_delay(kAutoLoginDelay2);
(...skipping 16 matching lines...) Expand all
230 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) { 227 TEST_F(ExistingUserControllerAutoLoginTest, ConfigureAutoLogin) {
231 existing_user_controller()->OnSigninScreenReady(); 228 existing_user_controller()->OnSigninScreenReady();
232 229
233 // Timer shouldn't start when the policy is disabled. 230 // Timer shouldn't start when the policy is disabled.
234 ConfigureAutoLogin(); 231 ConfigureAutoLogin();
235 EXPECT_FALSE(auto_login_timer()); 232 EXPECT_FALSE(auto_login_timer());
236 EXPECT_EQ(auto_login_delay(), 0); 233 EXPECT_EQ(auto_login_delay(), 0);
237 EXPECT_EQ(auto_login_username(), ""); 234 EXPECT_EQ(auto_login_username(), "");
238 235
239 // Timer shouldn't start when the delay alone is set. 236 // Timer shouldn't start when the delay alone is set.
240 SetAutoLoginSettings("", kAutoLoginDelay1); 237 SetAutoLoginSettings(EmptyAccountId(), kAutoLoginDelay1);
241 ConfigureAutoLogin(); 238 ConfigureAutoLogin();
242 EXPECT_FALSE(auto_login_timer()); 239 EXPECT_FALSE(auto_login_timer());
243 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1); 240 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1);
244 EXPECT_EQ(auto_login_username(), ""); 241 EXPECT_EQ(auto_login_username(), "");
245 242
246 // Timer should start when the account ID is set. 243 // Timer should start when the account ID is set.
247 SetAutoLoginSettings(kAutoLoginAccountId, kAutoLoginDelay1); 244 SetAutoLoginSettings(auto_login_account_id_, kAutoLoginDelay1);
248 ConfigureAutoLogin(); 245 ConfigureAutoLogin();
249 ASSERT_TRUE(auto_login_timer()); 246 ASSERT_TRUE(auto_login_timer());
250 EXPECT_TRUE(auto_login_timer()->IsRunning()); 247 EXPECT_TRUE(auto_login_timer()->IsRunning());
251 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 248 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
252 kAutoLoginDelay1); 249 kAutoLoginDelay1);
253 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1); 250 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay1);
254 EXPECT_EQ(auto_login_username(), auto_login_user_id_); 251 EXPECT_EQ(auto_login_username(), auto_login_account_id_.GetUserEmail());
255 252
256 // Timer should restart when the delay is changed. 253 // Timer should restart when the delay is changed.
257 SetAutoLoginSettings(kAutoLoginAccountId, kAutoLoginDelay2); 254 SetAutoLoginSettings(auto_login_account_id_, kAutoLoginDelay2);
258 ConfigureAutoLogin(); 255 ConfigureAutoLogin();
259 ASSERT_TRUE(auto_login_timer()); 256 ASSERT_TRUE(auto_login_timer());
260 EXPECT_TRUE(auto_login_timer()->IsRunning()); 257 EXPECT_TRUE(auto_login_timer()->IsRunning());
261 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 258 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
262 kAutoLoginDelay2); 259 kAutoLoginDelay2);
263 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); 260 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2);
264 EXPECT_EQ(auto_login_username(), auto_login_user_id_); 261 EXPECT_EQ(auto_login_username(), auto_login_account_id_.GetUserEmail());
265 262
266 // Timer should stop when the account ID is unset. 263 // Timer should stop when the account ID is unset.
267 SetAutoLoginSettings("", kAutoLoginDelay2); 264 SetAutoLoginSettings(EmptyAccountId(), kAutoLoginDelay2);
268 ConfigureAutoLogin(); 265 ConfigureAutoLogin();
269 ASSERT_TRUE(auto_login_timer()); 266 ASSERT_TRUE(auto_login_timer());
270 EXPECT_FALSE(auto_login_timer()->IsRunning()); 267 EXPECT_FALSE(auto_login_timer()->IsRunning());
271 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(), 268 EXPECT_EQ(auto_login_timer()->GetCurrentDelay().InMilliseconds(),
272 kAutoLoginDelay2); 269 kAutoLoginDelay2);
273 EXPECT_EQ(auto_login_username(), ""); 270 EXPECT_EQ(auto_login_username(), "");
274 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2); 271 EXPECT_EQ(auto_login_delay(), kAutoLoginDelay2);
275 } 272 }
276 273
277 } // namespace chromeos 274 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698