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

Side by Side Diff: chrome/browser/signin/easy_unlock_auth_attempt_unittest.cc

Issue 2937553002: Create Mojo Struct for user information used in login/lock screen. (Closed)
Patch Set: rebase Created 3 years, 6 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/signin/easy_unlock_auth_attempt.h" 5 #include "chrome/browser/signin/easy_unlock_auth_attempt.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 STATE_NONE, 110 STATE_NONE,
111 STATE_ATTEMPTING_UNLOCK, 111 STATE_ATTEMPTING_UNLOCK,
112 STATE_UNLOCK_CANCELED, 112 STATE_UNLOCK_CANCELED,
113 STATE_UNLOCK_DONE, 113 STATE_UNLOCK_DONE,
114 STATE_ATTEMPTING_SIGNIN, 114 STATE_ATTEMPTING_SIGNIN,
115 STATE_SIGNIN_CANCELED, 115 STATE_SIGNIN_CANCELED,
116 STATE_SIGNIN_DONE 116 STATE_SIGNIN_DONE
117 }; 117 };
118 118
119 explicit TestLockHandler(const AccountId& account_id) 119 explicit TestLockHandler(const AccountId& account_id)
120 : state_(STATE_NONE), auth_type_(USER_CLICK), account_id_(account_id) {} 120 : state_(STATE_NONE),
121 auth_type_(proximity_auth::mojom::AuthType::USER_CLICK),
122 account_id_(account_id) {}
121 123
122 ~TestLockHandler() override {} 124 ~TestLockHandler() override {}
123 125
124 void set_state(AuthState value) { state_ = value; } 126 void set_state(AuthState value) { state_ = value; }
125 AuthState state() const { return state_; } 127 AuthState state() const { return state_; }
126 128
127 // Sets the secret that is expected to be sent to |AttemptEasySignin| 129 // Sets the secret that is expected to be sent to |AttemptEasySignin|
128 void set_expected_secret(const std::string& value) { 130 void set_expected_secret(const std::string& value) {
129 expected_secret_ = value; 131 expected_secret_ = value;
130 } 132 }
131 133
132 // Not using |SetAuthType| to make sure it's not called during tests. 134 // Not using |SetAuthType| to make sure it's not called during tests.
133 void set_auth_type(AuthType value) { auth_type_ = value; } 135 void set_auth_type(proximity_auth::mojom::AuthType value) {
136 auth_type_ = value;
137 }
134 138
135 // proximity_auth::ScreenlockBridge::LockHandler implementation: 139 // proximity_auth::ScreenlockBridge::LockHandler implementation:
136 void ShowBannerMessage(const base::string16& message) override { 140 void ShowBannerMessage(const base::string16& message) override {
137 ADD_FAILURE() << "Should not be reached."; 141 ADD_FAILURE() << "Should not be reached.";
138 } 142 }
139 143
140 void ShowUserPodCustomIcon( 144 void ShowUserPodCustomIcon(
141 const AccountId& account_id, 145 const AccountId& account_id,
142 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& icon) 146 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& icon)
143 override { 147 override {
144 ADD_FAILURE() << "Should not be reached."; 148 ADD_FAILURE() << "Should not be reached.";
145 } 149 }
146 150
147 void HideUserPodCustomIcon(const AccountId& account_id) override { 151 void HideUserPodCustomIcon(const AccountId& account_id) override {
148 ADD_FAILURE() << "Should not be reached."; 152 ADD_FAILURE() << "Should not be reached.";
149 } 153 }
150 154
151 void EnableInput() override { 155 void EnableInput() override {
152 ASSERT_EQ(STATE_ATTEMPTING_UNLOCK, state_); 156 ASSERT_EQ(STATE_ATTEMPTING_UNLOCK, state_);
153 state_ = STATE_UNLOCK_CANCELED; 157 state_ = STATE_UNLOCK_CANCELED;
154 } 158 }
155 159
156 void SetAuthType(const AccountId& account_id, 160 void SetAuthType(const AccountId& account_id,
157 AuthType auth_type, 161 proximity_auth::mojom::AuthType auth_type,
158 const base::string16& auth_value) override { 162 const base::string16& auth_value) override {
159 ADD_FAILURE() << "Should not be reached."; 163 ADD_FAILURE() << "Should not be reached.";
160 } 164 }
161 165
162 AuthType GetAuthType(const AccountId& account_id) const override { 166 proximity_auth::mojom::AuthType GetAuthType(
167 const AccountId& account_id) const override {
163 return auth_type_; 168 return auth_type_;
164 } 169 }
165 170
166 ScreenType GetScreenType() const override { 171 ScreenType GetScreenType() const override {
167 // Return an arbitrary value; this is not used by the test code. 172 // Return an arbitrary value; this is not used by the test code.
168 return LOCK_SCREEN; 173 return LOCK_SCREEN;
169 } 174 }
170 175
171 void Unlock(const AccountId& account_id) override { 176 void Unlock(const AccountId& account_id) override {
172 ASSERT_TRUE(account_id_ == account_id) 177 ASSERT_TRUE(account_id_ == account_id)
(...skipping 19 matching lines...) Expand all
192 ASSERT_EQ(chromeos::EasyUnlockKeyManager::GetKeyLabel(0u), key_label); 197 ASSERT_EQ(chromeos::EasyUnlockKeyManager::GetKeyLabel(0u), key_label);
193 state_ = STATE_SIGNIN_DONE; 198 state_ = STATE_SIGNIN_DONE;
194 } 199 }
195 #else // if !defined(OS_CHROMEOS) 200 #else // if !defined(OS_CHROMEOS)
196 ADD_FAILURE() << "Should not be reached."; 201 ADD_FAILURE() << "Should not be reached.";
197 #endif 202 #endif
198 } 203 }
199 204
200 private: 205 private:
201 AuthState state_; 206 AuthState state_;
202 AuthType auth_type_; 207 proximity_auth::mojom::AuthType auth_type_;
203 const AccountId account_id_; 208 const AccountId account_id_;
204 std::string expected_secret_; 209 std::string expected_secret_;
205 210
206 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); 211 DISALLOW_COPY_AND_ASSIGN(TestLockHandler);
207 }; 212 };
208 213
209 class EasyUnlockAuthAttemptUnlockTest : public testing::Test { 214 class EasyUnlockAuthAttemptUnlockTest : public testing::Test {
210 public: 215 public:
211 EasyUnlockAuthAttemptUnlockTest() {} 216 EasyUnlockAuthAttemptUnlockTest() {}
212 ~EasyUnlockAuthAttemptUnlockTest() override {} 217 ~EasyUnlockAuthAttemptUnlockTest() override {}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_FALSE(auth_attempt_->Start()); 254 EXPECT_FALSE(auth_attempt_->Start());
250 EXPECT_EQ(0u, app_manager_->auth_attempt_count()); 255 EXPECT_EQ(0u, app_manager_->auth_attempt_count());
251 } 256 }
252 257
253 TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenAuthTypeIsPassword) { 258 TEST_F(EasyUnlockAuthAttemptUnlockTest, StartWhenAuthTypeIsPassword) {
254 InitScreenLock(); 259 InitScreenLock();
255 ASSERT_TRUE(proximity_auth::ScreenlockBridge::Get()->IsLocked()); 260 ASSERT_TRUE(proximity_auth::ScreenlockBridge::Get()->IsLocked());
256 ASSERT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state()); 261 ASSERT_EQ(TestLockHandler::STATE_ATTEMPTING_UNLOCK, lock_handler_->state());
257 262
258 lock_handler_->set_auth_type( 263 lock_handler_->set_auth_type(
259 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD); 264 proximity_auth::mojom::AuthType::OFFLINE_PASSWORD);
260 265
261 EXPECT_FALSE(auth_attempt_->Start()); 266 EXPECT_FALSE(auth_attempt_->Start());
262 267
263 EXPECT_EQ(0u, app_manager_->auth_attempt_count()); 268 EXPECT_EQ(0u, app_manager_->auth_attempt_count());
264 EXPECT_EQ(TestLockHandler::STATE_UNLOCK_CANCELED, lock_handler_->state()); 269 EXPECT_EQ(TestLockHandler::STATE_UNLOCK_CANCELED, lock_handler_->state());
265 } 270 }
266 271
267 TEST_F(EasyUnlockAuthAttemptUnlockTest, 272 TEST_F(EasyUnlockAuthAttemptUnlockTest,
268 StartWhenDispatchingAuthAttemptEventFails) { 273 StartWhenDispatchingAuthAttemptEventFails) {
269 InitScreenLock(); 274 InitScreenLock();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 EXPECT_FALSE(auth_attempt_->Start()); 412 EXPECT_FALSE(auth_attempt_->Start());
408 EXPECT_EQ(0u, app_manager_->auth_attempt_count()); 413 EXPECT_EQ(0u, app_manager_->auth_attempt_count());
409 } 414 }
410 415
411 TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenAuthTypeIsPassword) { 416 TEST_F(EasyUnlockAuthAttemptSigninTest, StartWhenAuthTypeIsPassword) {
412 InitScreenLock(); 417 InitScreenLock();
413 ASSERT_TRUE(proximity_auth::ScreenlockBridge::Get()->IsLocked()); 418 ASSERT_TRUE(proximity_auth::ScreenlockBridge::Get()->IsLocked());
414 ASSERT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); 419 ASSERT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
415 420
416 lock_handler_->set_auth_type( 421 lock_handler_->set_auth_type(
417 proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD); 422 proximity_auth::mojom::AuthType::OFFLINE_PASSWORD);
418 423
419 EXPECT_FALSE(auth_attempt_->Start()); 424 EXPECT_FALSE(auth_attempt_->Start());
420 425
421 EXPECT_EQ(0u, app_manager_->auth_attempt_count()); 426 EXPECT_EQ(0u, app_manager_->auth_attempt_count());
422 EXPECT_EQ(TestLockHandler::STATE_SIGNIN_CANCELED, lock_handler_->state()); 427 EXPECT_EQ(TestLockHandler::STATE_SIGNIN_CANCELED, lock_handler_->state());
423 } 428 }
424 429
425 TEST_F(EasyUnlockAuthAttemptSigninTest, 430 TEST_F(EasyUnlockAuthAttemptSigninTest,
426 StartWhenDispatchingAuthAttemptEventFails) { 431 StartWhenDispatchingAuthAttemptEventFails) {
427 InitScreenLock(); 432 InitScreenLock();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state()); 568 EXPECT_EQ(TestLockHandler::STATE_ATTEMPTING_SIGNIN, lock_handler_->state());
564 569
565 auth_attempt_->FinalizeSignin(test_account_id1_, GetWrappedSecret(), 570 auth_attempt_->FinalizeSignin(test_account_id1_, GetWrappedSecret(),
566 GetSessionKey()); 571 GetSessionKey());
567 572
568 EXPECT_EQ(TestLockHandler::STATE_SIGNIN_DONE, lock_handler_->state()); 573 EXPECT_EQ(TestLockHandler::STATE_SIGNIN_DONE, lock_handler_->state());
569 } 574 }
570 #endif // defined(OS_CHROMEOS) 575 #endif // defined(OS_CHROMEOS)
571 576
572 } // namespace 577 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_auth_attempt.cc ('k') | chrome/browser/signin/easy_unlock_screenlock_state_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698