peletskyi | c8452f2 | 2016-02-23 15:26:12 | [diff] [blame] | 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 "components/user_manager/user.h" |
| 6 | |
| 7 | #include "components/signin/core/account_id/account_id.h" |
| 8 | #include "testing/gtest/include/gtest/gtest.h" |
| 9 | |
| 10 | namespace user_manager { |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | const char kEmail[] = "[email protected]"; |
| 15 | const char kGaiaId[] = "fake_gaia_id"; |
| 16 | |
| 17 | } // namespace |
| 18 | |
| 19 | TEST(UserTest, DeviceLocalAccountAffiliation) { |
| 20 | // This implementation of RAII for User* is to prevent memory leak. |
| 21 | // Smart pointers are not friends of User and can't call protected destructor. |
| 22 | class ScopedUser { |
| 23 | public: |
| 24 | ScopedUser(const User* const user) : user_(user) {} |
| 25 | ~ScopedUser() { delete user_; } |
| 26 | |
| 27 | bool IsAffiliated() const { return user_ && user_->IsAffiliated(); } |
| 28 | |
| 29 | private: |
| 30 | const User* const user_; |
| 31 | |
| 32 | DISALLOW_COPY_AND_ASSIGN(ScopedUser); |
| 33 | }; |
| 34 | |
| 35 | const AccountId account_id = AccountId::FromUserEmailGaiaId(kEmail, kGaiaId); |
| 36 | |
| 37 | ScopedUser kiosk_user(User::CreateKioskAppUser(account_id)); |
| 38 | EXPECT_TRUE(kiosk_user.IsAffiliated()); |
| 39 | |
| 40 | ScopedUser public_session_user(User::CreatePublicAccountUser(account_id)); |
| 41 | EXPECT_TRUE(public_session_user.IsAffiliated()); |
| 42 | |
peletskyi | 53c440d | 2016-10-25 15:09:55 | [diff] [blame] | 43 | ScopedUser arc_kiosk_user(User::CreateArcKioskAppUser(account_id)); |
| 44 | EXPECT_TRUE(arc_kiosk_user.IsAffiliated()); |
peletskyi | c8452f2 | 2016-02-23 15:26:12 | [diff] [blame] | 45 | } |
| 46 | |
atwilson | d5a7eabf | 2017-03-09 13:18:39 | [diff] [blame] | 47 | TEST(UserTest, UserSessionInitialized) { |
| 48 | const AccountId account_id = AccountId::FromUserEmailGaiaId(kEmail, kGaiaId); |
| 49 | std::unique_ptr<User> user(User::CreateRegularUser(account_id)); |
| 50 | EXPECT_FALSE(user->profile_ever_initialized()); |
| 51 | user->set_profile_ever_initialized(true); |
| 52 | EXPECT_TRUE(user->profile_ever_initialized()); |
| 53 | } |
| 54 | |
peletskyi | c8452f2 | 2016-02-23 15:26:12 | [diff] [blame] | 55 | } // namespace user_manager |