#include "extensions/browser/extension_registrar.h"
#include <memory>
#include <optional>
#include "base/location.h"
#include "base/task/sequenced_task_runner.h"
#include "build/chromeos_buildflags.h"
#include "content/public/browser/browser_context.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/test_extensions_browser_client.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_switches.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ash/crosapi/browser_util.h"
#include "chrome/common/pref_names.h"
#include "chromeos/ash/components/standalone_browser/feature_refs.h"
#include "chromeos/ash/components/standalone_browser/lacros_availability.h"
#include "components/account_id/account_id.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/scoped_user_manager.h"
#endif
namespace extensions {
namespace {
Return;
_;
LoadErrorBehavior;
class TestExtensionSystem : public MockExtensionSystem { … };
class TestExtensionRegistrarDelegate : public ExtensionRegistrar::Delegate { … };
}
class ExtensionRegistrarTest : public ExtensionsTest { … };
TEST_F(ExtensionRegistrarTest, Basic) { … }
TEST_F(ExtensionRegistrarTest, AlreadyEnabled) { … }
TEST_F(ExtensionRegistrarTest, Disable) { … }
TEST_F(ExtensionRegistrarTest, DisableAndEnable) { … }
TEST_F(ExtensionRegistrarTest, AddDisabled) { … }
TEST_F(ExtensionRegistrarTest, AddForceEnabled) { … }
TEST_F(ExtensionRegistrarTest, AddForceDisabled) { … }
TEST_F(ExtensionRegistrarTest, AddBlocklisted) { … }
TEST_F(ExtensionRegistrarTest, AddBlocked) { … }
TEST_F(ExtensionRegistrarTest, TerminateExtension) { … }
TEST_F(ExtensionRegistrarTest, DisableTerminatedExtension) { … }
TEST_F(ExtensionRegistrarTest, EnableTerminatedExtension) { … }
TEST_F(ExtensionRegistrarTest, ReloadExtension) { … }
TEST_F(ExtensionRegistrarTest, RemoveReloadedExtension) { … }
TEST_F(ExtensionRegistrarTest, ReloadTerminatedExtension) { … }
TEST_F(ExtensionRegistrarTest, DisableNotAshKeeplistedExtension) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ExtensionRegistrarTest,
DisableNotAshKeeplistedForceInstalledExtensionIfAshDisabled) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(ash::standalone_browser::GetFeatureRefs(), {});
base::test::ScopedCommandLine scoped_command_line;
scoped_command_line.GetProcessCommandLine()->AppendSwitch(
ash::switches::kEnableLacrosForTesting);
auto fake_user_manager = std::make_unique<user_manager::FakeUserManager>();
auto* primary_user =
fake_user_manager->AddUser(AccountId::FromUserEmail("test@test"));
fake_user_manager->UserLoggedIn(primary_user->GetAccountId(),
primary_user->username_hash(),
false,
false);
auto scoped_user_manager = std::make_unique<user_manager::ScopedUserManager>(
std::move(fake_user_manager));
static_cast<TestingPrefServiceSimple*>(pref_service())
->registry()
->RegisterIntegerPref(
prefs::kLacrosLaunchSwitch,
static_cast<int>(
ash::standalone_browser::LacrosAvailability::kLacrosOnly));
EXPECT_FALSE(crosapi::browser_util::IsAshWebBrowserEnabled());
ON_CALL(*delegate(), CanDisableExtension(extension().get()))
.WillByDefault(Return(false));
AddEnabledExtension();
TryDisablingNotAshKeeplistedExtension( true);
}
TEST_F(ExtensionRegistrarTest,
NotDisableNotAshKeeplistedForceInstalledExtensionIfAshEnabled) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({}, ash::standalone_browser::GetFeatureRefs());
static_cast<TestingPrefServiceSimple*>(pref_service())
->registry()
->RegisterIntegerPref(
prefs::kLacrosLaunchSwitch,
static_cast<int>(
ash::standalone_browser::LacrosAvailability::kLacrosOnly));
EXPECT_TRUE(crosapi::browser_util::IsAshWebBrowserEnabled());
ON_CALL(*delegate(), CanDisableExtension(extension().get()))
.WillByDefault(Return(false));
AddEnabledExtension();
TryDisablingNotAshKeeplistedExtension( false);
}
#endif
}