Index: chrome/common/favicon/big_icon_url_parser_unittest.cc |
diff --git a/chrome/common/favicon/big_icon_url_parser_unittest.cc b/chrome/common/favicon/big_icon_url_parser_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9fb37a5d15e7653407cc4c50e0657a57c886d818 |
--- /dev/null |
+++ b/chrome/common/favicon/big_icon_url_parser_unittest.cc |
@@ -0,0 +1,64 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/common/favicon/big_icon_url_parser.h" |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
+ |
+using chrome::BigIconUrlParser; |
+ |
+namespace chrome { |
+ |
+namespace { |
+ |
+const char kTestUrlStr[] = "https://www.google.ca/imghp?hl=en&tab=wi"; |
+ |
+} // namespace |
+ |
+TEST(BigIconUrlParserTest, ParseBigIconPathSuccess) { |
+ |
+ // Everything populated. |
+ { |
+ chrome::BigIconUrlParser parser; |
+ EXPECT_TRUE(parser.Parse(std::string("48/") + kTestUrlStr)); |
+ EXPECT_EQ(48, parser.size_in_pixels()); |
+ EXPECT_EQ(GURL(kTestUrlStr), GURL(parser.url_string())); |
+ EXPECT_EQ(3U, parser.path_index()); |
+ } |
+ |
+ // Empty URL. |
+ { |
+ chrome::BigIconUrlParser parser; |
+ EXPECT_TRUE(parser.Parse("48/")); |
+ EXPECT_EQ(48, parser.size_in_pixels()); |
+ EXPECT_EQ(GURL(), GURL(parser.url_string())); |
+ EXPECT_EQ(3U, parser.path_index()); |
+ } |
+ |
+ // Tolerate invalid URL. |
+ { |
+ chrome::BigIconUrlParser parser; |
+ EXPECT_TRUE(parser.Parse("48/NOT A VALID URL")); |
+ EXPECT_EQ(48, parser.size_in_pixels()); |
+ EXPECT_EQ("NOT A VALID URL", parser.url_string()); |
+ EXPECT_EQ(3U, parser.path_index()); |
+ } |
+} |
+ |
+TEST(BigIconUrlParserTest, ParseBigIconPathFailure) { |
+ const char* test_cases[] = { |
+ // Missing size. |
+ "/http://www.google.com/", |
+ // Bad size. |
+ "-1/http://www.google.com/", |
+ }; |
+ for (size_t i = 0; i < arraysize(test_cases); ++i) { |
+ chrome::BigIconUrlParser parser; |
+ EXPECT_FALSE(parser.Parse(test_cases[i])) << "test_cases[" << i << "]"; |
+ } |
+} |
+ |
+} // namespace chrome |