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

Side by Side Diff: components/favicon_base/fallback_icon_url_parser_unittest.cc

Issue 2374753002: Track when fallback icon color is the default. (Closed)
Patch Set: Merge branch 'refs/heads/master' into default-color Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/favicon_base/fallback_icon_url_parser.h" 5 #include "components/favicon_base/fallback_icon_url_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "components/favicon_base/fallback_icon_style.h" 10 #include "components/favicon_base/fallback_icon_style.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 << "test_cases[" << i << "]"; 86 << "test_cases[" << i << "]";
87 } 87 }
88 } 88 }
89 89
90 TEST_F(FallbackIconUrlParserTest, ParseSpecsEmpty) { 90 TEST_F(FallbackIconUrlParserTest, ParseSpecsEmpty) {
91 int size; 91 int size;
92 FallbackIconStyle style; 92 FallbackIconStyle style;
93 EXPECT_TRUE(ParseSpecs(",,,,", &size, &style)); 93 EXPECT_TRUE(ParseSpecs(",,,,", &size, &style));
94 EXPECT_EQ(16, size); 94 EXPECT_EQ(16, size);
95 EXPECT_EQ(kDefaultBackgroundColor, style.background_color); 95 EXPECT_EQ(kDefaultBackgroundColor, style.background_color);
96 EXPECT_TRUE(style.is_default_background_color);
96 EXPECT_EQ(kDefaultTextColorLight, style.text_color); 97 EXPECT_EQ(kDefaultTextColorLight, style.text_color);
97 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio); 98 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio);
98 EXPECT_EQ(kDefaultRoundness, style.roundness); 99 EXPECT_EQ(kDefaultRoundness, style.roundness);
99 } 100 }
100 101
101 TEST_F(FallbackIconUrlParserTest, ParseSpecsPartial) { 102 TEST_F(FallbackIconUrlParserTest, ParseSpecsPartial) {
102 int size; 103 int size;
103 FallbackIconStyle style; 104 FallbackIconStyle style;
104 EXPECT_TRUE(ParseSpecs(",,aCE,,0.1", &size, &style)); 105 EXPECT_TRUE(ParseSpecs(",,aCE,,0.1", &size, &style));
105 EXPECT_EQ(16, size); 106 EXPECT_EQ(16, size);
106 EXPECT_EQ(kDefaultBackgroundColor, style.background_color); 107 EXPECT_EQ(kDefaultBackgroundColor, style.background_color);
108 EXPECT_TRUE(style.is_default_background_color);
107 EXPECT_EQ(SkColorSetRGB(0xAA, 0xCC, 0xEE), style.text_color); 109 EXPECT_EQ(SkColorSetRGB(0xAA, 0xCC, 0xEE), style.text_color);
108 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio); 110 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio);
109 EXPECT_EQ(0.1, style.roundness); 111 EXPECT_EQ(0.1, style.roundness);
110 } 112 }
111 113
112 TEST_F(FallbackIconUrlParserTest, ParseSpecsFull) { 114 TEST_F(FallbackIconUrlParserTest, ParseSpecsFull) {
113 int size; 115 int size;
114 116
115 { 117 {
116 FallbackIconStyle style; 118 FallbackIconStyle style;
117 EXPECT_TRUE(ParseSpecs("16,000,f01,0.75,0.25", &size, &style)); 119 EXPECT_TRUE(ParseSpecs("16,000,f01,0.75,0.25", &size, &style));
118 EXPECT_EQ(16, size); 120 EXPECT_EQ(16, size);
119 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); 121 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color);
122 EXPECT_FALSE(style.is_default_background_color);
120 EXPECT_EQ(SkColorSetRGB(0xff, 0x00, 0x11), style.text_color); 123 EXPECT_EQ(SkColorSetRGB(0xff, 0x00, 0x11), style.text_color);
121 EXPECT_EQ(0.75, style.font_size_ratio); 124 EXPECT_EQ(0.75, style.font_size_ratio);
122 EXPECT_EQ(0.25, style.roundness); 125 EXPECT_EQ(0.25, style.roundness);
123 } 126 }
124 127
125 { 128 {
126 FallbackIconStyle style; 129 FallbackIconStyle style;
127 EXPECT_TRUE(ParseSpecs("48,black,123456,0.5,0.3", &size, &style)); 130 EXPECT_TRUE(ParseSpecs("48,black,123456,0.5,0.3", &size, &style));
128 EXPECT_EQ(48, size); 131 EXPECT_EQ(48, size);
129 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); 132 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color);
133 EXPECT_FALSE(style.is_default_background_color);
130 EXPECT_EQ(SkColorSetRGB(0x12, 0x34, 0x56), style.text_color); 134 EXPECT_EQ(SkColorSetRGB(0x12, 0x34, 0x56), style.text_color);
131 EXPECT_EQ(0.5, style.font_size_ratio); 135 EXPECT_EQ(0.5, style.font_size_ratio);
132 EXPECT_EQ(0.3, style.roundness); 136 EXPECT_EQ(0.3, style.roundness);
133 } 137 }
134 138
135 { 139 {
136 FallbackIconStyle style; 140 FallbackIconStyle style;
137 EXPECT_TRUE(ParseSpecs("1,000,red,0,0", &size, &style)); 141 EXPECT_TRUE(ParseSpecs("1,000,red,0,0", &size, &style));
138 EXPECT_EQ(1, size); 142 EXPECT_EQ(1, size);
139 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); 143 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color);
144 EXPECT_FALSE(style.is_default_background_color);
140 EXPECT_EQ(SkColorSetRGB(0xFF, 0x00, 0x00), style.text_color); 145 EXPECT_EQ(SkColorSetRGB(0xFF, 0x00, 0x00), style.text_color);
141 EXPECT_EQ(0, style.font_size_ratio); 146 EXPECT_EQ(0, style.font_size_ratio);
142 EXPECT_EQ(0, style.roundness); 147 EXPECT_EQ(0, style.roundness);
143 } 148 }
144 } 149 }
145 150
146 TEST_F(FallbackIconUrlParserTest, ParseSpecsDefaultTextColor) { 151 TEST_F(FallbackIconUrlParserTest, ParseSpecsDefaultTextColor) {
147 int size; 152 int size;
148 153
149 { 154 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathSuccess) { 216 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathSuccess) {
212 const std::string specs = "31,black,fff,0.75,0.25"; 217 const std::string specs = "31,black,fff,0.75,0.25";
213 218
214 // Everything populated. 219 // Everything populated.
215 { 220 {
216 chrome::ParsedFallbackIconPath parsed; 221 chrome::ParsedFallbackIconPath parsed;
217 EXPECT_TRUE(parsed.Parse(specs + "/" + kTestUrlStr)); 222 EXPECT_TRUE(parsed.Parse(specs + "/" + kTestUrlStr));
218 EXPECT_EQ(31, parsed.size_in_pixels()); 223 EXPECT_EQ(31, parsed.size_in_pixels());
219 const favicon_base::FallbackIconStyle& style = parsed.style(); 224 const favicon_base::FallbackIconStyle& style = parsed.style();
220 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); 225 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color);
226 EXPECT_FALSE(style.is_default_background_color);
221 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); 227 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color);
222 EXPECT_EQ(0.75, style.font_size_ratio); 228 EXPECT_EQ(0.75, style.font_size_ratio);
223 EXPECT_EQ(0.25, style.roundness); 229 EXPECT_EQ(0.25, style.roundness);
224 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string())); 230 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string()));
225 EXPECT_EQ(specs.length() + 1, parsed.path_index()); 231 EXPECT_EQ(specs.length() + 1, parsed.path_index());
226 } 232 }
227 233
228 // Empty URL. 234 // Empty URL.
229 { 235 {
230 chrome::ParsedFallbackIconPath parsed; 236 chrome::ParsedFallbackIconPath parsed;
231 EXPECT_TRUE(parsed.Parse(specs + "/")); 237 EXPECT_TRUE(parsed.Parse(specs + "/"));
232 EXPECT_EQ(31, parsed.size_in_pixels()); 238 EXPECT_EQ(31, parsed.size_in_pixels());
233 const favicon_base::FallbackIconStyle& style = parsed.style(); 239 const favicon_base::FallbackIconStyle& style = parsed.style();
234 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); 240 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color);
241 EXPECT_FALSE(style.is_default_background_color);
235 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); 242 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color);
236 EXPECT_EQ(0.75, style.font_size_ratio); 243 EXPECT_EQ(0.75, style.font_size_ratio);
237 EXPECT_EQ(0.25, style.roundness); 244 EXPECT_EQ(0.25, style.roundness);
238 EXPECT_EQ(GURL(), GURL(parsed.url_string())); 245 EXPECT_EQ(GURL(), GURL(parsed.url_string()));
239 EXPECT_EQ(specs.length() + 1, parsed.path_index()); 246 EXPECT_EQ(specs.length() + 1, parsed.path_index());
240 } 247 }
241 248
242 // Tolerate invalid URL. 249 // Tolerate invalid URL.
243 { 250 {
244 chrome::ParsedFallbackIconPath parsed; 251 chrome::ParsedFallbackIconPath parsed;
245 EXPECT_TRUE(parsed.Parse(specs + "/NOT A VALID URL")); 252 EXPECT_TRUE(parsed.Parse(specs + "/NOT A VALID URL"));
246 EXPECT_EQ(31, parsed.size_in_pixels()); 253 EXPECT_EQ(31, parsed.size_in_pixels());
247 const favicon_base::FallbackIconStyle& style = parsed.style(); 254 const favicon_base::FallbackIconStyle& style = parsed.style();
248 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); 255 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color);
256 EXPECT_FALSE(style.is_default_background_color);
249 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); 257 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color);
250 EXPECT_EQ(0.75, style.font_size_ratio); 258 EXPECT_EQ(0.75, style.font_size_ratio);
251 EXPECT_EQ(0.25, style.roundness); 259 EXPECT_EQ(0.25, style.roundness);
252 EXPECT_EQ("NOT A VALID URL", parsed.url_string()); 260 EXPECT_EQ("NOT A VALID URL", parsed.url_string());
253 EXPECT_EQ(specs.length() + 1, parsed.path_index()); 261 EXPECT_EQ(specs.length() + 1, parsed.path_index());
254 } 262 }
255 263
256 // Size and style are default. 264 // Size and style are default.
257 { 265 {
258 std::string specs2 = ",,,,"; 266 std::string specs2 = ",,,,";
259 chrome::ParsedFallbackIconPath parsed; 267 chrome::ParsedFallbackIconPath parsed;
260 EXPECT_TRUE(parsed.Parse(specs2 + "/" + kTestUrlStr)); 268 EXPECT_TRUE(parsed.Parse(specs2 + "/" + kTestUrlStr));
261 EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels()); 269 EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels());
262 const favicon_base::FallbackIconStyle& style = parsed.style(); 270 const favicon_base::FallbackIconStyle& style = parsed.style();
263 EXPECT_EQ(kDefaultBackgroundColor, style.background_color); 271 EXPECT_EQ(kDefaultBackgroundColor, style.background_color);
272 EXPECT_TRUE(style.is_default_background_color);
264 EXPECT_EQ(kDefaultTextColorLight, style.text_color); 273 EXPECT_EQ(kDefaultTextColorLight, style.text_color);
265 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio); 274 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio);
266 EXPECT_EQ(kDefaultRoundness, style.roundness); 275 EXPECT_EQ(kDefaultRoundness, style.roundness);
267 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string())); 276 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string()));
268 EXPECT_EQ(specs2.length() + 1, parsed.path_index()); 277 EXPECT_EQ(specs2.length() + 1, parsed.path_index());
269 } 278 }
270 } 279 }
271 280
272 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathFailure) { 281 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathFailure) {
273 const char* test_cases[] = { 282 const char* test_cases[] = {
274 // Bad size. 283 // Bad size.
275 "-1,000,fff,0.75,0.25/http://www.google.com/", 284 "-1,000,fff,0.75,0.25/http://www.google.com/",
276 // Bad specs. 285 // Bad specs.
277 "32,#junk,fff,0.75,0.25/http://www.google.com/", 286 "32,#junk,fff,0.75,0.25/http://www.google.com/",
278 }; 287 };
279 for (size_t i = 0; i < arraysize(test_cases); ++i) { 288 for (size_t i = 0; i < arraysize(test_cases); ++i) {
280 chrome::ParsedFallbackIconPath parsed; 289 chrome::ParsedFallbackIconPath parsed;
281 EXPECT_FALSE(parsed.Parse(test_cases[i])) << "test_cases[" << i << "]"; 290 EXPECT_FALSE(parsed.Parse(test_cases[i])) << "test_cases[" << i << "]";
282 } 291 }
283 } 292 }
284 293
285 } // namespace chrome 294 } // namespace chrome
OLDNEW
« no previous file with comments | « components/favicon_base/fallback_icon_url_parser.cc ('k') | ios/chrome/browser/favicon/large_icon_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698