#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "ui/native_theme/native_theme.h"
class PageColorsBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PageColorsBrowserTest, PageColorsPrefChange) { … }
#if BUILDFLAG(IS_CHROMEOS)
#define MAYBE_PageColorsCalculationWithIncreasedContrastToggle …
#else
#define MAYBE_PageColorsCalculationWithIncreasedContrastToggle …
#endif
IN_PROC_BROWSER_TEST_F(PageColorsBrowserTest,
MAYBE_PageColorsCalculationWithIncreasedContrastToggle) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(PageColorsBrowserTest, PageColorsWithHighContrast) {
ui::NativeTheme::PageColors page_colors_pref =
static_cast<ui::NativeTheme::PageColors>(
browser()->profile()->GetPrefs()->GetInteger(prefs::kPageColors));
auto* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
auto* native_theme_web = ui::NativeTheme::GetInstanceForWeb();
ui::NativeTheme::PageColors page_colors_state = native_theme->GetPageColors();
bool is_default_page_colors_on_high_contrast =
browser()->profile()->GetPrefs()->GetBoolean(
prefs::kIsDefaultPageColorsOnHighContrast);
EXPECT_EQ(page_colors_state, page_colors_pref);
EXPECT_TRUE(is_default_page_colors_on_high_contrast);
native_theme->set_forced_colors(true);
native_theme->SetPreferredContrast(ui::NativeTheme::PreferredContrast::kMore);
page_colors_pref = static_cast<ui::NativeTheme::PageColors>(
browser()->profile()->GetPrefs()->GetInteger(prefs::kPageColors));
page_colors_state = native_theme->GetPageColors();
is_default_page_colors_on_high_contrast =
browser()->profile()->GetPrefs()->GetBoolean(
prefs::kIsDefaultPageColorsOnHighContrast);
EXPECT_TRUE(is_default_page_colors_on_high_contrast);
EXPECT_EQ(page_colors_pref, ui::NativeTheme::PageColors::kHighContrast);
EXPECT_EQ(page_colors_state, page_colors_pref);
native_theme->set_forced_colors(false);
native_theme->SetPreferredContrast(
ui::NativeTheme::PreferredContrast::kNoPreference);
page_colors_pref = static_cast<ui::NativeTheme::PageColors>(
browser()->profile()->GetPrefs()->GetInteger(prefs::kPageColors));
page_colors_state = native_theme->GetPageColors();
is_default_page_colors_on_high_contrast =
browser()->profile()->GetPrefs()->GetBoolean(
prefs::kIsDefaultPageColorsOnHighContrast);
EXPECT_TRUE(is_default_page_colors_on_high_contrast);
EXPECT_EQ(page_colors_pref, ui::NativeTheme::PageColors::kOff);
EXPECT_EQ(page_colors_state, page_colors_pref);
native_theme->set_forced_colors(true);
native_theme->SetPreferredContrast(ui::NativeTheme::PreferredContrast::kMore);
browser()->profile()->GetPrefs()->SetInteger(
prefs::kPageColors, ui::NativeTheme::PageColors::kOff);
is_default_page_colors_on_high_contrast =
browser()->profile()->GetPrefs()->GetBoolean(
prefs::kIsDefaultPageColorsOnHighContrast);
EXPECT_FALSE(is_default_page_colors_on_high_contrast);
EXPECT_FALSE(native_theme_web->InForcedColorsMode());
native_theme->set_forced_colors(false);
native_theme->SetPreferredContrast(
ui::NativeTheme::PreferredContrast::kNoPreference);
native_theme->set_forced_colors(true);
native_theme->SetPreferredContrast(ui::NativeTheme::PreferredContrast::kMore);
page_colors_pref = static_cast<ui::NativeTheme::PageColors>(
browser()->profile()->GetPrefs()->GetInteger(prefs::kPageColors));
page_colors_state = native_theme->GetPageColors();
EXPECT_FALSE(native_theme_web->InForcedColorsMode());
EXPECT_EQ(page_colors_pref, ui::NativeTheme::PageColors::kOff);
EXPECT_EQ(page_colors_state, page_colors_pref);
}
#endif
IN_PROC_BROWSER_TEST_F(PageColorsBrowserTest, PageColorsWithNativeTheme) { … }