diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-11 22:09:55 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-11 22:09:55 +0000 |
commit | 75cbb35fa7fb6ce0a511612ec91998c053247be8 (patch) | |
tree | 5abee27b2c5f2c60e5017aa6c00b43d9fe2376f4 /chrome/browser/browser_theme_provider_unittest.cc | |
parent | 9fa8c2f5e9581c2e521fd28aadedc4c77b9b2150 (diff) | |
download | chromium_src-75cbb35fa7fb6ce0a511612ec91998c053247be8.zip chromium_src-75cbb35fa7fb6ce0a511612ec91998c053247be8.tar.gz chromium_src-75cbb35fa7fb6ce0a511612ec91998c053247be8.tar.bz2 |
Revert "Completely redo how themes are stored on disk and processed at install
time," as it fails valgrind tests.
This reverts commit 86faccd1028937a69ccc718718fd48c06c0cd471 (r34379).
Review URL: http://codereview.chromium.org/490025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34385 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_theme_provider_unittest.cc')
-rw-r--r-- | chrome/browser/browser_theme_provider_unittest.cc | 179 |
1 files changed, 177 insertions, 2 deletions
diff --git a/chrome/browser/browser_theme_provider_unittest.cc b/chrome/browser/browser_theme_provider_unittest.cc index 533c7af..6556a56 100644 --- a/chrome/browser/browser_theme_provider_unittest.cc +++ b/chrome/browser/browser_theme_provider_unittest.cc @@ -8,7 +8,87 @@ #include "base/values.h" #include "base/json/json_reader.h" -TEST(BrowserThemeProviderTest, AlignmentConversion) { +class BrowserThemeProviderTest : public ::testing::Test { + public: + // Transformation for link underline colors. + SkColor BuildThirdOpacity(SkColor color_link) { + return SkColorSetA(color_link, SkColorGetA(color_link) / 3); + } + + // Returns a mapping from each COLOR_* constant to the default value for this + // constant. Callers get this map, and then modify expected values and then + // run the resulting thing through VerifyColorMap(). + std::map<int, SkColor> GetDefaultColorMap() { + std::map<int, SkColor> colors; + colors[BrowserThemeProvider::COLOR_FRAME] = + BrowserThemeProvider::kDefaultColorFrame; + colors[BrowserThemeProvider::COLOR_FRAME_INACTIVE] = + BrowserThemeProvider::kDefaultColorFrameInactive; + colors[BrowserThemeProvider::COLOR_FRAME_INCOGNITO] = + BrowserThemeProvider::kDefaultColorFrameIncognito; + colors[BrowserThemeProvider::COLOR_FRAME_INCOGNITO_INACTIVE] = + BrowserThemeProvider::kDefaultColorFrameIncognitoInactive; + colors[BrowserThemeProvider::COLOR_TOOLBAR] = + BrowserThemeProvider::kDefaultColorToolbar; + colors[BrowserThemeProvider::COLOR_TAB_TEXT] = + BrowserThemeProvider::kDefaultColorTabText; + colors[BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT] = + BrowserThemeProvider::kDefaultColorBackgroundTabText; + colors[BrowserThemeProvider::COLOR_BOOKMARK_TEXT] = + BrowserThemeProvider::kDefaultColorBookmarkText; + colors[BrowserThemeProvider::COLOR_NTP_BACKGROUND] = + BrowserThemeProvider::kDefaultColorNTPBackground; + colors[BrowserThemeProvider::COLOR_NTP_TEXT] = + BrowserThemeProvider::kDefaultColorNTPText; + colors[BrowserThemeProvider::COLOR_NTP_LINK] = + BrowserThemeProvider::kDefaultColorNTPLink; + colors[BrowserThemeProvider::COLOR_NTP_LINK_UNDERLINE] = + BuildThirdOpacity(BrowserThemeProvider::kDefaultColorNTPLink); + colors[BrowserThemeProvider::COLOR_NTP_HEADER] = + BrowserThemeProvider::kDefaultColorNTPHeader; + colors[BrowserThemeProvider::COLOR_NTP_SECTION] = + BrowserThemeProvider::kDefaultColorNTPSection; + colors[BrowserThemeProvider::COLOR_NTP_SECTION_TEXT] = + BrowserThemeProvider::kDefaultColorNTPSectionText; + colors[BrowserThemeProvider::COLOR_NTP_SECTION_LINK] = + BrowserThemeProvider::kDefaultColorNTPSectionLink; + colors[BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE] = + BuildThirdOpacity(BrowserThemeProvider::kDefaultColorNTPSectionLink); + colors[BrowserThemeProvider::COLOR_CONTROL_BACKGROUND] = + BrowserThemeProvider::kDefaultColorControlBackground; + colors[BrowserThemeProvider::COLOR_BUTTON_BACKGROUND] = + BrowserThemeProvider::kDefaultColorButtonBackground; + + return colors; + } + + void VerifyColorMap(const std::map<int, SkColor>& color_map) { + for (std::map<int, SkColor>::const_iterator it = color_map.begin(); + it != color_map.end(); ++it) { + EXPECT_EQ(it->second, provider_.GetColor(it->first)); + } + } + + void LoadColorJSON(const std::string& json) { + scoped_ptr<Value> value(base::JSONReader::Read(json, false)); + ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); + provider_.SetColorData(static_cast<DictionaryValue*>(value.get())); + } + + void LoadTintJSON(const std::string& json) { + scoped_ptr<Value> value(base::JSONReader::Read(json, false)); + ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY)); + provider_.SetTintData(static_cast<DictionaryValue*>(value.get())); + } + + void GenerateFrameColors() { + provider_.GenerateFrameColors(); + } + + BrowserThemeProvider provider_; +}; + +TEST_F(BrowserThemeProviderTest, AlignmentConversion) { // Verify that we get out what we put in. std::string top_left = "top left"; int alignment = BrowserThemeProvider::StringToAlignment(top_left); @@ -33,7 +113,7 @@ TEST(BrowserThemeProviderTest, AlignmentConversion) { EXPECT_EQ("", BrowserThemeProvider::AlignmentToString(alignment)); } -TEST(BrowserThemeProviderTest, AlignmentConversionInput) { +TEST_F(BrowserThemeProviderTest, AlignmentConversionInput) { // Verify that we output in an expected format. int alignment = BrowserThemeProvider::StringToAlignment("right bottom"); EXPECT_EQ("bottom right", BrowserThemeProvider::AlignmentToString(alignment)); @@ -50,3 +130,98 @@ TEST(BrowserThemeProviderTest, AlignmentConversionInput) { alignment = BrowserThemeProvider::StringToAlignment("new zealandtop"); EXPECT_EQ("", BrowserThemeProvider::AlignmentToString(alignment)); } + +TEST_F(BrowserThemeProviderTest, ColorSanityCheck) { + // Make sure that BrowserThemeProvider returns all the default colors if it + // isn't provided any color overrides. + std::map<int, SkColor> colors = GetDefaultColorMap(); + VerifyColorMap(colors); +} + +TEST_F(BrowserThemeProviderTest, DeriveUnderlineLinkColor) { + // If we specify a link color, but don't specify the underline color, the + // theme provider should create one. + std::string color_json = "{ \"ntp_link\": [128, 128, 128, 1]," + " \"ntp_section_link\": [128, 128, 128, 1] }"; + LoadColorJSON(color_json); + + std::map<int, SkColor> colors = GetDefaultColorMap(); + SkColor link_color = SkColorSetARGB(255, 128, 128, 128); + colors[BrowserThemeProvider::COLOR_NTP_LINK] = link_color; + colors[BrowserThemeProvider::COLOR_NTP_LINK_UNDERLINE] = + BuildThirdOpacity(link_color); + colors[BrowserThemeProvider::COLOR_NTP_SECTION_LINK] = link_color; + colors[BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE] = + BuildThirdOpacity(link_color); + + VerifyColorMap(colors); +} + +TEST_F(BrowserThemeProviderTest, ProvideUnderlineLinkColor) { + // If we specify the underline color, it shouldn't try to generate one.x + std::string color_json = "{ \"ntp_link\": [128, 128, 128]," + " \"ntp_link_underline\": [255, 255, 255]," + " \"ntp_section_link\": [128, 128, 128]," + " \"ntp_section_link_underline\": [255, 255, 255]" + "}"; + LoadColorJSON(color_json); + + std::map<int, SkColor> colors = GetDefaultColorMap(); + SkColor link_color = SkColorSetRGB(128, 128, 128); + SkColor underline_color = SkColorSetRGB(255, 255, 255); + colors[BrowserThemeProvider::COLOR_NTP_LINK] = link_color; + colors[BrowserThemeProvider::COLOR_NTP_LINK_UNDERLINE] = underline_color; + colors[BrowserThemeProvider::COLOR_NTP_SECTION_LINK] = link_color; + colors[BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE] = + underline_color; + + VerifyColorMap(colors); +} + +TEST_F(BrowserThemeProviderTest, UseSectionColorAsNTPHeader) { + std::string color_json = "{ \"ntp_section\": [190, 190, 190] }"; + LoadColorJSON(color_json); + + std::map<int, SkColor> colors = GetDefaultColorMap(); + SkColor ntp_color = SkColorSetRGB(190, 190, 190); + colors[BrowserThemeProvider::COLOR_NTP_HEADER] = ntp_color; + colors[BrowserThemeProvider::COLOR_NTP_SECTION] = ntp_color; + VerifyColorMap(colors); +} + +TEST_F(BrowserThemeProviderTest, ProvideNtpHeaderColor) { + std::string color_json = "{ \"ntp_header\": [120, 120, 120], " + " \"ntp_section\": [190, 190, 190] }"; + LoadColorJSON(color_json); + + std::map<int, SkColor> colors = GetDefaultColorMap(); + SkColor ntp_header = SkColorSetRGB(120, 120, 120); + SkColor ntp_section = SkColorSetRGB(190, 190, 190); + colors[BrowserThemeProvider::COLOR_NTP_HEADER] = ntp_header; + colors[BrowserThemeProvider::COLOR_NTP_SECTION] = ntp_section; + VerifyColorMap(colors); +} + +TEST_F(BrowserThemeProviderTest, DefaultTintingDefaultColors) { + // Default tints for buttons and frames...are no tints! So make sure that + // when we try to generate frame colors, we end up with the same. + GenerateFrameColors(); + + std::map<int, SkColor> colors = GetDefaultColorMap(); + colors[BrowserThemeProvider::COLOR_FRAME] = + HSLShift(BrowserThemeProvider::kDefaultColorFrame, + BrowserThemeProvider::kDefaultTintFrame); + colors[BrowserThemeProvider::COLOR_FRAME_INACTIVE] = + HSLShift(BrowserThemeProvider::kDefaultColorFrame, + BrowserThemeProvider::kDefaultTintFrameInactive); + colors[BrowserThemeProvider::COLOR_FRAME_INCOGNITO] = + HSLShift(BrowserThemeProvider::kDefaultColorFrame, + BrowserThemeProvider::kDefaultTintFrameIncognito); + colors[BrowserThemeProvider::COLOR_FRAME_INCOGNITO_INACTIVE] = + HSLShift(BrowserThemeProvider::kDefaultColorFrame, + BrowserThemeProvider::kDefaultTintFrameIncognitoInactive); + VerifyColorMap(colors); +} + +// TODO(erg): Test more tinting combinations. For example, with non-default +// colors or when providing tints. |