diff options
Diffstat (limited to 'extensions/common')
-rw-r--r-- | extensions/common/image_util.cc | 6 | ||||
-rw-r--r-- | extensions/common/image_util_unittest.cc | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/extensions/common/image_util.cc b/extensions/common/image_util.cc index efad19b..6a8e13a 100644 --- a/extensions/common/image_util.cc +++ b/extensions/common/image_util.cc @@ -13,6 +13,7 @@ #include "base/strings/stringprintf.h" #include "third_party/re2/src/re2/re2.h" #include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/utils/SkParse.h" #include "ui/gfx/color_utils.h" namespace extensions { @@ -29,6 +30,11 @@ bool ParseCssColorString(const std::string& color_string, SkColor* result) { NOTIMPLEMENTED(); return false; } + if (SkParse::FindNamedColor(color_string.c_str(), color_string.size(), + result) != nullptr) { + return true; + } + return false; } diff --git a/extensions/common/image_util_unittest.cc b/extensions/common/image_util_unittest.cc index 8e7d80f..e4a81bb 100644 --- a/extensions/common/image_util_unittest.cc +++ b/extensions/common/image_util_unittest.cc @@ -108,4 +108,15 @@ TEST(ImageUtilTest, AcceptHsla) { RunPassHslTest("hsla(0, 100%, 50%, 1)", SK_ColorRED); } +TEST(ImageUtilTest, BasicColorKeyword) { + SkColor color = 0; + EXPECT_TRUE(image_util::ParseCssColorString("red", &color)); + EXPECT_EQ(color, SK_ColorRED); + + EXPECT_TRUE(image_util::ParseCssColorString("blue", &color)); + EXPECT_EQ(color, SK_ColorBLUE); + + EXPECT_FALSE(image_util::ParseCssColorString("my_red", &color)); +} + } // namespace extensions |