1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/profile_util.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_service_user_test_base.h"
#include "chrome/browser/profiles/profile.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "components/account_id/account_id.h"
#include "components/user_manager/user.h"
#endif // BUILDFLAG(IS_CHROMEOS)
using extensions::profile_util::ProfileCanUseNonComponentExtensions;
namespace extensions {
class ProfileUtilUnitTest : public ExtensionServiceUserTestBase {
public:
void SetUp() override {
ExtensionServiceUserTestBase::SetUp();
InitializeEmptyExtensionService();
}
};
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ProfileUtilUnitTest, ProfileCanUseNonComponentExtensions_RegularUser) {
ASSERT_NO_FATAL_FAILURE(LoginChromeOSUser(
GetFakeUserManager()->AddUser(account_id_), account_id_));
EXPECT_TRUE(ProfileCanUseNonComponentExtensions(profile()));
}
TEST_F(ProfileUtilUnitTest, ProfileCanUseNonComponentExtensions_ChildUser) {
const user_manager::User* user =
GetFakeUserManager()->AddChildUser(account_id_);
ASSERT_NO_FATAL_FAILURE(LoginChromeOSUser(user, account_id_));
EXPECT_TRUE(ProfileCanUseNonComponentExtensions(profile()));
}
TEST_F(ProfileUtilUnitTest, ProfileCannotUseNonComponentExtensions_GuestUser) {
ASSERT_NO_FATAL_FAILURE(MaybeSetUpTestUser(/*is_guest=*/true));
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(profile()));
}
// TODO(crbug.com/40878021): Test a signin, lockscreen, or lockscreen app
// profile. `FakeChromeUserManager` doesn't have one currently. Worst case could
// mock the `Profile` path to do this.
TEST_F(ProfileUtilUnitTest,
DISABLED_ProfileCannotUseNonComponentExtensions_NotAUserProfile) {}
TEST_F(ProfileUtilUnitTest,
ProfileCannotUseNonComponentExtensions_KioskAppUser) {
ASSERT_NO_FATAL_FAILURE(LoginChromeOSUser(
GetFakeUserManager()->AddKioskAppUser(account_id_), account_id_));
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(profile()));
}
TEST_F(ProfileUtilUnitTest,
ProfileCannotUseNonComponentExtensions_WebKioskAppUser) {
ASSERT_NO_FATAL_FAILURE(LoginChromeOSUser(
GetFakeUserManager()->AddWebKioskAppUser(account_id_), account_id_));
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(profile()));
}
TEST_F(ProfileUtilUnitTest, ProfileCannotUseNonComponentExtensions_PublicUser) {
ASSERT_NO_FATAL_FAILURE(LoginChromeOSUser(
GetFakeUserManager()->AddPublicAccountUser(account_id_), account_id_));
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(profile()));
}
#else
TEST_F(ProfileUtilUnitTest,
ProfileCanUseNonComponentExtensions_RegularProfile) {
// profile() defaults to a regular profile.
EXPECT_TRUE(ProfileCanUseNonComponentExtensions(profile()));
}
TEST_F(ProfileUtilUnitTest,
Browser_ProfileCannotUseNonComponentExtensions_NoProfile) {
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(/*profile=*/nullptr));
}
TEST_F(ProfileUtilUnitTest,
ProfileCannotUseNonComponentExtensions_GuestProfile) {
ASSERT_NO_FATAL_FAILURE(MaybeSetUpTestUser(/*is_guest=*/true));
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(profile()));
}
TEST_F(ProfileUtilUnitTest,
Browser_ProfileCannotUseNonComponentExtensions_IncognitoProfile) {
auto* incognito_test_profile =
profile()->GetPrimaryOTRProfile(/*create_if_needed=*/true);
ASSERT_TRUE(incognito_test_profile->IsIncognitoProfile());
EXPECT_FALSE(ProfileCanUseNonComponentExtensions(incognito_test_profile));
}
#endif // BUILDFLAG(IS_CHROMEOS)
} // namespace extensions
|