Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2345)

Unified Diff: chrome/common/favicon/fallback_icon_url_parser_unittest.cc

Issue 835903005: [Favicon] Add new fallback icon rendering flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and simplification. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/favicon/fallback_icon_url_parser_unittest.cc
diff --git a/chrome/common/favicon/fallback_icon_url_parser_unittest.cc b/chrome/common/favicon/fallback_icon_url_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e0dbf06d393f159408e9813ff19733ea9437e2f2
--- /dev/null
+++ b/chrome/common/favicon/fallback_icon_url_parser_unittest.cc
@@ -0,0 +1,205 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/favicon/fallback_icon_url_parser.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "components/favicon_base/favicon_types.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/gfx/favicon_size.h"
+
+using favicon_base::FallbackIconStyle;
+
+namespace {
+
+// Default values for FallbackIconStyle, from
+ // /components/favicon_base/favicon_types.h
pkotwicz 2015/01/23 20:44:08 Nit: fix whitespace
huangs 2015/01/26 21:34:56 Done.
+SkColor kDefaultBackgroundColor = SkColorSetRGB(0x80, 0x80, 0x80);
+SkColor kDefaultTextColorDark = SK_ColorBLACK;
+SkColor kDefaultTextColorLight = SK_ColorWHITE;
+double kDefaultFontSizeRatio = 0.8;
+double kDefaultRoundness = 0.125; // 1 / 8.
+
+const char kTestUrl[] = "https://www.google.ca/imghp?hl=en&tab=wi";
+
+} // namespace
+
+namespace chrome {
+
+TEST(FallbackIconUrlParserTest, ParseIconColorSuccess) {
+ SkColor c;
+ EXPECT_TRUE(ParseIconColor("01aBf0f4", &c));
+ EXPECT_EQ(SkColorSetARGB(0xF4, 0x01, 0xAB, 0xF0), c);
+ EXPECT_TRUE(ParseIconColor("01aBf0", &c));
+ EXPECT_EQ(SkColorSetRGB(0x01, 0xAB, 0xF0), c);
+ EXPECT_TRUE(ParseIconColor("01a", &c));
+ EXPECT_EQ(SkColorSetRGB(0x00, 0x11, 0xAA), c);
+ EXPECT_TRUE(ParseIconColor("000000", &c));
+ EXPECT_EQ(SkColorSetARGB(0xFF, 0x00, 0x00, 0x00), c);
+}
+
+TEST(FallbackIconUrlParserTest, ParseIconColorFailure) {
+ const char* test_cases[] = {
+ "",
+ "00000",
+ "000000000",
+ "0 1 2 3 ",
+ " 0 1 2 3",
+ "0ABCDEFG",
+ "#000000",
+ "000000 ",
+ "red"
+ };
+ for (int i = 0; i < arraysize(test_cases); ++i) {
+ SkColor c;
+ EXPECT_FALSE(ParseIconColor(test_cases[i], &c))
+ << "test_cases[" << i << "]";
+ }
+}
+
+TEST(FallbackIconUrlParserTest, ParseFallbackIconSpecsEmpty) {
+ int size;
+ FallbackIconStyle style;
+ EXPECT_TRUE(ParseFallbackIconSpecs(",,,,", &size, &style));
+ EXPECT_EQ(16, size);
+ EXPECT_EQ(kDefaultBackgroundColor, style.background_color);
+ EXPECT_EQ(kDefaultTextColorLight, style.text_color);
+ EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio);
+ EXPECT_EQ(kDefaultRoundness, style.roundness);
+}
+
+TEST(FallbackIconUrlParserTest, ParseFallbackIconSpecsPartial) {
+ int size;
+ FallbackIconStyle style;
+ EXPECT_TRUE(ParseFallbackIconSpecs(",,aCE,,0.1", &size, &style));
+ EXPECT_EQ(16, size);
+ EXPECT_EQ(kDefaultBackgroundColor, style.background_color);
+ EXPECT_EQ(SkColorSetRGB(0xAA, 0xCC, 0xEE), style.text_color);
+ EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio);
+ EXPECT_EQ(0.1, style.roundness);
+}
+
+TEST(FallbackIconUrlParserTest, ParseFallbackIconSpecsFull) {
+ int size1;
+ FallbackIconStyle style1;
+ EXPECT_TRUE(ParseFallbackIconSpecs("16,000,fff,0.75,0.25", &size1, &style1));
+ EXPECT_EQ(16, size1);
+ EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style1.background_color);
+ EXPECT_EQ(SkColorSetRGB(0xff, 0xff, 0xff), style1.text_color);
+ EXPECT_EQ(0.75, style1.font_size_ratio);
+ EXPECT_EQ(0.25, style1.roundness);
+
+ int size2;
+ FallbackIconStyle style2;
+ EXPECT_TRUE(ParseFallbackIconSpecs("48,f05,123456,0.5,0.3", &size2, &style2));
+ EXPECT_EQ(48, size2);
+ EXPECT_EQ(SkColorSetRGB(0xff, 0x00, 0x55), style2.background_color);
+ EXPECT_EQ(SkColorSetRGB(0x12, 0x34, 0x56), style2.text_color);
+ EXPECT_EQ(0.5, style2.font_size_ratio);
+ EXPECT_EQ(0.3, style2.roundness);
+
+ int size3;
+ FallbackIconStyle style3;
+ EXPECT_TRUE(ParseFallbackIconSpecs("1,000,000,0,0", &size3, &style3));
+ EXPECT_EQ(1, size3);
+ EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style3.background_color);
+ EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style3.text_color);
+ EXPECT_EQ(0, style3.font_size_ratio);
+ EXPECT_EQ(0, style3.roundness);
+}
+
+TEST(FallbackIconUrlParserTest, ParseFallbackIconSpecsDefaultTextColor) {
+ int size;
+
+ // Dark background -> Light text.
+ FallbackIconStyle style1;
+ EXPECT_TRUE(ParseFallbackIconSpecs(",000,,,", &size, &style1));
+ EXPECT_EQ(kDefaultTextColorLight, style1.text_color);
+
+ // Light background -> Dark text.
+ FallbackIconStyle style2;
+ EXPECT_TRUE(ParseFallbackIconSpecs(",fff,,,", &size, &style2));
+ EXPECT_EQ(kDefaultTextColorDark, style2.text_color);
+
+ // Light background -> Dark text, more params don't matter.
+ FallbackIconStyle style3;
+ EXPECT_TRUE(ParseFallbackIconSpecs("107,fff,,0.3,0.5", &size, &style3));
+ EXPECT_EQ(kDefaultTextColorDark, style2.text_color);
+}
+
+TEST(FallbackIconUrlParserTest, ParseFallbackIconSpecsFailure) {
+ const char* test_cases[] = {
+ // Need exactly 5 params.
+ "",
+ "16",
+ "16,000",
+ "16,000,fff",
+ "16,000,fff,0.75",
+ ",,,"
+ ",,,,,",
+ "16,000,fff,0.75,0.25,junk",
+ // Don't allow any space.
+ "16,000,fff, 0.75,0.25",
+ "16,000 ,fff,0.75,0.25",
+ "16,000,fff,0.75,0.25 ",
+ // Adding junk text.
+ "16,000,fff,0.75,0.25junk",
+ "junk,000,fff,0.75,0.25",
+ "16,junk,fff,0.75,0.25",
+ "16,000,junk,0.75,0.25",
+ "16,000,fff,junk,0.25",
+ "16,000,fff,0.75,junk",
+ // Out of bound.
+ "0,000,fff,0.75,0.25", // size.
+ "4294967296,000,fff,0.75,0.25", // size.
+ "-1,000,fff,0.75,0.25", // size.
+ "16,000,fff,-0.1,0.25", // font_size_ratio.
+ "16,000,fff,1.1,0.25", // font_size_ratio.
+ "16,000,fff,0.75,-0.1", // roundness.
+ "16,000,fff,0.75,1.1", // roundness.
+ };
+ for (int i = 0; i < arraysize(test_cases); ++i) {
+ int size;
+ FallbackIconStyle style;
+ EXPECT_FALSE(ParseFallbackIconSpecs(test_cases[i], &size, &style))
+ << "test_cases[" << i << "]";
+
+ }
+}
+
+TEST(FallbackIconUrlParserTest, ParseFallbackIconPath) {
+ const std::string specs = "31,000,fff,0.75,0.25";
+ const std::string url = kTestUrl;
+ chrome::ParsedFallbackIconPath parsed;
+
+ // Everything populated.
+ EXPECT_TRUE(chrome::ParseFallbackIconPath(specs + "/" + url, &parsed));
+ EXPECT_EQ(kTestUrl, parsed.url);
+ EXPECT_EQ(31, parsed.size_in_pixels);
+ EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), parsed.style.background_color);
+ EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), parsed.style.text_color);
+ EXPECT_EQ(0.75, parsed.style.font_size_ratio);
+ EXPECT_EQ(0.25, parsed.style.roundness);
+
+ // Empty URL.
+ EXPECT_TRUE(chrome::ParseFallbackIconPath(specs + "/", &parsed));
+ EXPECT_EQ("", parsed.url);
+ EXPECT_EQ(31, parsed.size_in_pixels);
+ EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), parsed.style.background_color);
+ EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), parsed.style.text_color);
+ EXPECT_EQ(0.75, parsed.style.font_size_ratio);
+ EXPECT_EQ(0.25, parsed.style.roundness);
+
+ // Size and style are default.
+ EXPECT_TRUE(chrome::ParseFallbackIconPath(",,,,/" + url, &parsed));
+ EXPECT_EQ(kTestUrl, parsed.url);
+ EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels);
+ EXPECT_EQ(kDefaultBackgroundColor, parsed.style.background_color);
+ EXPECT_EQ(kDefaultTextColorLight, parsed.style.text_color);
+ EXPECT_EQ(kDefaultFontSizeRatio, parsed.style.font_size_ratio);
+ EXPECT_EQ(kDefaultRoundness, parsed.style.roundness);
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698