summaryrefslogtreecommitdiffstats
path: root/components/favicon_base/large_icon_url_parser_unittest.cc
diff options
context:
space:
mode:
authorblundell <blundell@chromium.org>2015-07-08 03:07:45 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-08 10:08:22 +0000
commitee0ade20e42f6ff67ec7402c80610e3d0b7f960a (patch)
tree60056d8d047c4bf82f6bf31ce0ec8ca286ef268c /components/favicon_base/large_icon_url_parser_unittest.cc
parent0c714f7ca6d4f027501aa8ef8ae91ebc99788b62 (diff)
downloadchromium_src-ee0ade20e42f6ff67ec7402c80610e3d0b7f960a.zip
chromium_src-ee0ade20e42f6ff67ec7402c80610e3d0b7f960a.tar.gz
chromium_src-ee0ade20e42f6ff67ec7402c80610e3d0b7f960a.tar.bz2
Componentize //chrome/common/favicon
This code is used by iOS; move it into //components/favicon_base. TBR=sky, rdsmith Review URL: https://codereview.chromium.org/1223603002 Cr-Commit-Position: refs/heads/master@{#337794}
Diffstat (limited to 'components/favicon_base/large_icon_url_parser_unittest.cc')
-rw-r--r--components/favicon_base/large_icon_url_parser_unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/components/favicon_base/large_icon_url_parser_unittest.cc b/components/favicon_base/large_icon_url_parser_unittest.cc
new file mode 100644
index 0000000..e6f52ec
--- /dev/null
+++ b/components/favicon_base/large_icon_url_parser_unittest.cc
@@ -0,0 +1,61 @@
+// 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 "components/favicon_base/large_icon_url_parser.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace {
+
+const char kTestUrlStr[] = "https://www.google.ca/imghp?hl=en&tab=wi";
+
+} // namespace
+
+TEST(LargeIconUrlParserTest, ParseLargeIconPathSuccess) {
+ // Everything populated.
+ {
+ 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.
+ {
+ 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.
+ {
+ 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* const test_cases[] = {
+ "",
+ "/",
+ "//",
+ "48", // Missing '/'.
+ "/http://www.google.com/", // Missing size.
+ "not_a_number/http://www.google.com/", // Bad size.
+ "0/http://www.google.com/", // Non-positive size.
+ "-1/http://www.google.com/", // Non-positive size.
+ };
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ LargeIconUrlParser parser;
+ EXPECT_FALSE(parser.Parse(test_cases[i])) << "test_cases[" << i << "]";
+ }
+}