Cleanup: Pass std::string as const reference from pdf/
[chromium-blink-merge.git] / components / favicon_base / large_icon_url_parser_unittest.cc
blobe6f52ec61f68eb9eb9b8b059748d08c24da8d96b
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.
5 #include "components/favicon_base/large_icon_url_parser.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
11 namespace {
13 const char kTestUrlStr[] = "https://www.google.ca/imghp?hl=en&tab=wi";
15 } // namespace
17 TEST(LargeIconUrlParserTest, ParseLargeIconPathSuccess) {
18 // Everything populated.
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());
27 // Empty URL.
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());
36 // Tolerate invalid URL.
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());
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.
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 << "]";