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

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

Powered by Google App Engine
This is Rietveld 408576698