| OLD | NEW |
| 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/favicon_types.h" | 8 #include "components/favicon_base/favicon_types.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/base/layout.h" | 10 #include "ui/base/layout.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); | 51 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); |
| 52 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; | 52 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; |
| 53 chrome::ParsedFaviconPath parsed; | 53 chrome::ParsedFaviconPath parsed; |
| 54 | 54 |
| 55 // Test that we can still parse the legacy 'size' parameter format. | 55 // Test that we can still parse the legacy 'size' parameter format. |
| 56 const std::string path2 = "size/32/" + url; | 56 const std::string path2 = "size/32/" + url; |
| 57 EXPECT_TRUE(chrome::ParseFaviconPath(path2, icon_types, &parsed)); | 57 EXPECT_TRUE(chrome::ParseFaviconPath(path2, icon_types, &parsed)); |
| 58 EXPECT_FALSE(parsed.is_icon_url); | 58 EXPECT_FALSE(parsed.is_icon_url); |
| 59 EXPECT_EQ(url, parsed.url); | 59 EXPECT_EQ(url, parsed.url); |
| 60 EXPECT_EQ(32, parsed.size_in_dip); | 60 EXPECT_EQ(32, parsed.size_in_dip); |
| 61 EXPECT_EQ(ui::SCALE_FACTOR_100P, parsed.scale_factor); | 61 EXPECT_EQ(1.0f, parsed.scale_factor); |
| 62 | 62 |
| 63 // Test parsing current 'size' parameter format. | 63 // Test parsing current 'size' parameter format. |
| 64 const std::string path3 = "size/32@1.4x/" + url; | 64 const std::string path3 = "size/32@1.4x/" + url; |
| 65 EXPECT_TRUE(chrome::ParseFaviconPath(path3, icon_types, &parsed)); | 65 EXPECT_TRUE(chrome::ParseFaviconPath(path3, icon_types, &parsed)); |
| 66 EXPECT_FALSE(parsed.is_icon_url); | 66 EXPECT_FALSE(parsed.is_icon_url); |
| 67 EXPECT_EQ(url, parsed.url); | 67 EXPECT_EQ(url, parsed.url); |
| 68 EXPECT_EQ(32, parsed.size_in_dip); | 68 EXPECT_EQ(32, parsed.size_in_dip); |
| 69 EXPECT_EQ(ui::SCALE_FACTOR_140P, parsed.scale_factor); | 69 EXPECT_EQ(1.4f, parsed.scale_factor); |
| 70 | 70 |
| 71 // Test that we pick the ui::ScaleFactor which is closest to the passed in | 71 // Test that we pick the ui::ScaleFactor which is closest to the passed in |
| 72 // scale factor. | 72 // scale factor. |
| 73 const std::string path4 = "size/16@1.41x/" + url; | 73 const std::string path4 = "size/16@1.41x/" + url; |
| 74 EXPECT_TRUE(chrome::ParseFaviconPath(path4, icon_types, &parsed)); | 74 EXPECT_TRUE(chrome::ParseFaviconPath(path4, icon_types, &parsed)); |
| 75 EXPECT_FALSE(parsed.is_icon_url); | 75 EXPECT_FALSE(parsed.is_icon_url); |
| 76 EXPECT_EQ(url, parsed.url); | 76 EXPECT_EQ(url, parsed.url); |
| 77 EXPECT_EQ(16, parsed.size_in_dip); | 77 EXPECT_EQ(16, parsed.size_in_dip); |
| 78 EXPECT_EQ(ui::SCALE_FACTOR_140P, parsed.scale_factor); | 78 EXPECT_EQ(1.41f, parsed.scale_factor); |
| 79 | 79 |
| 80 // Invalid cases. | 80 // Invalid cases. |
| 81 const std::string path5 = "size/" + url; | 81 const std::string path5 = "size/" + url; |
| 82 EXPECT_FALSE(chrome::ParseFaviconPath(path5, icon_types, &parsed)); | 82 EXPECT_FALSE(chrome::ParseFaviconPath(path5, icon_types, &parsed)); |
| 83 const std::string path6 = "size/@1x/" + url; | 83 const std::string path6 = "size/@1x/" + url; |
| 84 EXPECT_FALSE(chrome::ParseFaviconPath(path6, icon_types, &parsed)); | 84 EXPECT_FALSE(chrome::ParseFaviconPath(path6, icon_types, &parsed)); |
| 85 const std::string path7 = "size/abc@1x/" + url; | 85 const std::string path7 = "size/abc@1x/" + url; |
| 86 EXPECT_FALSE(chrome::ParseFaviconPath(path7, icon_types, &parsed)); | 86 EXPECT_FALSE(chrome::ParseFaviconPath(path7, icon_types, &parsed)); |
| 87 | 87 |
| 88 // Part of url looks like 'size' parameter. | 88 // Part of url looks like 'size' parameter. |
| 89 const std::string path8 = "http://www.google.com/size/32@1.4x"; | 89 const std::string path8 = "http://www.google.com/size/32@1.4x"; |
| 90 EXPECT_TRUE(chrome::ParseFaviconPath(path8, icon_types, &parsed)); | 90 EXPECT_TRUE(chrome::ParseFaviconPath(path8, icon_types, &parsed)); |
| 91 EXPECT_FALSE(parsed.is_icon_url); | 91 EXPECT_FALSE(parsed.is_icon_url); |
| 92 EXPECT_EQ(path8, parsed.url); | 92 EXPECT_EQ(path8, parsed.url); |
| 93 EXPECT_EQ(16, parsed.size_in_dip); | 93 EXPECT_EQ(16, parsed.size_in_dip); |
| 94 EXPECT_EQ(ui::SCALE_FACTOR_100P, parsed.scale_factor); | 94 EXPECT_EQ(1.0f, parsed.scale_factor); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Test parsing path with the 'largest' parameter. | 97 // Test parsing path with the 'largest' parameter. |
| 98 TEST_F(FaviconUrlParserTest, ParsingLargestParam) { | 98 TEST_F(FaviconUrlParserTest, ParsingLargestParam) { |
| 99 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); | 99 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); |
| 100 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; | 100 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; |
| 101 chrome::ParsedFaviconPath parsed; | 101 chrome::ParsedFaviconPath parsed; |
| 102 | 102 |
| 103 const std::string path9 = "largest/" + url; | 103 const std::string path9 = "largest/" + url; |
| 104 EXPECT_TRUE(chrome::ParseFaviconPath(path9, icon_types, &parsed)); | 104 EXPECT_TRUE(chrome::ParseFaviconPath(path9, icon_types, &parsed)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 TEST_F(FaviconUrlParserTest, ParsingSizeParamAndUrlModifier) { | 148 TEST_F(FaviconUrlParserTest, ParsingSizeParamAndUrlModifier) { |
| 149 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); | 149 const std::string url("https://www.google.ca/imghp?hl=en&tab=wi"); |
| 150 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; | 150 int icon_types = favicon_base::TOUCH_PRECOMPOSED_ICON; |
| 151 chrome::ParsedFaviconPath parsed; | 151 chrome::ParsedFaviconPath parsed; |
| 152 | 152 |
| 153 const std::string path13 = "size/32@1.4x/origin/" + url; | 153 const std::string path13 = "size/32@1.4x/origin/" + url; |
| 154 EXPECT_TRUE(chrome::ParseFaviconPath(path13, icon_types, &parsed)); | 154 EXPECT_TRUE(chrome::ParseFaviconPath(path13, icon_types, &parsed)); |
| 155 EXPECT_FALSE(parsed.is_icon_url); | 155 EXPECT_FALSE(parsed.is_icon_url); |
| 156 EXPECT_EQ("https://www.google.ca/", parsed.url); | 156 EXPECT_EQ("https://www.google.ca/", parsed.url); |
| 157 EXPECT_EQ(32, parsed.size_in_dip); | 157 EXPECT_EQ(32, parsed.size_in_dip); |
| 158 EXPECT_EQ(ui::SCALE_FACTOR_140P, parsed.scale_factor); | 158 EXPECT_EQ(1.4f, parsed.scale_factor); |
| 159 | 159 |
| 160 const std::string path14 = | 160 const std::string path14 = |
| 161 "largest/iconurl/http://www.google.com/favicon.ico"; | 161 "largest/iconurl/http://www.google.com/favicon.ico"; |
| 162 EXPECT_TRUE(chrome::ParseFaviconPath(path14, icon_types, &parsed)); | 162 EXPECT_TRUE(chrome::ParseFaviconPath(path14, icon_types, &parsed)); |
| 163 EXPECT_TRUE(parsed.is_icon_url); | 163 EXPECT_TRUE(parsed.is_icon_url); |
| 164 EXPECT_EQ("http://www.google.com/favicon.ico", parsed.url); | 164 EXPECT_EQ("http://www.google.com/favicon.ico", parsed.url); |
| 165 EXPECT_EQ(0, parsed.size_in_dip); | 165 EXPECT_EQ(0, parsed.size_in_dip); |
| 166 } | 166 } |
| OLD | NEW |