Commit b45f2c82 authored by Wei Li's avatar Wei Li Committed by Commit Bot

Remove dependency on profile based theme provider

In browser tests, remove using profile based theme provider. Also, the
previous ThemeIntegration test didn't seem working as intended, fix that
as well.

BUG=1056758

Change-Id: I8c9abb7289a739d91ed836d012a20ec149c8124e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2044433
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746050}
parent 383448cd
...@@ -199,45 +199,40 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupContentsViewTest, ThemeIntegration) { ...@@ -199,45 +199,40 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupContentsViewTest, ThemeIntegration) {
} }
ASSERT_TRUE(theme_service->UsingDefaultTheme()); ASSERT_TRUE(theme_service->UsingDefaultTheme());
Browser* browser_under_test = browser(); Browser* regular_browser = browser();
BrowserView::GetBrowserViewForBrowser(browser()) BrowserView* browser_view =
->GetNativeTheme() BrowserView::GetBrowserViewForBrowser(regular_browser);
->set_use_dark_colors(false); browser_view->GetNativeTheme()->set_use_dark_colors(true);
const ui::ThemeProvider* light_theme_provider = const ui::ThemeProvider* theme_provider = browser_view->GetThemeProvider();
&ThemeService::GetThemeProviderForProfile(browser_under_test->profile()); const SkColor selection_color_dark =
const ui::ThemeProvider* dark_theme_provider = GetOmniboxColor(theme_provider, OmniboxPart::RESULTS_BACKGROUND,
&ThemeService::GetThemeProviderForProfile( OmniboxPartState::SELECTED);
browser_under_test->profile()->GetOffTheRecordProfile());
browser_view->GetNativeTheme()->set_use_dark_colors(false);
const SkColor selection_color_light =
GetOmniboxColor(theme_provider, OmniboxPart::RESULTS_BACKGROUND,
OmniboxPartState::SELECTED);
// Unthemed, non-incognito always has a white background. Exceptions: Inverted // Unthemed, non-incognito always has a white background. Exceptions: Inverted
// color themes on Windows and GTK (not tested here). // color themes on Windows and GTK (not tested here).
EXPECT_EQ(SK_ColorWHITE, GetOmniboxColor(light_theme_provider, EXPECT_EQ(SK_ColorWHITE,
OmniboxPart::RESULTS_BACKGROUND)); GetOmniboxColor(theme_provider, OmniboxPart::RESULTS_BACKGROUND));
// Helper to get the background selected color for |browser_under_test| using
// omnibox_theme.
auto get_selection_color = [](const ui::ThemeProvider* theme_provider) {
return GetOmniboxColor(theme_provider, OmniboxPart::RESULTS_BACKGROUND,
OmniboxPartState::SELECTED);
};
const SkColor selection_color_light = auto get_selection_color = [](const Browser* browser) {
GetOmniboxColor(light_theme_provider, OmniboxPart::RESULTS_BACKGROUND, return GetOmniboxColor(
OmniboxPartState::SELECTED); BrowserView::GetBrowserViewForBrowser(browser)->GetThemeProvider(),
const SkColor selection_color_dark = OmniboxPart::RESULTS_BACKGROUND, OmniboxPartState::SELECTED);
GetOmniboxColor(dark_theme_provider, OmniboxPart::RESULTS_BACKGROUND, };
OmniboxPartState::SELECTED);
// Tests below are mainly interested just whether things change, so ensure // Tests below are mainly interested just whether things change, so ensure
// that can be detected. // that can be detected.
EXPECT_NE(selection_color_dark, selection_color_light); EXPECT_NE(selection_color_dark, selection_color_light);
EXPECT_EQ(selection_color_light, get_selection_color(light_theme_provider)); EXPECT_EQ(selection_color_light, get_selection_color(regular_browser));
// Check unthemed incognito windows. // Check unthemed incognito windows.
Browser* incognito_browser = CreateIncognitoBrowser(); Browser* incognito_browser = CreateIncognitoBrowser();
browser_under_test = incognito_browser; EXPECT_EQ(selection_color_dark, get_selection_color(incognito_browser));
EXPECT_EQ(selection_color_dark, get_selection_color(dark_theme_provider));
// Install a theme (in both browsers, since it's the same profile). // Install a theme (in both browsers, since it's the same profile).
extensions::ChromeTestExtensionLoader loader(browser()->profile()); extensions::ChromeTestExtensionLoader loader(browser()->profile());
...@@ -250,11 +245,10 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupContentsViewTest, ThemeIntegration) { ...@@ -250,11 +245,10 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupContentsViewTest, ThemeIntegration) {
} }
// Check the incognito browser first. Everything should now be light. // Check the incognito browser first. Everything should now be light.
EXPECT_EQ(selection_color_light, get_selection_color(light_theme_provider)); EXPECT_EQ(selection_color_light, get_selection_color(incognito_browser));
// Same in the non-incognito browser. // Same in the non-incognito browser.
browser_under_test = browser(); EXPECT_EQ(selection_color_light, get_selection_color(regular_browser));
EXPECT_EQ(selection_color_light, get_selection_color(light_theme_provider));
// Switch to the default theme without installing a custom theme. E.g. this is // Switch to the default theme without installing a custom theme. E.g. this is
// what gets used on KDE or when switching to the "classic" theme in settings. // what gets used on KDE or when switching to the "classic" theme in settings.
...@@ -262,11 +256,10 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupContentsViewTest, ThemeIntegration) { ...@@ -262,11 +256,10 @@ IN_PROC_BROWSER_TEST_F(OmniboxPopupContentsViewTest, ThemeIntegration) {
ThemeChangeWaiter wait(theme_service); ThemeChangeWaiter wait(theme_service);
theme_service->UseDefaultTheme(); theme_service->UseDefaultTheme();
} }
EXPECT_EQ(selection_color_light, get_selection_color(light_theme_provider)); EXPECT_EQ(selection_color_light, get_selection_color(regular_browser));
// Check incognito again. It should now use a dark theme, even on Linux. // Check incognito again. It should now use a dark theme, even on Linux.
browser_under_test = incognito_browser; EXPECT_EQ(selection_color_dark, get_selection_color(incognito_browser));
EXPECT_EQ(selection_color_dark, get_selection_color(dark_theme_provider));
} }
// TODO(tapted): https://crbug.com/905508 Fix and enable on Mac. // TODO(tapted): https://crbug.com/905508 Fix and enable on Mac.
......
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