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

Side by Side Diff: chrome/browser/ui/ash/multi_user/multi_user_util_chromeos_unittest.cc

Issue 1984733002: [Reland] GetAccountIdFromProfile() should not return an empty account id if a valid profile is prov… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/test/ash_test_base.h"
6 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
7 #include "chrome/browser/chromeos/profiles/profile_helper.h"
8 #include "chrome/browser/signin/account_tracker_service_factory.h"
9 #include "chrome/browser/signin/fake_signin_manager_builder.h"
10 #include "chrome/browser/signin/signin_manager_factory.h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "components/signin/core/account_id/account_id.h"
14 #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"
17
18 namespace ash {
19 namespace test {
20
21 namespace {
22
23 const char kTestGaiaId[] = "gaia_id";
24 const char kTestAccountId[] = "test@test.com";
25
26 class MultiUserTestingProfile : public TestingProfile {
27 public:
28 explicit MultiUserTestingProfile(TestingProfile* profile)
29 : profile_(profile) {}
30 ~MultiUserTestingProfile() override {}
31
32 Profile* GetOriginalProfile() override { return this; }
33
34 std::string GetProfileUserName() const override {
35 const SigninManagerBase* signin_manager =
36 SigninManagerFactory::GetForProfileIfExists(profile_.get());
37 if (signin_manager)
38 return signin_manager->GetAuthenticatedAccountInfo().email;
39
40 return std::string();
41 }
42
43 TestingProfile* profile() { return profile_.get(); }
44
45 private:
46 std::unique_ptr<TestingProfile> profile_;
47
48 DISALLOW_COPY_AND_ASSIGN(MultiUserTestingProfile);
49 };
50
51 } // namespace
52
53 class MultiUserUtilTest : public AshTestBase {
54 public:
55 MultiUserUtilTest() {}
56 ~MultiUserUtilTest() override{};
57
58 void SetUp() override {
59 AshTestBase::SetUp();
60
61 fake_user_manager_ = new user_manager::FakeUserManager;
62 user_manager_enabler_.reset(
63 new chromeos::ScopedUserManagerEnabler(fake_user_manager_));
64
65 TestingProfile::Builder builder;
66 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
67 BuildFakeSigninManagerBase);
68 TestingProfile* profile = builder.Build().release();
69 profile_.reset(new MultiUserTestingProfile(profile));
70 }
71
72 void TearDown() override {
73 profile_.reset();
74 AshTestBase::TearDown();
75 }
76
77 // Add a user to account tracker service with given gaia_id and email.
78 std::string AddUserToAccountTracker(const std::string& gaia_id,
79 const std::string& email) {
80 AccountTrackerService* account_tracker_service =
81 AccountTrackerServiceFactory::GetForProfile(profile_->profile());
82 FakeSigninManagerBase* signin_manager = static_cast<FakeSigninManagerBase*>(
83 SigninManagerFactory::GetForProfile(profile_->profile()));
84 account_tracker_service->SeedAccountInfo(gaia_id, email);
85 const std::string id =
86 account_tracker_service->PickAccountIdForAccount(gaia_id, email);
87 signin_manager->SignIn(id);
88
89 fake_user_manager_->AddUser(multi_user_util::GetAccountIdFromEmail(id));
90 fake_user_manager_->UserLoggedIn(
91 multi_user_util::GetAccountIdFromEmail(id),
92 chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(id),
93 false /* browser_restart */);
94
95 return id;
96 }
97
98 void SimulateTokenRevoked(const std::string& account_id) {
99 AccountTrackerService* account_tracker_service =
100 AccountTrackerServiceFactory::GetForProfile(profile_->profile());
101 account_tracker_service->RemoveAccount(account_id);
102 }
103
104 MultiUserTestingProfile* profile() { return profile_.get(); }
105
106 private:
107 std::unique_ptr<MultiUserTestingProfile> profile_;
108 user_manager::FakeUserManager* fake_user_manager_; // Not owned.
109 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
110
111 DISALLOW_COPY_AND_ASSIGN(MultiUserUtilTest);
112 };
113
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
116 // revoked. (On Chrome OS we don't force to end the session in this case.)
117 TEST_F(MultiUserUtilTest, ReturnValidAccountIdIfTokenRevoked) {
118 std::string id = AddUserToAccountTracker(kTestGaiaId, kTestAccountId);
119 EXPECT_EQ(kTestAccountId, profile()->GetProfileUserName());
120 EXPECT_EQ(kTestAccountId,
121 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail());
122
123 SimulateTokenRevoked(id);
124 EXPECT_EQ(std::string(), profile()->GetProfileUserName());
125 EXPECT_EQ(kTestAccountId,
126 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail());
127 }
128
129 } // namespace test
130 } // namespace ash
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/multi_user/multi_user_util.cc ('k') | chrome/browser/ui/browser_finder_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698