OLD | NEW |
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 "chrome/common/favicon/fallback_icon_url_parser.h" | 5 #include "chrome/common/favicon/fallback_icon_url_parser.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "components/favicon_base/fallback_icon_style.h" | 8 #include "components/favicon_base/fallback_icon_style.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathSuccess) { | 209 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathSuccess) { |
210 const std::string specs = "31,black,fff,0.75,0.25"; | 210 const std::string specs = "31,black,fff,0.75,0.25"; |
211 | 211 |
212 // Everything populated. | 212 // Everything populated. |
213 { | 213 { |
214 chrome::ParsedFallbackIconPath parsed; | 214 chrome::ParsedFallbackIconPath parsed; |
215 EXPECT_TRUE(parsed.Parse(specs + "/" + kTestUrlStr)); | 215 EXPECT_TRUE(parsed.Parse(specs + "/" + kTestUrlStr)); |
216 EXPECT_EQ(GURL(kTestUrlStr), parsed.url()); | |
217 EXPECT_EQ(31, parsed.size_in_pixels()); | 216 EXPECT_EQ(31, parsed.size_in_pixels()); |
218 const favicon_base::FallbackIconStyle& style = parsed.style(); | 217 const favicon_base::FallbackIconStyle& style = parsed.style(); |
219 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); | 218 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); |
220 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); | 219 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); |
221 EXPECT_EQ(0.75, style.font_size_ratio); | 220 EXPECT_EQ(0.75, style.font_size_ratio); |
222 EXPECT_EQ(0.25, style.roundness); | 221 EXPECT_EQ(0.25, style.roundness); |
| 222 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string())); |
| 223 EXPECT_EQ(specs.length() + 1, parsed.path_index()); |
223 } | 224 } |
224 | 225 |
225 // Empty URL. | 226 // Empty URL. |
226 { | 227 { |
227 chrome::ParsedFallbackIconPath parsed; | 228 chrome::ParsedFallbackIconPath parsed; |
228 EXPECT_TRUE(parsed.Parse(specs + "/")); | 229 EXPECT_TRUE(parsed.Parse(specs + "/")); |
229 EXPECT_EQ(GURL(), parsed.url()); | |
230 EXPECT_EQ(31, parsed.size_in_pixels()); | 230 EXPECT_EQ(31, parsed.size_in_pixels()); |
231 const favicon_base::FallbackIconStyle& style = parsed.style(); | 231 const favicon_base::FallbackIconStyle& style = parsed.style(); |
232 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); | 232 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); |
233 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); | 233 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); |
234 EXPECT_EQ(0.75, style.font_size_ratio); | 234 EXPECT_EQ(0.75, style.font_size_ratio); |
235 EXPECT_EQ(0.25, style.roundness); | 235 EXPECT_EQ(0.25, style.roundness); |
| 236 EXPECT_EQ(GURL(), GURL(parsed.url_string())); |
| 237 EXPECT_EQ(specs.length() + 1, parsed.path_index()); |
| 238 } |
| 239 |
| 240 // Tolerate invalid URL. |
| 241 { |
| 242 chrome::ParsedFallbackIconPath parsed; |
| 243 EXPECT_TRUE(parsed.Parse(specs + "/NOT A VALID URL")); |
| 244 EXPECT_EQ(31, parsed.size_in_pixels()); |
| 245 const favicon_base::FallbackIconStyle& style = parsed.style(); |
| 246 EXPECT_EQ(SkColorSetRGB(0x00, 0x00, 0x00), style.background_color); |
| 247 EXPECT_EQ(SkColorSetRGB(0xFF, 0xFF, 0xFF), style.text_color); |
| 248 EXPECT_EQ(0.75, style.font_size_ratio); |
| 249 EXPECT_EQ(0.25, style.roundness); |
| 250 EXPECT_EQ("NOT A VALID URL", parsed.url_string()); |
| 251 EXPECT_EQ(specs.length() + 1, parsed.path_index()); |
236 } | 252 } |
237 | 253 |
238 // Size and style are default. | 254 // Size and style are default. |
239 { | 255 { |
240 chrome::ParsedFallbackIconPath parsed; | 256 chrome::ParsedFallbackIconPath parsed; |
241 EXPECT_TRUE(parsed.Parse(std::string(",,,,/") + kTestUrlStr)); | 257 EXPECT_TRUE(parsed.Parse(std::string(",,,,/") + kTestUrlStr)); |
242 EXPECT_EQ(GURL(kTestUrlStr), parsed.url()); | |
243 EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels()); | 258 EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels()); |
244 const favicon_base::FallbackIconStyle& style = parsed.style(); | 259 const favicon_base::FallbackIconStyle& style = parsed.style(); |
245 EXPECT_EQ(kDefaultBackgroundColor, style.background_color); | 260 EXPECT_EQ(kDefaultBackgroundColor, style.background_color); |
246 EXPECT_EQ(kDefaultTextColorLight, style.text_color); | 261 EXPECT_EQ(kDefaultTextColorLight, style.text_color); |
247 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio); | 262 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio); |
248 EXPECT_EQ(kDefaultRoundness, style.roundness); | 263 EXPECT_EQ(kDefaultRoundness, style.roundness); |
| 264 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string())); |
| 265 EXPECT_EQ(specs.length() + 1, parsed.path_index()); |
249 } | 266 } |
250 } | 267 } |
251 | 268 |
252 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathFailure) { | 269 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathFailure) { |
253 const char* test_cases[] = { | 270 const char* test_cases[] = { |
254 // Bad size. | 271 // Bad size. |
255 "-1,000,fff,0.75,0.25/http://www.google.com/", | 272 "-1,000,fff,0.75,0.25/http://www.google.com/", |
256 // Bad specs. | 273 // Bad specs. |
257 "32,#junk,fff,0.75,0.25/http://www.google.com/", | 274 "32,#junk,fff,0.75,0.25/http://www.google.com/", |
258 // Bad URL. | |
259 "32,000,fff,0.75,0.25/NOT A VALID URL", | |
260 }; | 275 }; |
261 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 276 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
262 chrome::ParsedFallbackIconPath parsed; | 277 chrome::ParsedFallbackIconPath parsed; |
263 EXPECT_FALSE(parsed.Parse(test_cases[i])) << "test_cases[" << i << "]"; | 278 EXPECT_FALSE(parsed.Parse(test_cases[i])) << "test_cases[" << i << "]"; |
264 } | 279 } |
265 } | 280 } |
266 | 281 |
267 } // namespace chrome | 282 } // namespace chrome |
OLD | NEW |