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

Side by Side Diff: chrome/common/favicon/favicon_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: Refactor by extracting FallbackIconSpecsBuilder. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/favicon_url_parser.h" 5 #include "chrome/common/favicon/favicon_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_specs.h"
8 #include "components/favicon_base/favicon_types.h" 9 #include "components/favicon_base/favicon_types.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/layout.h" 11 #include "ui/base/layout.h"
11 12
13 using favicon_base::FallbackIconSpecs;
14
12 class FaviconUrlParserTest : public testing::Test { 15 class FaviconUrlParserTest : public testing::Test {
13 public: 16 public:
14 FaviconUrlParserTest() { 17 FaviconUrlParserTest() {
15 // Set the supported scale factors because the supported scale factors 18 // Set the supported scale factors because the supported scale factors
16 // affect the result of ParsePathAndScale(). 19 // affect the result of ParsePathAndScale().
17 std::vector<ui::ScaleFactor> supported_scale_factors; 20 std::vector<ui::ScaleFactor> supported_scale_factors;
18 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P); 21 supported_scale_factors.push_back(ui::SCALE_FACTOR_100P);
19 supported_scale_factors.push_back(ui::SCALE_FACTOR_140P); 22 supported_scale_factors.push_back(ui::SCALE_FACTOR_140P);
20 scoped_set_supported_scale_factors_.reset( 23 scoped_set_supported_scale_factors_.reset(
21 new ui::test::ScopedSetSupportedScaleFactors(supported_scale_factors)); 24 new ui::test::ScopedSetSupportedScaleFactors(supported_scale_factors));
(...skipping 14 matching lines...) Expand all
36 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); 39 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi");
37 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; 40 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON;
38 chrome::ParsedFaviconPath parsed; 41 chrome::ParsedFaviconPath parsed;
39 42
40 const std::string path1 = url; 43 const std::string path1 = url;
41 EXPECT_TRUE(chrome::ParseFaviconPath(path1, icon_types, &parsed)); 44 EXPECT_TRUE(chrome::ParseFaviconPath(path1, icon_types, &parsed));
42 EXPECT_FALSE(parsed.is_icon_url); 45 EXPECT_FALSE(parsed.is_icon_url);
43 EXPECT_EQ(url, parsed.url); 46 EXPECT_EQ(url, parsed.url);
44 EXPECT_EQ(16, parsed.size_in_dip); 47 EXPECT_EQ(16, parsed.size_in_dip);
45 EXPECT_EQ(1.0f, parsed.device_scale_factor); 48 EXPECT_EQ(1.0f, parsed.device_scale_factor);
49 EXPECT_FALSE(parsed.fallback_specs);
46 } 50 }
47 51
48 // Test parsing path with a 'size' parameter. 52 // Test parsing path with a 'size' parameter.
49 TEST_F(FaviconUrlParserTest, ParsingSizeParam) { 53 TEST_F(FaviconUrlParserTest, ParsingSizeParam) {
50 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); 54 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi");
51 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; 55 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON;
52 chrome::ParsedFaviconPath parsed; 56 chrome::ParsedFaviconPath parsed;
53 57
54 // Test that we can still parse the legacy 'size' parameter format. 58 // Test that we can still parse the legacy 'size' parameter format.
55 const std::string path2 = "size/32/" + url; 59 const std::string path2 = "size/32/" + url;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 EXPECT_EQ(32, parsed.size_in_dip); 160 EXPECT_EQ(32, parsed.size_in_dip);
157 EXPECT_EQ(1.4f, parsed.device_scale_factor); 161 EXPECT_EQ(1.4f, parsed.device_scale_factor);
158 162
159 const std::string path14 = 163 const std::string path14 =
160 "largest/iconurl/http://www.google.com/favicon.ico"; 164 "largest/iconurl/http://www.google.com/favicon.ico";
161 EXPECT_TRUE(chrome::ParseFaviconPath(path14, icon_types, &parsed)); 165 EXPECT_TRUE(chrome::ParseFaviconPath(path14, icon_types, &parsed));
162 EXPECT_TRUE(parsed.is_icon_url); 166 EXPECT_TRUE(parsed.is_icon_url);
163 EXPECT_EQ("http://www.google.com/favicon.ico", parsed.url); 167 EXPECT_EQ("http://www.google.com/favicon.ico", parsed.url);
164 EXPECT_EQ(0, parsed.size_in_dip); 168 EXPECT_EQ(0, parsed.size_in_dip);
165 } 169 }
170
171 // Test parsing path with a 'fallback' parameter.
172 TEST_F(FaviconUrlParserTest, ParsingFallbackParam) {
173 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi");
174 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON;
175 chrome::ParsedFaviconPath parsed;
176
177 // Empty is valid.
178 const std::string path15 = "fallback//" + url;
179 EXPECT_TRUE(chrome::ParseFaviconPath(path15, icon_types, &parsed));
180 EXPECT_TRUE(parsed.fallback_specs);
181 EXPECT_FALSE(parsed.fallback_specs->Has(FallbackIconSpecs::BACKGROUND_COLOR));
182 EXPECT_FALSE(parsed.fallback_specs->Has(FallbackIconSpecs::TEXT_COLOR));
183 EXPECT_FALSE(parsed.fallback_specs->Has(FallbackIconSpecs::FONT_SIZE_RATIO));
184 EXPECT_FALSE(parsed.fallback_specs->Has(
185 FallbackIconSpecs::CORNER_RADIUS_RATIO));
186
187 // Everything populated.
188 const std::string path16 = "fallback/abc,123456,0.5,0.1/" + url;
189 EXPECT_TRUE(chrome::ParseFaviconPath(path16, icon_types, &parsed));
190 EXPECT_TRUE(parsed.fallback_specs);
191 EXPECT_EQ(SkColorSetRGB(0xAA, 0xBB, 0xCC),
192 parsed.fallback_specs->BackgroundColor());
193 EXPECT_EQ(SkColorSetRGB(0x12, 0x34, 0x56),
194 parsed.fallback_specs->TextColor());
195 EXPECT_EQ(0.5, parsed.fallback_specs->FontSizeRatio());
196 EXPECT_EQ(0.1, parsed.fallback_specs->CornerRadiusRatio());
197
198 // Partially populated.
199 const std::string path17 = "fallback/123abc,,0.6/" + url;
200 EXPECT_TRUE(chrome::ParseFaviconPath(path17, icon_types, &parsed));
201 EXPECT_TRUE(parsed.fallback_specs);
202 EXPECT_EQ(SkColorSetRGB(0x12, 0x3A, 0xBC),
203 parsed.fallback_specs->BackgroundColor());
204 EXPECT_FALSE(parsed.fallback_specs->Has(FallbackIconSpecs::TEXT_COLOR));
205 EXPECT_EQ(0.6, parsed.fallback_specs->FontSizeRatio());
206 EXPECT_FALSE(parsed.fallback_specs->Has(
207 FallbackIconSpecs::CORNER_RADIUS_RATIO));
208
209 // Error: FontSizeRatio too large.
210 const std::string path18 = "fallback/fff,000,100/" + url;
211 EXPECT_FALSE(chrome::ParseFaviconPath(path18, icon_types, &parsed));
212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698