Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/test/ash_test_base.h" | 5 #include "ash/test/ash_test_base.h" |
| 6 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | |
| 6 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 7 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 7 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 8 #include "chrome/browser/signin/account_tracker_service_factory.h" | 9 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 9 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 10 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 11 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 12 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/signin/core/account_id/account_id.h" | 14 #include "components/signin/core/account_id/account_id.h" |
| 14 #include "components/signin/core/browser/account_tracker_service.h" | 15 #include "components/signin/core/browser/account_tracker_service.h" |
| 15 #include "components/user_manager/fake_user_manager.h" | |
| 16 #include "components/user_manager/user.h" | 16 #include "components/user_manager/user.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kTestGaiaId[] = "gaia_id"; | 23 const char kTestGaiaId[] = "gaia_id"; |
| 24 const char kTestAccountId[] = "test@test.com"; | 24 const char kTestAccountId[] = "test@test.com"; |
| 25 | 25 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 class MultiUserUtilTest : public AshTestBase { | 53 class MultiUserUtilTest : public AshTestBase { |
| 54 public: | 54 public: |
| 55 MultiUserUtilTest() {} | 55 MultiUserUtilTest() {} |
| 56 ~MultiUserUtilTest() override{}; | 56 ~MultiUserUtilTest() override{}; |
| 57 | 57 |
| 58 void SetUp() override { | 58 void SetUp() override { |
| 59 AshTestBase::SetUp(); | 59 AshTestBase::SetUp(); |
| 60 | 60 |
| 61 fake_user_manager_ = new user_manager::FakeUserManager; | 61 fake_user_manager_ = new chromeos::FakeChromeUserManager; |
| 62 user_manager_enabler_.reset( | 62 user_manager_enabler_.reset( |
| 63 new chromeos::ScopedUserManagerEnabler(fake_user_manager_)); | 63 new chromeos::ScopedUserManagerEnabler(fake_user_manager_)); |
| 64 | 64 |
| 65 TestingProfile::Builder builder; | 65 TestingProfile::Builder builder; |
| 66 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 66 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| 67 BuildFakeSigninManagerBase); | 67 BuildFakeSigninManagerBase); |
| 68 TestingProfile* profile = builder.Build().release(); | 68 TestingProfile* profile = builder.Build().release(); |
| 69 profile_.reset(new MultiUserTestingProfile(profile)); | 69 profile_.reset(new MultiUserTestingProfile(profile)); |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 98 void SimulateTokenRevoked(const std::string& account_id) { | 98 void SimulateTokenRevoked(const std::string& account_id) { |
| 99 AccountTrackerService* account_tracker_service = | 99 AccountTrackerService* account_tracker_service = |
| 100 AccountTrackerServiceFactory::GetForProfile(profile_->profile()); | 100 AccountTrackerServiceFactory::GetForProfile(profile_->profile()); |
| 101 account_tracker_service->RemoveAccount(account_id); | 101 account_tracker_service->RemoveAccount(account_id); |
| 102 } | 102 } |
| 103 | 103 |
| 104 MultiUserTestingProfile* profile() { return profile_.get(); } | 104 MultiUserTestingProfile* profile() { return profile_.get(); } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 std::unique_ptr<MultiUserTestingProfile> profile_; | 107 std::unique_ptr<MultiUserTestingProfile> profile_; |
| 108 user_manager::FakeUserManager* fake_user_manager_; // Not owned. | 108 chromeos::FakeChromeUserManager* fake_user_manager_; // Not owned. |
|
msw
2016/11/17 18:31:22
nit: okay, this one is used; it'd be nice to eithe
yoshiki
2016/11/18 15:54:15
Done.
| |
| 109 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 109 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 110 | 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(MultiUserUtilTest); | 111 DISALLOW_COPY_AND_ASSIGN(MultiUserUtilTest); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 // Test that during the session it will always return a valid account id if a | 114 // Test that during the session it will always return a valid account id if a |
| 115 // valid profile is provided, even if this profile's refresh token has been | 115 // valid profile is provided, even if this profile's refresh token has been |
| 116 // revoked. (On Chrome OS we don't force to end the session in this case.) | 116 // revoked. (On Chrome OS we don't force to end the session in this case.) |
| 117 TEST_F(MultiUserUtilTest, ReturnValidAccountIdIfTokenRevoked) { | 117 TEST_F(MultiUserUtilTest, ReturnValidAccountIdIfTokenRevoked) { |
| 118 std::string id = AddUserToAccountTracker(kTestGaiaId, kTestAccountId); | 118 std::string id = AddUserToAccountTracker(kTestGaiaId, kTestAccountId); |
| 119 EXPECT_EQ(kTestAccountId, profile()->GetProfileUserName()); | 119 EXPECT_EQ(kTestAccountId, profile()->GetProfileUserName()); |
| 120 EXPECT_EQ(kTestAccountId, | 120 EXPECT_EQ(kTestAccountId, |
| 121 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail()); | 121 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail()); |
| 122 | 122 |
| 123 SimulateTokenRevoked(id); | 123 SimulateTokenRevoked(id); |
| 124 EXPECT_EQ(std::string(), profile()->GetProfileUserName()); | 124 EXPECT_EQ(std::string(), profile()->GetProfileUserName()); |
| 125 EXPECT_EQ(kTestAccountId, | 125 EXPECT_EQ(kTestAccountId, |
| 126 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail()); | 126 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace test | 129 } // namespace test |
| 130 } // namespace ash | 130 } // namespace ash |
| OLD | NEW |