OLD | NEW |
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_service.h" | 5 #include "chrome/browser/signin/easy_unlock_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 27 matching lines...) Expand all Loading... |
38 using chromeos::ProfileHelper; | 38 using chromeos::ProfileHelper; |
39 using device::MockBluetoothAdapter; | 39 using device::MockBluetoothAdapter; |
40 using testing::_; | 40 using testing::_; |
41 using testing::AnyNumber; | 41 using testing::AnyNumber; |
42 using testing::Return; | 42 using testing::Return; |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 // IDs for fake users used in tests. | 46 // IDs for fake users used in tests. |
47 const char kTestUserPrimary[] = "primary_user@nowhere.com"; | 47 const char kTestUserPrimary[] = "primary_user@nowhere.com"; |
| 48 const char kPrimaryGaiaId[] = "1111111111"; |
48 const char kTestUserSecondary[] = "secondary_user@nowhere.com"; | 49 const char kTestUserSecondary[] = "secondary_user@nowhere.com"; |
| 50 const char kSecondaryGaiaId[] = "2222222222"; |
49 | 51 |
50 // App manager to be used in EasyUnlockService tests. | 52 // App manager to be used in EasyUnlockService tests. |
51 // This effectivelly abstracts the extension system from the tests. | 53 // This effectivelly abstracts the extension system from the tests. |
52 class TestAppManager : public EasyUnlockAppManager { | 54 class TestAppManager : public EasyUnlockAppManager { |
53 public: | 55 public: |
54 TestAppManager() | 56 TestAppManager() |
55 : state_(STATE_NOT_LOADED), | 57 : state_(STATE_NOT_LOADED), |
56 app_launch_count_(0u), | 58 app_launch_count_(0u), |
57 reload_count_(0u), | 59 reload_count_(0u), |
58 ready_(false) {} | 60 ready_(false) {} |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 power_manager_client_ = new FakePowerManagerClient; | 217 power_manager_client_ = new FakePowerManagerClient; |
216 dbus_setter->SetPowerManagerClient( | 218 dbus_setter->SetPowerManagerClient( |
217 scoped_ptr<PowerManagerClient>(power_manager_client_)); | 219 scoped_ptr<PowerManagerClient>(power_manager_client_)); |
218 | 220 |
219 ON_CALL(*mock_user_manager_, Shutdown()).WillByDefault(Return()); | 221 ON_CALL(*mock_user_manager_, Shutdown()).WillByDefault(Return()); |
220 ON_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) | 222 ON_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) |
221 .WillByDefault(Return(true)); | 223 .WillByDefault(Return(true)); |
222 ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) | 224 ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) |
223 .WillByDefault(Return(false)); | 225 .WillByDefault(Return(false)); |
224 | 226 |
225 SetUpProfile(&profile_, AccountId::FromUserEmail(kTestUserPrimary)); | 227 SetUpProfile(&profile_, AccountId::FromUserEmailGaiaId( |
| 228 kTestUserPrimary, kPrimaryGaiaId)); |
226 } | 229 } |
227 | 230 |
228 void TearDown() override { | 231 void TearDown() override { |
229 delete app_manager_factory; | 232 delete app_manager_factory; |
230 app_manager_factory = NULL; | 233 app_manager_factory = NULL; |
231 } | 234 } |
232 | 235 |
233 void SetEasyUnlockAllowedPolicy(bool allowed) { | 236 void SetEasyUnlockAllowedPolicy(bool allowed) { |
234 profile_->GetTestingPrefService()->SetManagedPref( | 237 profile_->GetTestingPrefService()->SetManagedPref( |
235 prefs::kEasyUnlockAllowed, new base::FundamentalValue(allowed)); | 238 prefs::kEasyUnlockAllowed, new base::FundamentalValue(allowed)); |
(...skipping 24 matching lines...) Expand all Loading... |
260 | 263 |
261 void SetAppManagerReady(content::BrowserContext* context) { | 264 void SetAppManagerReady(content::BrowserContext* context) { |
262 ASSERT_TRUE(app_manager_factory); | 265 ASSERT_TRUE(app_manager_factory); |
263 TestAppManager* app_manager = app_manager_factory->Find(context); | 266 TestAppManager* app_manager = app_manager_factory->Find(context); |
264 ASSERT_TRUE(app_manager); | 267 ASSERT_TRUE(app_manager); |
265 app_manager->SetReady(); | 268 app_manager->SetReady(); |
266 } | 269 } |
267 | 270 |
268 void SetUpSecondaryProfile() { | 271 void SetUpSecondaryProfile() { |
269 SetUpProfile(&secondary_profile_, | 272 SetUpProfile(&secondary_profile_, |
270 AccountId::FromUserEmail(kTestUserSecondary)); | 273 AccountId::FromUserEmailGaiaId(kTestUserSecondary, |
| 274 kSecondaryGaiaId)); |
271 } | 275 } |
272 | 276 |
273 private: | 277 private: |
274 // Sets up a test profile with a user id. | 278 // Sets up a test profile with a user id. |
275 void SetUpProfile(scoped_ptr<TestingProfile>* profile, | 279 void SetUpProfile(scoped_ptr<TestingProfile>* profile, |
276 const AccountId& account_id) { | 280 const AccountId& account_id) { |
277 ASSERT_TRUE(profile); | 281 ASSERT_TRUE(profile); |
278 ASSERT_FALSE(profile->get()); | 282 ASSERT_FALSE(profile->get()); |
279 | 283 |
280 TestingProfile::Builder builder; | 284 TestingProfile::Builder builder; |
281 builder.AddTestingFactory(EasyUnlockServiceFactory::GetInstance(), | 285 builder.AddTestingFactory(EasyUnlockServiceFactory::GetInstance(), |
282 &CreateEasyUnlockServiceForTest); | 286 &CreateEasyUnlockServiceForTest); |
283 *profile = builder.Build(); | 287 *profile = builder.Build(); |
284 | 288 |
285 mock_user_manager_->AddUser(account_id); | 289 mock_user_manager_->AddUser(account_id); |
286 profile->get()->set_profile_name(account_id.GetUserEmail()); | 290 profile->get()->set_profile_name(account_id.GetUserEmail()); |
287 | 291 |
288 SigninManagerBase* signin_manager = | 292 SigninManagerBase* signin_manager = |
289 SigninManagerFactory::GetForProfile(profile->get()); | 293 SigninManagerFactory::GetForProfile(profile->get()); |
290 signin_manager->SetAuthenticatedAccountInfo(account_id.GetUserEmail(), | 294 signin_manager->SetAuthenticatedAccountInfo(account_id.GetGaiaId(), |
291 account_id.GetUserEmail()); | 295 account_id.GetUserEmail()); |
292 } | 296 } |
293 | 297 |
294 protected: | 298 protected: |
295 scoped_ptr<TestingProfile> profile_; | 299 scoped_ptr<TestingProfile> profile_; |
296 scoped_ptr<TestingProfile> secondary_profile_; | 300 scoped_ptr<TestingProfile> secondary_profile_; |
297 chromeos::MockUserManager* mock_user_manager_; | 301 chromeos::MockUserManager* mock_user_manager_; |
298 | 302 |
299 private: | 303 private: |
300 content::TestBrowserThreadBundle thread_bundle_; | 304 content::TestBrowserThreadBundle thread_bundle_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 TEST_F(EasyUnlockServiceTest, NotAllowedForEphemeralAccounts) { | 372 TEST_F(EasyUnlockServiceTest, NotAllowedForEphemeralAccounts) { |
369 ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) | 373 ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) |
370 .WillByDefault(Return(true)); | 374 .WillByDefault(Return(true)); |
371 | 375 |
372 SetAppManagerReady(profile_.get()); | 376 SetAppManagerReady(profile_.get()); |
373 EXPECT_FALSE(EasyUnlockService::Get(profile_.get())->IsAllowed()); | 377 EXPECT_FALSE(EasyUnlockService::Get(profile_.get())->IsAllowed()); |
374 EXPECT_TRUE( | 378 EXPECT_TRUE( |
375 EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED)); | 379 EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED)); |
376 } | 380 } |
377 | 381 |
| 382 TEST_F(EasyUnlockServiceTest, GetAccountId) { |
| 383 EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserPrimary, kPrimaryGaiaId), |
| 384 EasyUnlockService::Get(profile_.get())->GetAccountId()); |
| 385 |
| 386 SetUpSecondaryProfile(); |
| 387 EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserSecondary, |
| 388 kSecondaryGaiaId), |
| 389 EasyUnlockService::Get(secondary_profile_.get())->GetAccountId()); |
| 390 } |
| 391 |
378 } // namespace | 392 } // namespace |
OLD | NEW |