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