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

Side by Side Diff: chrome/common/favicon/fallback_icon_url_parser_unittest.cc

Issue 1010783002: [Icons NTP] Working prototype to fetch, store, and display big icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks and unit test fix. Created 5 years, 9 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 "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
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 {
256 std::string specs2 = ",,,,";
240 chrome::ParsedFallbackIconPath parsed; 257 chrome::ParsedFallbackIconPath parsed;
241 EXPECT_TRUE(parsed.Parse(std::string(",,,,/") + kTestUrlStr)); 258 EXPECT_TRUE(parsed.Parse(specs2 + "/" + kTestUrlStr));
242 EXPECT_EQ(GURL(kTestUrlStr), parsed.url());
243 EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels()); 259 EXPECT_EQ(gfx::kFaviconSize, parsed.size_in_pixels());
244 const favicon_base::FallbackIconStyle& style = parsed.style(); 260 const favicon_base::FallbackIconStyle& style = parsed.style();
245 EXPECT_EQ(kDefaultBackgroundColor, style.background_color); 261 EXPECT_EQ(kDefaultBackgroundColor, style.background_color);
246 EXPECT_EQ(kDefaultTextColorLight, style.text_color); 262 EXPECT_EQ(kDefaultTextColorLight, style.text_color);
247 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio); 263 EXPECT_EQ(kDefaultFontSizeRatio, style.font_size_ratio);
248 EXPECT_EQ(kDefaultRoundness, style.roundness); 264 EXPECT_EQ(kDefaultRoundness, style.roundness);
265 EXPECT_EQ(GURL(kTestUrlStr), GURL(parsed.url_string()));
266 EXPECT_EQ(specs2.length() + 1, parsed.path_index());
249 } 267 }
250 } 268 }
251 269
252 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathFailure) { 270 TEST_F(FallbackIconUrlParserTest, ParseFallbackIconPathFailure) {
253 const char* test_cases[] = { 271 const char* test_cases[] = {
254 // Bad size. 272 // Bad size.
255 "-1,000,fff,0.75,0.25/http://www.google.com/", 273 "-1,000,fff,0.75,0.25/http://www.google.com/",
256 // Bad specs. 274 // Bad specs.
257 "32,#junk,fff,0.75,0.25/http://www.google.com/", 275 "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 }; 276 };
261 for (size_t i = 0; i < arraysize(test_cases); ++i) { 277 for (size_t i = 0; i < arraysize(test_cases); ++i) {
262 chrome::ParsedFallbackIconPath parsed; 278 chrome::ParsedFallbackIconPath parsed;
263 EXPECT_FALSE(parsed.Parse(test_cases[i])) << "test_cases[" << i << "]"; 279 EXPECT_FALSE(parsed.Parse(test_cases[i])) << "test_cases[" << i << "]";
264 } 280 }
265 } 281 }
266 282
267 } // namespace chrome 283 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/common/favicon/fallback_icon_url_parser.cc ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698