Chromium Code Reviews| Index: components/arc/arc_util_unittest.cc |
| diff --git a/components/arc/arc_util_unittest.cc b/components/arc/arc_util_unittest.cc |
| index d083927672ee8e2d7d0da772da36dc4313909378..54ad8ef89b32dc62791b3487fa741bcbc17ae27e 100644 |
| --- a/components/arc/arc_util_unittest.cc |
| +++ b/components/arc/arc_util_unittest.cc |
| @@ -12,6 +12,9 @@ |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/test/scoped_feature_list.h" |
| +#include "components/signin/core/account_id/account_id.h" |
| +#include "components/user_manager/fake_user_manager.h" |
| +#include "components/user_manager/user.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/test/test_windows.h" |
| @@ -39,6 +42,44 @@ class ScopedArcFeature { |
| DISALLOW_COPY_AND_ASSIGN(ScopedArcFeature); |
| }; |
| +// Helper to enable user_manager::FakeUserManager while it is in scope. |
| +// TODO(xiyuan): Remove after ScopedUserManagerEnabler is moved to user_manager. |
| +class ScopedUserManager { |
| + public: |
| + explicit ScopedUserManager(user_manager::UserManager* user_manager) |
| + : user_manager_(user_manager) { |
| + DCHECK(!user_manager::UserManager::IsInitialized()); |
| + user_manager->Initialize(); |
| + } |
| + ~ScopedUserManager() { |
| + DCHECK_EQ(user_manager::UserManager::Get(), user_manager_); |
| + user_manager_->Shutdown(); |
| + user_manager_->Destroy(); |
| + } |
| + |
| + private: |
| + user_manager::UserManager* const user_manager_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedUserManager); |
| +}; |
| + |
| +// Fake user that can be created with a specified type. |
| +class FakeUser : public user_manager::User { |
| + public: |
| + explicit FakeUser(user_manager::UserType user_type) |
| + : User(AccountId::FromUserEmail("user@test.com")), |
| + user_type_(user_type) {} |
| + ~FakeUser() override = default; |
| + |
| + // user_manager::User: |
| + user_manager::UserType GetType() const override { return user_type_; } |
| + |
| + private: |
| + const user_manager::UserType user_type_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FakeUser); |
| +}; |
| + |
| using ArcUtilTest = testing::Test; |
| TEST_F(ArcUtilTest, IsArcAvailable_None) { |
| @@ -182,5 +223,50 @@ TEST_F(ArcUtilTest, IsArcAppWindow) { |
| EXPECT_FALSE(IsArcAppWindow(nullptr)); |
| } |
| +TEST_F(ArcUtilTest, IsArcAllowedForUser) { |
| + user_manager::FakeUserManager fake_user_manager; |
| + ScopedUserManager scoped_user_manager(&fake_user_manager); |
| + |
| + struct { |
| + user_manager::UserType user_type; |
| + bool expected_allowed; |
| + } const kTestCases[] = { |
| + {user_manager::USER_TYPE_REGULAR, true}, |
| + {user_manager::USER_TYPE_GUEST, false}, |
| + {user_manager::USER_TYPE_PUBLIC_ACCOUNT, false}, |
| + {user_manager::USER_TYPE_SUPERVISED, false}, |
| + {user_manager::USER_TYPE_KIOSK_APP, false}, |
| + {user_manager::USER_TYPE_CHILD, true}, |
| + {user_manager::USER_TYPE_ARC_KIOSK_APP, false}, |
| + {user_manager::USER_TYPE_ACTIVE_DIRECTORY, false}, |
| + }; |
| + for (const auto& test_case : kTestCases) { |
| + const FakeUser user(test_case.user_type); |
| + EXPECT_EQ(test_case.expected_allowed, IsArcAllowedForUser(&user)) |
| + << "User type=" << test_case.user_type; |
| + } |
| + |
| + // Active directory users are allowed when ARC is supported for active |
| + // directory managed devices. |
| + auto* command_line = base::CommandLine::ForCurrentProcess(); |
| + command_line->InitFromArgv( |
| + {"", "--arc-availability=officially-supported-with-active-directory"}); |
|
hidehiko
2017/05/18 18:52:50
This is flag is being deprecated (as you looks reb
xiyuan
2017/05/22 20:58:18
Removed after rebase.
|
| + const FakeUser active_directory_user( |
| + user_manager::USER_TYPE_ACTIVE_DIRECTORY); |
| + EXPECT_TRUE(IsArcAllowedForUser(&active_directory_user)); |
| + |
| + // An ephemeral user is a logged in user but unknown to UserManager when |
| + // ephemeral policy is set. |
| + fake_user_manager.SetEphemeralUsersEnabled(true); |
| + fake_user_manager.UserLoggedIn(AccountId::FromUserEmail("test@test.com"), |
| + "test@test.com-hash", false); |
| + const user_manager::User* ephemeral_user = fake_user_manager.GetActiveUser(); |
| + ASSERT_TRUE(ephemeral_user && fake_user_manager.IsUserCryptohomeDataEphemeral( |
|
hidehiko
2017/05/18 18:52:50
nit/style: How about splitting two ASSERT_TRUEs?
S
xiyuan
2017/05/22 20:58:18
Done.
|
| + ephemeral_user->GetAccountId())); |
| + |
| + // Ephemeral user is not allowed for ARC. |
| + EXPECT_FALSE(IsArcAllowedForUser(ephemeral_user)); |
| +} |
| + |
| } // namespace |
| } // namespace arc |