Commit 5c495213 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Add NativeTheme::GetSystemColor Redirection Equivalence Test

This test helps ensure that color values do not change when the
Color Provider feature is enabled.

BUG=1057754
TBR=sky@chromium.org
ui/base Feature Addition for the Color Provider.

Change-Id: Ifd115ee7d4b6f73e337e5e74269d521960de7250
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086191
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746630}
parent 7ae6c0d5
...@@ -16,6 +16,10 @@ const base::Feature kCalculateNativeWinOcclusion{ ...@@ -16,6 +16,10 @@ const base::Feature kCalculateNativeWinOcclusion{
"CalculateNativeWinOcclusion", base::FEATURE_DISABLED_BY_DEFAULT}; "CalculateNativeWinOcclusion", base::FEATURE_DISABLED_BY_DEFAULT};
#endif // OW_WIN #endif // OW_WIN
// Whether or not to delegate color queries to the color provider.
const base::Feature kColorProviderRedirection = {
"ColorProviderRedirection", base::FEATURE_DISABLED_BY_DEFAULT};
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Integrate input method specific settings to Chrome OS settings page. // Integrate input method specific settings to Chrome OS settings page.
// https://crbug.com/895886. // https://crbug.com/895886.
......
...@@ -14,6 +14,8 @@ namespace features { ...@@ -14,6 +14,8 @@ namespace features {
// Keep sorted! // Keep sorted!
COMPONENT_EXPORT(UI_BASE_FEATURES)
extern const base::Feature kColorProviderRedirection;
COMPONENT_EXPORT(UI_BASE_FEATURES) COMPONENT_EXPORT(UI_BASE_FEATURES)
extern const base::Feature kCompositorThreadedScrollbarScrolling; extern const base::Feature kCompositorThreadedScrollbarScrolling;
COMPONENT_EXPORT(UI_BASE_FEATURES) COMPONENT_EXPORT(UI_BASE_FEATURES)
......
...@@ -22,6 +22,7 @@ jumbo_component("native_theme") { ...@@ -22,6 +22,7 @@ jumbo_component("native_theme") {
"native_theme.h", "native_theme.h",
"native_theme_base.cc", "native_theme_base.cc",
"native_theme_base.h", "native_theme_base.h",
"native_theme_color_id.h",
"native_theme_export.h", "native_theme_export.h",
"native_theme_features.cc", "native_theme_features.cc",
"native_theme_features.h", "native_theme_features.h",
...@@ -123,7 +124,7 @@ jumbo_source_set("test_support") { ...@@ -123,7 +124,7 @@ jumbo_source_set("test_support") {
} }
test("native_theme_unittests") { test("native_theme_unittests") {
sources = [] sources = [ "native_theme_unittest.cc" ]
if (use_aura) { if (use_aura) {
sources += [ "native_theme_aura_unittest.cc" ] sources += [ "native_theme_aura_unittest.cc" ]
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/native_theme/caption_style.h" #include "ui/native_theme/caption_style.h"
#include "ui/native_theme/native_theme_color_id.h"
#include "ui/native_theme/native_theme_export.h" #include "ui/native_theme/native_theme_export.h"
#include "ui/native_theme/native_theme_observer.h" #include "ui/native_theme/native_theme_observer.h"
...@@ -320,121 +321,9 @@ class NATIVE_THEME_EXPORT NativeTheme { ...@@ -320,121 +321,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
// Colors for GetSystemColor(). // Colors for GetSystemColor().
enum ColorId { enum ColorId {
// Windows #define OP(enum_name) enum_name
kColorId_WindowBackground, NATIVE_THEME_COLOR_IDS,
// Dialogs #undef OP
kColorId_DialogBackground,
kColorId_DialogForeground,
kColorId_BubbleBackground,
kColorId_BubbleFooterBackground,
// FocusableBorder
kColorId_FocusedBorderColor,
kColorId_UnfocusedBorderColor,
// Button
kColorId_ButtonBorderColor,
kColorId_ButtonEnabledColor,
kColorId_ButtonDisabledColor,
kColorId_ButtonHoverColor,
kColorId_ButtonInkDropFillColor,
kColorId_ButtonInkDropShadowColor,
kColorId_ButtonPressedShade,
kColorId_ButtonUncheckedColor,
kColorId_ProminentButtonColor,
kColorId_ProminentButtonDisabledColor,
kColorId_ProminentButtonFocusedColor,
kColorId_ProminentButtonHoverColor,
kColorId_ProminentButtonInkDropShadowColor,
kColorId_ProminentButtonInkDropFillColor,
kColorId_TextOnProminentButtonColor,
// ToggleButton
kColorId_ToggleButtonShadowColor,
kColorId_ToggleButtonTrackColorOff,
kColorId_ToggleButtonTrackColorOn,
// MenuItem
kColorId_EnabledMenuItemForegroundColor,
kColorId_DisabledMenuItemForegroundColor,
kColorId_SelectedMenuItemForegroundColor,
kColorId_FocusedMenuItemBackgroundColor,
kColorId_MenuDropIndicator,
kColorId_MenuItemMinorTextColor,
kColorId_MenuSeparatorColor,
kColorId_MenuBackgroundColor,
kColorId_MenuBorderColor,
kColorId_HighlightedMenuItemBackgroundColor,
kColorId_HighlightedMenuItemForegroundColor,
kColorId_MenuItemAlertBackgroundColor,
// Dropdown
kColorId_DropdownBackgroundColor,
kColorId_DropdownForegroundColor,
kColorId_DropdownSelectedBackgroundColor,
kColorId_DropdownSelectedForegroundColor,
// Label
kColorId_LabelEnabledColor,
kColorId_LabelDisabledColor,
kColorId_LabelSecondaryColor,
kColorId_LabelTextSelectionColor,
kColorId_LabelTextSelectionBackgroundFocused,
// Link
kColorId_LinkDisabled,
kColorId_LinkEnabled,
kColorId_LinkPressed,
kColorId_OverlayScrollbarThumbBackground,
kColorId_OverlayScrollbarThumbForeground,
// Slider
kColorId_SliderThumbDefault,
kColorId_SliderTroughDefault,
kColorId_SliderThumbMinimal,
kColorId_SliderTroughMinimal,
// Separator
kColorId_SeparatorColor,
// TabbedPane
kColorId_TabTitleColorActive,
kColorId_TabTitleColorInactive,
kColorId_TabBottomBorder,
kColorId_TabHighlightBackground,
kColorId_TabHighlightFocusedBackground,
// Textfield
kColorId_TextfieldDefaultColor,
kColorId_TextfieldDefaultBackground,
kColorId_TextfieldReadOnlyColor,
kColorId_TextfieldReadOnlyBackground,
kColorId_TextfieldSelectionColor,
kColorId_TextfieldSelectionBackgroundFocused,
// Tooltip
kColorId_TooltipBackground,
kColorId_TooltipIcon,
kColorId_TooltipIconHovered,
kColorId_TooltipText,
// Tree
kColorId_TreeBackground,
kColorId_TreeText,
kColorId_TreeSelectedText,
kColorId_TreeSelectedTextUnfocused,
kColorId_TreeSelectionBackgroundFocused,
kColorId_TreeSelectionBackgroundUnfocused,
// Table
kColorId_TableBackground,
kColorId_TableText,
kColorId_TableSelectedText,
kColorId_TableSelectedTextUnfocused,
kColorId_TableSelectionBackgroundFocused,
kColorId_TableSelectionBackgroundUnfocused,
kColorId_TableGroupingIndicatorColor,
// Table Header
kColorId_TableHeaderText,
kColorId_TableHeaderBackground,
kColorId_TableHeaderSeparator,
// Colors for the material spinner (aka throbber).
kColorId_ThrobberSpinningColor,
kColorId_ThrobberWaitingColor,
kColorId_ThrobberLightColor,
// Colors for icons that alert, e.g. upgrade reminders.
kColorId_AlertSeverityLow,
kColorId_AlertSeverityMedium,
kColorId_AlertSeverityHigh,
// Colors for icons in secondary UI (content settings, help button, etc).
kColorId_DefaultIconColor,
// TODO(benrg): move other hardcoded colors here.
kColorId_NumColors, kColorId_NumColors,
}; };
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_NATIVE_THEME_NATIVE_THEME_COLOR_ID_H_
#define UI_NATIVE_THEME_NATIVE_THEME_COLOR_ID_H_
// Clang format mangles sectioned lists like the below badly.
// clang-format off
#define NATIVE_THEME_COLOR_IDS \
/* Windows */ \
OP(kColorId_WindowBackground), \
/* Dialogs */ \
OP(kColorId_DialogBackground), \
OP(kColorId_DialogForeground), \
OP(kColorId_BubbleBackground), \
OP(kColorId_BubbleFooterBackground), \
/* FocusableBorder */ \
OP(kColorId_FocusedBorderColor), \
OP(kColorId_UnfocusedBorderColor), \
/* Button */ \
OP(kColorId_ButtonBorderColor), \
OP(kColorId_ButtonEnabledColor), \
OP(kColorId_ButtonDisabledColor), \
OP(kColorId_ButtonHoverColor), \
OP(kColorId_ButtonInkDropFillColor), \
OP(kColorId_ButtonInkDropShadowColor), \
OP(kColorId_ButtonPressedShade), \
OP(kColorId_ButtonUncheckedColor), \
OP(kColorId_ProminentButtonColor), \
OP(kColorId_ProminentButtonDisabledColor), \
OP(kColorId_ProminentButtonFocusedColor), \
OP(kColorId_ProminentButtonHoverColor), \
OP(kColorId_ProminentButtonInkDropShadowColor), \
OP(kColorId_ProminentButtonInkDropFillColor), \
OP(kColorId_TextOnProminentButtonColor), \
/* ToggleButton */ \
OP(kColorId_ToggleButtonShadowColor), \
OP(kColorId_ToggleButtonTrackColorOff), \
OP(kColorId_ToggleButtonTrackColorOn), \
/* MenuItem */ \
OP(kColorId_EnabledMenuItemForegroundColor), \
OP(kColorId_DisabledMenuItemForegroundColor), \
OP(kColorId_SelectedMenuItemForegroundColor), \
OP(kColorId_FocusedMenuItemBackgroundColor), \
OP(kColorId_MenuDropIndicator), \
OP(kColorId_MenuItemMinorTextColor), \
OP(kColorId_MenuSeparatorColor), \
OP(kColorId_MenuBackgroundColor), \
OP(kColorId_MenuBorderColor), \
OP(kColorId_HighlightedMenuItemBackgroundColor), \
OP(kColorId_HighlightedMenuItemForegroundColor), \
OP(kColorId_MenuItemAlertBackgroundColor), \
/* Dropdown */ \
OP(kColorId_DropdownBackgroundColor), \
OP(kColorId_DropdownForegroundColor), \
OP(kColorId_DropdownSelectedBackgroundColor), \
OP(kColorId_DropdownSelectedForegroundColor), \
/* Label */ \
OP(kColorId_LabelEnabledColor), \
OP(kColorId_LabelDisabledColor), \
OP(kColorId_LabelSecondaryColor), \
OP(kColorId_LabelTextSelectionColor), \
OP(kColorId_LabelTextSelectionBackgroundFocused), \
/* Link */ \
OP(kColorId_LinkDisabled), \
OP(kColorId_LinkEnabled), \
OP(kColorId_LinkPressed), \
OP(kColorId_OverlayScrollbarThumbBackground), \
OP(kColorId_OverlayScrollbarThumbForeground), \
/* Slider */ \
OP(kColorId_SliderThumbDefault), \
OP(kColorId_SliderTroughDefault), \
OP(kColorId_SliderThumbMinimal), \
OP(kColorId_SliderTroughMinimal), \
/* Separator */ \
OP(kColorId_SeparatorColor), \
/* TabbedPane */ \
OP(kColorId_TabTitleColorActive), \
OP(kColorId_TabTitleColorInactive), \
OP(kColorId_TabBottomBorder), \
OP(kColorId_TabHighlightBackground), \
OP(kColorId_TabHighlightFocusedBackground), \
/* Textfield */ \
OP(kColorId_TextfieldDefaultColor), \
OP(kColorId_TextfieldDefaultBackground), \
OP(kColorId_TextfieldReadOnlyColor), \
OP(kColorId_TextfieldReadOnlyBackground), \
OP(kColorId_TextfieldSelectionColor), \
OP(kColorId_TextfieldSelectionBackgroundFocused), \
/* Tooltip */ \
OP(kColorId_TooltipBackground), \
OP(kColorId_TooltipIcon), \
OP(kColorId_TooltipIconHovered), \
OP(kColorId_TooltipText), \
/* Tree */ \
OP(kColorId_TreeBackground), \
OP(kColorId_TreeText), \
OP(kColorId_TreeSelectedText), \
OP(kColorId_TreeSelectedTextUnfocused), \
OP(kColorId_TreeSelectionBackgroundFocused), \
OP(kColorId_TreeSelectionBackgroundUnfocused), \
/* Table */ \
OP(kColorId_TableBackground), \
OP(kColorId_TableText), \
OP(kColorId_TableSelectedText), \
OP(kColorId_TableSelectedTextUnfocused), \
OP(kColorId_TableSelectionBackgroundFocused), \
OP(kColorId_TableSelectionBackgroundUnfocused), \
OP(kColorId_TableGroupingIndicatorColor), \
/* Table Header */ \
OP(kColorId_TableHeaderText), \
OP(kColorId_TableHeaderBackground), \
OP(kColorId_TableHeaderSeparator), \
/* Colors for the material spinner (aka throbber). */ \
OP(kColorId_ThrobberSpinningColor), \
OP(kColorId_ThrobberWaitingColor), \
OP(kColorId_ThrobberLightColor), \
/* Colors for icons that alert, e.g. upgrade reminders. */ \
OP(kColorId_AlertSeverityLow), \
OP(kColorId_AlertSeverityMedium), \
OP(kColorId_AlertSeverityHigh), \
/* Colors for icons in secondary UI (content settings, help button, etc). */ \
OP(kColorId_DefaultIconColor)
// clang-format on
#endif // UI_NATIVE_THEME_NATIVE_THEME_COLOR_ID_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/native_theme/native_theme.h"
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
#include "ui/native_theme/native_theme_color_id.h"
namespace ui {
namespace {
constexpr const char* kColorIdStringName[] = {
#define OP(enum_name) #enum_name
NATIVE_THEME_COLOR_IDS
#undef OP
};
class NativeThemeRedirectedEquivalenceTest
: public testing::TestWithParam<NativeTheme::ColorId> {
public:
NativeThemeRedirectedEquivalenceTest() = default;
static std::string ParamInfoToString(
::testing::TestParamInfo<NativeTheme::ColorId> param_info) {
NativeTheme::ColorId color_id = param_info.param;
if (color_id >= NativeTheme::ColorId::kColorId_NumColors) {
ADD_FAILURE() << "Invalid color value " << color_id;
return "Invalid";
}
return kColorIdStringName[color_id];
}
};
} // namespace
TEST_P(NativeThemeRedirectedEquivalenceTest, NativeUiGetSystemColor) {
// Verifies that colors with and without the Color Provider are the same.
NativeTheme* native_theme = NativeTheme::GetInstanceForNativeUi();
NativeTheme::ColorId color_id = GetParam();
SkColor original = native_theme->GetSystemColor(color_id);
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kColorProviderRedirection);
SkColor redirected = native_theme->GetSystemColor(color_id);
EXPECT_EQ(original, redirected);
}
#define OP(enum_name) NativeTheme::ColorId::enum_name
INSTANTIATE_TEST_SUITE_P(
,
NativeThemeRedirectedEquivalenceTest,
::testing::Values(NATIVE_THEME_COLOR_IDS),
NativeThemeRedirectedEquivalenceTest::ParamInfoToString);
#undef OP
} // namespace ui
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