summaryrefslogtreecommitdiffstats
path: root/extensions/common/image_util_unittest.cc
diff options
context:
space:
mode:
authorlimasdf <limasdf@gmail.com>2015-11-01 11:39:14 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-01 19:40:10 +0000
commit3aa01facda4b2c43f0ffdbaa65c7b91b971c18f7 (patch)
treeceaf69deeed8bfd699897657e6d720ed281824e3 /extensions/common/image_util_unittest.cc
parent0bf3ae453e2c4bb9ba0f5e78a7f82847d55f2d5a (diff)
downloadchromium_src-3aa01facda4b2c43f0ffdbaa65c7b91b971c18f7.zip
chromium_src-3aa01facda4b2c43f0ffdbaa65c7b91b971c18f7.tar.gz
chromium_src-3aa01facda4b2c43f0ffdbaa65c7b91b971c18f7.tar.bz2
chrome.browserAction.setBadgeBackgroundColor accepts hsl CSS color strings
Accepts HSL(Hue-Saturation-Lightness) color model from setBadgeBackgroundColor. e.g. hsl(120, 100%, 50%), hsla(120, 100%, 50%, 0.5) TEST=browser_tests --gtest_filter=BrowserActionApiTest.BadgeBackgroundColor extensions_unittests --gtest_filter=ImageUtilTest.* BUG=545194 Review URL: https://codereview.chromium.org/1412823004 Cr-Commit-Position: refs/heads/master@{#357289}
Diffstat (limited to 'extensions/common/image_util_unittest.cc')
-rw-r--r--extensions/common/image_util_unittest.cc81
1 files changed, 70 insertions, 11 deletions
diff --git a/extensions/common/image_util_unittest.cc b/extensions/common/image_util_unittest.cc
index ca13ab2..8e7d80f 100644
--- a/extensions/common/image_util_unittest.cc
+++ b/extensions/common/image_util_unittest.cc
@@ -7,46 +7,105 @@
#include "extensions/common/image_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/gfx/color_utils.h"
namespace extensions {
-void RunPassTest(const std::string& css_string, SkColor expected_result) {
+void RunPassHexTest(const std::string& css_string, SkColor expected_result) {
SkColor color = 0;
- EXPECT_TRUE(image_util::ParseCSSColorString(css_string, &color));
+ EXPECT_TRUE(image_util::ParseHexColorString(css_string, &color));
EXPECT_EQ(color, expected_result);
}
-void RunFailTest(const std::string& css_string) {
+void RunFailHexTest(const std::string& css_string) {
SkColor color = 0;
- EXPECT_FALSE(image_util::ParseCSSColorString(css_string, &color));
+ EXPECT_FALSE(image_util::ParseHexColorString(css_string, &color));
+}
+
+void RunPassHslTest(const std::string& hsl_string, SkColor expected) {
+ SkColor color = 0;
+ EXPECT_TRUE(image_util::ParseHslColorString(hsl_string, &color));
+ EXPECT_EQ(color, expected);
+}
+
+void RunFailHslTest(const std::string& hsl_string) {
+ SkColor color = 0;
+ EXPECT_FALSE(image_util::ParseHslColorString(hsl_string, &color));
}
TEST(ImageUtilTest, ChangeBadgeBackgroundNormalCSS) {
- RunPassTest("#34006A", SkColorSetARGB(0xFF, 0x34, 0, 0x6A));
+ RunPassHexTest("#34006A", SkColorSetARGB(0xFF, 0x34, 0, 0x6A));
}
TEST(ImageUtilTest, ChangeBadgeBackgroundShortCSS) {
- RunPassTest("#A1E", SkColorSetARGB(0xFF, 0xAA, 0x11, 0xEE));
+ RunPassHexTest("#A1E", SkColorSetARGB(0xFF, 0xAA, 0x11, 0xEE));
}
TEST(ImageUtilTest, ChangeBadgeBackgroundCSSNoHash) {
- RunFailTest("11FF22");
+ RunFailHexTest("11FF22");
}
TEST(ImageUtilTest, ChangeBadgeBackgroundCSSTooShort) {
- RunFailTest("#FF22");
+ RunFailHexTest("#FF22");
}
TEST(ImageUtilTest, ChangeBadgeBackgroundCSSTooLong) {
- RunFailTest("#FF22128");
+ RunFailHexTest("#FF22128");
}
TEST(ImageUtilTest, ChangeBadgeBackgroundCSSInvalid) {
- RunFailTest("#-22128");
+ RunFailHexTest("#-22128");
}
TEST(ImageUtilTest, ChangeBadgeBackgroundCSSInvalidWithPlus) {
- RunFailTest("#+22128");
+ RunFailHexTest("#+22128");
+}
+
+TEST(ImageUtilTest, AcceptHsl) {
+ // Run basic color tests.
+ RunPassHslTest("hsl(0, 100%, 50%)", SK_ColorRED);
+ RunPassHslTest("hsl(120, 100%, 50%)", SK_ColorGREEN);
+ RunPassHslTest("hsl(240, 100%, 50%)", SK_ColorBLUE);
+ RunPassHslTest("hsl(180, 100%, 50%)", SK_ColorCYAN);
+
+ // Passing in >100% saturation should be equivalent to 100%.
+ RunPassHslTest("hsl(120, 200%, 50%)", SK_ColorGREEN);
+
+ // Passing in the same degree +/- full rotations should be equivalent.
+ RunPassHslTest("hsl(480, 100%, 50%)", SK_ColorGREEN);
+ RunPassHslTest("hsl(-240, 100%, 50%)", SK_ColorGREEN);
+
+ // We should be able to parse doubles
+ RunPassHslTest("hsl(120.0, 100.0%, 50.0%)", SK_ColorGREEN);
+}
+
+TEST(ImageUtilTest, InvalidHsl) {
+ RunFailHslTest("(0,100%,50%)");
+ RunFailHslTest("[0, 100, 50]");
+ RunFailHslTest("hs l(0,100%,50%)");
+ RunFailHslTest("rgb(0,100%,50%)");
+ RunFailHslTest("hsl(0,100%)");
+ RunFailHslTest("hsl(100%,50%)");
+ RunFailHslTest("hsl(120, 100, 50)");
+ RunFailHslTest("hsl[120, 100%, 50%]");
+ RunFailHslTest("hsl(120, 100%, 50%, 1.0)");
+ RunFailHslTest("hsla(120, 100%, 50%)");
+}
+
+TEST(ImageUtilTest, AcceptHsla) {
+ // Run basic color tests.
+ RunPassHslTest("hsla(0, 100%, 50%, 1.0)", SK_ColorRED);
+ RunPassHslTest("hsla(0, 100%, 50%, 0.0)",
+ SkColorSetARGB(0x00, 0xFF, 0x00, 0x00));
+ RunPassHslTest("hsla(0, 100%, 50%, 0.5)",
+ SkColorSetARGB(0x7F, 0xFF, 0x00, 0x00));
+ RunPassHslTest("hsla(0, 100%, 50%, 0.25)",
+ SkColorSetARGB(0x3F, 0xFF, 0x00, 0x00));
+ RunPassHslTest("hsla(0, 100%, 50%, 0.75)",
+ SkColorSetARGB(0xBF, 0xFF, 0x00, 0x00));
+
+ // We should able to parse integer alpha value.
+ RunPassHslTest("hsla(0, 100%, 50%, 1)", SK_ColorRED);
}
} // namespace extensions