Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9600)

Unified Diff: chrome/common/favicon/large_icon_url_parser_unittest.cc

Issue 1014853004: [Icons NTP] Add LargeIconUrlParser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use base::StringPiece; fix tests. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/favicon/large_icon_url_parser_unittest.cc
diff --git a/chrome/common/favicon/large_icon_url_parser_unittest.cc b/chrome/common/favicon/large_icon_url_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3ba8315069b1700faf41fdb8128950b934890885
--- /dev/null
+++ b/chrome/common/favicon/large_icon_url_parser_unittest.cc
@@ -0,0 +1,67 @@
+// 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/large_icon_url_parser.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+using chrome::LargeIconUrlParser;
+
+namespace chrome {
+
+namespace {
+
+const char kTestUrlStr[] = "https://www.google.ca/imghp?hl=en&tab=wi";
+
+} // namespace
+
+TEST(LargeIconUrlParserTest, ParseLargeIconPathSuccess) {
+
+ // Everything populated.
+ {
+ chrome::LargeIconUrlParser 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::LargeIconUrlParser 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::LargeIconUrlParser 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(LargeIconUrlParserTest, ParseLargeIconPathFailure) {
+ const char* test_cases[] = {
Lei Zhang 2015/03/18 19:00:45 const char* const
huangs 2015/03/18 20:18:04 Done.
+ // Missing size.
+ "/http://www.google.com/",
+ // Bad size.
+ "not_a_number/http://www.google.com/",
+ // Non-positive sizes.
+ "0/http://www.google.com/",
+ "-1/http://www.google.com/",
+ };
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ chrome::LargeIconUrlParser parser;
+ EXPECT_FALSE(parser.Parse(test_cases[i])) << "test_cases[" << i << "]";
+ }
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698