Commit ec953592 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Fix increased contrast toggling

This CL fixes the theme service to be able to toggle native increased
contrast support.
We were not considering IncreasedContrastThemeSupplier as a default
theme and were not removing it when native increased contrast was
disabled.

Bug: 1056335
Change-Id: I42b59e58912de8224b3d7d4e84fb355cd7851dc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078376
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Auto-Submit: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746686}
parent d5229050
......@@ -281,6 +281,8 @@ class BrowserThemePack : public CustomThemeSupplier {
void GenerateRawImageForAllSupportedScales(int prs_id);
// Data pack, if we have one.
// TODO(crbug.com/1057889): Destroy this on in the thread pool, make the rest
// of CustomThemeSupplier destruction synchronous.
std::unique_ptr<ui::DataPack> data_pack_;
// All structs written to disk need to be packed; no alignment tricks here,
......
......@@ -89,12 +89,20 @@ bool ThemeHelper::IsAutogeneratedTheme(
bool ThemeHelper::IsDefaultTheme(const CustomThemeSupplier* theme_supplier) {
if (!theme_supplier)
return true;
if (theme_supplier->get_theme_type() !=
CustomThemeSupplier::ThemeType::EXTENSION) {
return false;
using Type = CustomThemeSupplier::ThemeType;
switch (theme_supplier->get_theme_type()) {
case Type::INCREASED_CONTRAST:
return true;
case Type::EXTENSION: {
const std::string& id = theme_supplier->extension_id();
return id == kDefaultThemeID || id == kDefaultThemeGalleryID;
}
case Type::NATIVE_X11:
case Type::AUTOGENERATED:
return false;
}
const std::string& id = theme_supplier->extension_id();
return id == kDefaultThemeID || id == kDefaultThemeGalleryID;
}
// static
......
......@@ -154,6 +154,8 @@ class ThemeService : public content::NotificationObserver,
std::unique_ptr<ThemeService::ThemeReinstaller>
BuildReinstallerForCurrentTheme();
const ThemeHelper& theme_helper_for_testing() const { return theme_helper_; }
protected:
// Set a custom default theme instead of the normal default theme.
virtual void SetCustomDefaultTheme(
......
......@@ -585,4 +585,25 @@ TEST_F(ThemeServiceTest, TranslucentOmniboxBackgroundAndText) {
}
}
TEST_F(ThemeServiceTest, NativeIncreasedContrastChanged) {
theme_service_->UseDefaultTheme();
native_theme_.SetUsesHighContrastColors(true);
theme_service_->OnNativeThemeUpdated(&native_theme_);
EXPECT_TRUE(theme_service_->UsingDefaultTheme());
bool using_increased_contrast =
theme_service_->GetThemeSupplier() &&
theme_service_->GetThemeSupplier()->get_theme_type() ==
CustomThemeSupplier::ThemeType::INCREASED_CONTRAST;
bool expecting_increased_contrast =
theme_service_->theme_helper_for_testing()
.ShouldUseIncreasedContrastThemeSupplier(&native_theme_);
EXPECT_EQ(using_increased_contrast, expecting_increased_contrast);
native_theme_.SetUsesHighContrastColors(false);
theme_service_->OnNativeThemeUpdated(&native_theme_);
EXPECT_TRUE(theme_service_->UsingDefaultTheme());
EXPECT_EQ(theme_service_->GetThemeSupplier(), nullptr);
}
} // namespace theme_service_internal
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment