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

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

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

Powered by Google App Engine
This is Rietveld 408576698