OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/favicon_base/large_icon_url_parser.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "base/macros.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "url/gurl.h" | |
12 | |
13 namespace { | |
14 | |
15 const char kTestUrlStr[] = "https://www.google.ca/imghp?hl=en&tab=wi"; | |
16 | |
17 } // namespace | |
18 | |
19 TEST(LargeIconUrlParserTest, ParseLargeIconPathSuccess) { | |
20 // Everything populated. | |
21 { | |
22 LargeIconUrlParser parser; | |
23 EXPECT_TRUE(parser.Parse(std::string("48/") + kTestUrlStr)); | |
24 EXPECT_EQ(48, parser.size_in_pixels()); | |
25 EXPECT_EQ(GURL(kTestUrlStr), GURL(parser.url_string())); | |
26 EXPECT_EQ(3U, parser.path_index()); | |
27 } | |
28 | |
29 // Empty URL. | |
30 { | |
31 LargeIconUrlParser parser; | |
32 EXPECT_TRUE(parser.Parse("48/")); | |
33 EXPECT_EQ(48, parser.size_in_pixels()); | |
34 EXPECT_EQ(GURL(), GURL(parser.url_string())); | |
35 EXPECT_EQ(3U, parser.path_index()); | |
36 } | |
37 | |
38 // Tolerate invalid URL. | |
39 { | |
40 LargeIconUrlParser parser; | |
41 EXPECT_TRUE(parser.Parse("48/NOT A VALID URL")); | |
42 EXPECT_EQ(48, parser.size_in_pixels()); | |
43 EXPECT_EQ("NOT A VALID URL", parser.url_string()); | |
44 EXPECT_EQ(3U, parser.path_index()); | |
45 } | |
46 } | |
47 | |
48 TEST(LargeIconUrlParserTest, ParseLargeIconPathFailure) { | |
49 const char* const test_cases[] = { | |
50 "", | |
51 "/", | |
52 "//", | |
53 "48", // Missing '/'. | |
54 "/http://www.google.com/", // Missing size. | |
55 "not_a_number/http://www.google.com/", // Bad size. | |
56 "0/http://www.google.com/", // Non-positive size. | |
57 "-1/http://www.google.com/", // Non-positive size. | |
58 }; | |
59 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
60 LargeIconUrlParser parser; | |
61 EXPECT_FALSE(parser.Parse(test_cases[i])) << "test_cases[" << i << "]"; | |
62 } | |
63 } | |
OLD | NEW |