diff options
author | limasdf <limasdf@gmail.com> | 2016-03-10 03:14:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-10 11:15:37 +0000 |
commit | 2fc1c838798d0c76f1c135f1791d3989ab7a2b01 (patch) | |
tree | 3576eb540f370455cbb456b91d4c25ab12c46983 /extensions/common | |
parent | 37f57d892222dc0ed816ae004074d7c80600ad46 (diff) | |
download | chromium_src-2fc1c838798d0c76f1c135f1791d3989ab7a2b01.zip chromium_src-2fc1c838798d0c76f1c135f1791d3989ab7a2b01.tar.gz chromium_src-2fc1c838798d0c76f1c135f1791d3989ab7a2b01.tar.bz2 |
chrome.browserAction.setBadgeBackgroundColor accepts color keyword
Accepts color keyword like 'black', 'blue' from setBadgeBackgroundColor.
Also, if unable to parse color string, returns proper error message
TEST=browser_tests --gtest_filter=BrowserActionApiTest.BadgeBackgroundColor
extensions_unittests --gtest_filter=ImageUtilTest.*
BUG=593194
Review URL: https://codereview.chromium.org/1781563003
Cr-Commit-Position: refs/heads/master@{#380386}
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 |