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