Chromium Code Reviews| Index: chrome/browser/themes/theme_service_unittest.cc |
| diff --git a/chrome/browser/themes/theme_service_unittest.cc b/chrome/browser/themes/theme_service_unittest.cc |
| index 0900a4b942d81580a426ce7e1b51645a3b72fee0..127055d14fe6588a946e80f4b55ddaf859fae2c4 100644 |
| --- a/chrome/browser/themes/theme_service_unittest.cc |
| +++ b/chrome/browser/themes/theme_service_unittest.cc |
| @@ -29,6 +29,7 @@ |
| #include "extensions/common/extension.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/base/material_design/material_design_controller.h" |
| +#include "ui/base/test/material_design_controller_test_api.h" |
| #if defined(ENABLE_SUPERVISED_USERS) |
| #include "chrome/browser/supervised_user/supervised_user_service.h" |
| @@ -45,6 +46,17 @@ class ThemeServiceTest : public extensions::ExtensionServiceTestBase { |
| registry_(NULL) {} |
| ~ThemeServiceTest() override {} |
| + void SetUp() override { |
| + extensions::ExtensionServiceTestBase::SetUp(); |
| + extensions::ExtensionServiceTestBase::ExtensionServiceInitParams params = |
| + CreateDefaultInitParams(); |
| + params.profile_is_supervised = is_supervised_; |
| + InitializeExtensionService(params); |
| + service_->Init(); |
| + registry_ = ExtensionRegistry::Get(profile_.get()); |
| + ASSERT_TRUE(registry_); |
| + } |
| + |
| // Moves a minimal theme to |temp_dir_path| and unpacks it from that |
| // directory. |
| std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) { |
| @@ -92,21 +104,20 @@ class ThemeServiceTest : public extensions::ExtensionServiceTestBase { |
| base::MessageLoop::current()->RunUntilIdle(); |
| } |
| - void SetUp() override { |
| - extensions::ExtensionServiceTestBase::SetUp(); |
| - extensions::ExtensionServiceTestBase::ExtensionServiceInitParams params = |
| - CreateDefaultInitParams(); |
| - params.profile_is_supervised = is_supervised_; |
| - InitializeExtensionService(params); |
| - service_->Init(); |
| - registry_ = ExtensionRegistry::Get(profile_.get()); |
| - ASSERT_TRUE(registry_); |
| - } |
| - |
| const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { |
| return theme_service->get_theme_supplier(); |
| } |
| + // Returns the separator color as the opaque result of blending it atop the |
| + // frame color (which is the color we use when calculating the contrast of the |
| + // separator with the tab and frame colors). |
| + static SkColor GetSeparatorColor(SkColor tab_color, SkColor frame_color) { |
| + const SkColor separator_color = |
| + ThemeService::GetSeparatorColor(tab_color, frame_color); |
| + return color_utils::AlphaBlend(SkColorSetA(separator_color, SK_AlphaOPAQUE), |
| + frame_color, SkColorGetA(separator_color)); |
| + } |
| + |
| protected: |
| bool is_supervised_; |
| ExtensionRegistry* registry_; |
| @@ -376,4 +387,89 @@ TEST_F(ThemeServiceSupervisedUserTest, SupervisedUserThemeReplacesNativeTheme) { |
| #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| #endif // defined(ENABLE_SUPERVISED_USERS) |
| +// Simple class to run tests in material design mode. |
| +class ThemeServiceMaterialDesignTest : public ThemeServiceTest { |
| + public: |
| + void SetUp() override { |
| + ThemeServiceTest::SetUp(); |
| + ui::test::MaterialDesignControllerTestAPI::SetMode( |
| + ui::MaterialDesignController::MATERIAL_NORMAL); |
| + } |
| + |
| + void TearDown() override { |
| + ThemeServiceTest::TearDown(); |
| + ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); |
| + } |
| +}; |
| + |
| +// Check that the function which computes the separator color behaves as |
| +// expected for a variety of inputs. We run in material design mode so we can |
| +// use the material normal and incognito color combinations, which differ from |
| +// each other in ways that are interesting to test. |
| +TEST_F(ThemeServiceMaterialDesignTest, SeparatorColor) { |
| + // For the default theme, the separator should darken the frame. |
| + SkColor tab_color = |
| + ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, false); |
| + SkColor frame_color = |
| + ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_FRAME, false); |
| + SkColor separator_color = GetSeparatorColor(tab_color, frame_color); |
|
Evan Stade
2016/03/15 19:05:06
can you add a check to verify this matches what yo
Peter Kasting
2016/03/16 03:12:59
Sure.
|
| + double frame_luminance = color_utils::GetRelativeLuminance(frame_color); |
| + EXPECT_LT(color_utils::GetRelativeLuminance(separator_color), |
| + frame_luminance); |
| + |
| + // If we reverse the colors, the separator should lighten the frame. |
| + separator_color = GetSeparatorColor(frame_color, tab_color); |
| + EXPECT_GT(color_utils::GetRelativeLuminance(separator_color), |
| + frame_luminance); |
| + |
| + // When the frame color is black, the separator should lighten the frame, but |
| + // it should still be darker than the tab color. |
| + separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK); |
| + double separator_luminance = |
| + color_utils::GetRelativeLuminance(separator_color); |
| + double tab_luminance = color_utils::GetRelativeLuminance(tab_color); |
| + EXPECT_GT(separator_luminance, 0); |
| + EXPECT_LT(separator_luminance, tab_luminance); |
| + |
| + // When the frame color is white, the separator should darken the frame; it |
| + // should also be lighter than the tab color since otherwise the contrast with |
| + // the tab would be too minimal. |
| + separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); |
| + separator_luminance = color_utils::GetRelativeLuminance(separator_color); |
| + EXPECT_LT(separator_luminance, 1); |
| + EXPECT_LT(separator_luminance, tab_luminance); |
| + |
| + // Likewise for the default incognito theme, the separator should darken the |
| + // frame. |
| + tab_color = |
| + ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, true); |
| + frame_color = |
| + ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_FRAME, true); |
| + separator_color = GetSeparatorColor(tab_color, frame_color); |
| + frame_luminance = color_utils::GetRelativeLuminance(frame_color); |
| + EXPECT_LT(color_utils::GetRelativeLuminance(separator_color), |
| + frame_luminance); |
| + |
| + // And if we reverse the colors, the separator should lighten the frame. |
| + separator_color = GetSeparatorColor(frame_color, tab_color); |
| + EXPECT_GT(color_utils::GetRelativeLuminance(separator_color), |
| + frame_luminance); |
| + |
| + // When the frame color is black, the separator should lighten the frame; it |
| + // should also be lighter than the tab color since otherwise the contrast with |
| + // the tab would be too minimal. |
| + separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK); |
| + separator_luminance = color_utils::GetRelativeLuminance(separator_color); |
| + tab_luminance = color_utils::GetRelativeLuminance(tab_color); |
| + EXPECT_GT(separator_luminance, 0); |
| + EXPECT_GT(separator_luminance, tab_luminance); |
| + |
| + // When the frame color is white, the separator should darken the frame, but |
| + // it should still be lighter than the tab color. |
| + separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); |
| + separator_luminance = color_utils::GetRelativeLuminance(separator_color); |
| + EXPECT_LT(separator_luminance, 1); |
| + EXPECT_GT(separator_luminance, tab_luminance); |
| +} |
| + |
| }; // namespace theme_service_internal |