blob: eb3ca8bfcaadbeeabeb08c4a133d28c9b0932224 [file] [log] [blame]
peletskyic8452f22016-02-23 15:26:121// 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
10namespace user_manager {
11
12namespace {
13
14const char kEmail[] = "[email protected]";
15const char kGaiaId[] = "fake_gaia_id";
16
17} // namespace
18
19TEST(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
peletskyi53c440d2016-10-25 15:09:5543 ScopedUser arc_kiosk_user(User::CreateArcKioskAppUser(account_id));
44 EXPECT_TRUE(arc_kiosk_user.IsAffiliated());
peletskyic8452f22016-02-23 15:26:1245}
46
atwilsond5a7eabf2017-03-09 13:18:3947TEST(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
peletskyic8452f22016-02-23 15:26:1255} // namespace user_manager