chromium/chrome/browser/themes/theme_service_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 {};

// A class that ensures any installed extension is uninstalled before it goes
// out of scope.  This ensures the temporary directory used to load the
// extension is unlocked and can be deleted.
class ThemeScoper {};

#if BUILDFLAG(IS_LINUX)
class LinuxUiGetterImpl : public ui::LinuxUiGetter {};
#endif

}  // namespace

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();

// Installs then uninstalls a theme and makes sure that the ThemeService
// reverts to the default theme after the uninstall.
TEST_F(ThemeServiceTest, ThemeInstallUninstall) {}

// Test that a theme extension is disabled when not in use. A theme may be
// installed but not in use if it there is an infobar to revert to the previous
// theme.
TEST_F(ThemeServiceTest, DisableUnusedTheme) {}

// Test the ThemeService's behavior when a theme is upgraded.
TEST_F(ThemeServiceTest, ThemeUpgrade) {}

TEST_F(ThemeServiceTest, NTPLogoAlternate) {}

// crbug.com/468280
TEST_F(ThemeServiceTest, UninstallThemeWhenNoReinstallers) {}

TEST_F(ThemeServiceTest, BuildFromColorTest) {}

TEST_F(ThemeServiceTest, BuildFromColor_DisableExtensionTest) {}

TEST_F(ThemeServiceTest, UseDefaultTheme_DisableExtensionTest) {}

// Test that setting theme to default resets the NTP theme as well.
TEST_F(ThemeServiceTest, UseDefaultTheme_DisableNtpThemeTest) {}

TEST_P(ColorProviderTest, OmniboxContrast) {}

// Sets and unsets themes using the BrowserThemeColor policy.
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)
// Verify that if uses device theme is unset and the user has a chosen color,
// they retain their chosen color.
TEST_F(ThemeServiceTest, UseDeviceTheme_DisabledByUserColor) {
  theme_service_->SetUserColor(SK_ColorGREEN);
  EXPECT_FALSE(theme_service_->UsingDeviceTheme());
}

// Verify that if the user has a theme loaded via extension and uses device
// theme is unset, they retain the extension.
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());
}

// Verify that if uses device theme has been set by the user, it is still
// true even if the user has a color from a different device.
TEST_F(ThemeServiceTest, UseDeviceTheme_ExplicitlyTrue) {
  theme_service_->UseDeviceTheme(true);
  theme_service_->SetUserColor(SK_ColorGREEN);
  EXPECT_TRUE(theme_service_->UsingDeviceTheme());
}
#endif  // IS_CHROMEOS

TEST_F(ThemeServiceTest, SetUseDeviceTheme) {}

TEST_F(ThemeServiceTest, SetBrowserColorScheme) {}

TEST_F(ThemeServiceTest, ReinstallerRecoversExtension) {}

TEST_F(ThemeServiceTest, ReinstallerRecoversAutogeneratedColor) {}

TEST_F(ThemeServiceTest, ReinstallerRecoversUserColor) {}

TEST_F(ThemeServiceTest, ReinstallerRecoversDefaultTheme) {}

}  // namespace theme_service_internal