#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/themes/theme_service.h"
#include <cmath>
#include "base/containers/fixed_flat_map.h"
#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/themes/custom_theme_supplier.h"
#include "chrome/browser/themes/test/theme_service_changed_waiter.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/themes/theme_service_test_utils.h"
#include "chrome/browser/themes/theme_syncable_service.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/color/chrome_color_mixers.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/color/color_mixers.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/mojom/themes.mojom.h"
#include "ui/base/ui_base_features.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_provider_manager.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/native_theme/test_native_theme.h"
#if BUILDFLAG(IS_LINUX)
#include "ui/linux/linux_ui.h"
#include "ui/linux/linux_ui_factory.h"
#include "ui/linux/linux_ui_getter.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace {
enum class ContrastMode { … };
enum class SystemTheme { … };
class ThemeScoper { … };
#if BUILDFLAG(IS_LINUX)
class LinuxUiGetterImpl : public ui::LinuxUiGetter { … };
#endif
}
namespace theme_service_internal {
class ThemeServiceTest : public extensions::ExtensionServiceTestBase { … };
class ColorProviderTest
: public ThemeServiceTest,
public testing::WithParamInterface<
std::tuple<ui::NativeTheme::ColorScheme, ContrastMode, SystemTheme>> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(ThemeServiceTest, ThemeInstallUninstall) { … }
TEST_F(ThemeServiceTest, DisableUnusedTheme) { … }
TEST_F(ThemeServiceTest, ThemeUpgrade) { … }
TEST_F(ThemeServiceTest, NTPLogoAlternate) { … }
TEST_F(ThemeServiceTest, UninstallThemeWhenNoReinstallers) { … }
TEST_F(ThemeServiceTest, BuildFromColorTest) { … }
TEST_F(ThemeServiceTest, BuildFromColor_DisableExtensionTest) { … }
TEST_F(ThemeServiceTest, UseDefaultTheme_DisableExtensionTest) { … }
TEST_F(ThemeServiceTest, UseDefaultTheme_DisableNtpThemeTest) { … }
TEST_P(ColorProviderTest, OmniboxContrast) { … }
TEST_F(ThemeServiceTest, PolicyThemeColorSet) { … }
TEST_F(ThemeServiceTest, UserColor) { … }
TEST_F(ThemeServiceTest, ThemeResetClearsUserColor) { … }
TEST_F(ThemeServiceTest, IsBaseline) { … }
TEST_F(ThemeServiceTest, IsGrayscale) { … }
TEST_F(ThemeServiceTest, ThemeResetClearsIsGrayscale) { … }
TEST_F(ThemeServiceTest, SetUserColorAndBrowserColorVariant) { … }
TEST_F(ThemeServiceTest, ThemeResetClearsBrowserColorVariant) { … }
TEST_F(ThemeServiceTest, UseDeviceTheme_DefaultValue) { … }
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ThemeServiceTest, UseDeviceTheme_DisabledByUserColor) {
theme_service_->SetUserColor(SK_ColorGREEN);
EXPECT_FALSE(theme_service_->UsingDeviceTheme());
}
TEST_F(ThemeServiceTest, UseDeviceTheme_DisabledByExtension) {
ThemeScoper scoper = LoadUnpackedTheme();
EXPECT_FALSE(theme_service_->UsingDeviceTheme());
}
TEST_F(ThemeServiceTest, UseDeviceTheme_DisabledByAutogeneratedTheme) {
theme_service_->BuildAutogeneratedThemeFromColor(
SkColorSetRGB(100, 100, 100));
ASSERT_TRUE(theme_service_->UsingAutogeneratedTheme());
EXPECT_FALSE(theme_service_->UsingDeviceTheme());
}
TEST_F(ThemeServiceTest, UseDeviceTheme_ExplicitlyTrue) {
theme_service_->UseDeviceTheme(true);
theme_service_->SetUserColor(SK_ColorGREEN);
EXPECT_TRUE(theme_service_->UsingDeviceTheme());
}
#endif
TEST_F(ThemeServiceTest, SetUseDeviceTheme) { … }
TEST_F(ThemeServiceTest, SetBrowserColorScheme) { … }
TEST_F(ThemeServiceTest, ReinstallerRecoversExtension) { … }
TEST_F(ThemeServiceTest, ReinstallerRecoversAutogeneratedColor) { … }
TEST_F(ThemeServiceTest, ReinstallerRecoversUserColor) { … }
TEST_F(ThemeServiceTest, ReinstallerRecoversDefaultTheme) { … }
}