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

Side by Side Diff: net/tools/flip_server/url_utilities_unittest.cc

Issue 2169503002: Remove flip_server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « net/tools/flip_server/url_utilities.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "net/tools/flip_server/url_utilities.h"
6
7 #include <string>
8
9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace net {
14
15 TEST(UrlUtilitiesTest, GetUrlHost) {
16 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com"));
17 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com:80"));
18 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com:80/"));
19 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com/news"));
20 EXPECT_EQ("www.foo.com",
21 UrlUtilities::GetUrlHost("www.foo.com:80/news?q=hello"));
22 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("www.foo.com/news?q=a:b"));
23 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("www.foo.com:80"));
24 }
25
26 TEST(UrlUtilitiesTest, GetUrlHostPath) {
27 EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHostPath("http://www.foo.com"));
28 EXPECT_EQ("www.foo.com:80",
29 UrlUtilities::GetUrlHostPath("http://www.foo.com:80"));
30 EXPECT_EQ("www.foo.com:80/",
31 UrlUtilities::GetUrlHostPath("http://www.foo.com:80/"));
32 EXPECT_EQ("www.foo.com/news",
33 UrlUtilities::GetUrlHostPath("http://www.foo.com/news"));
34 EXPECT_EQ("www.foo.com:80/news?q=hello",
35 UrlUtilities::GetUrlHostPath("www.foo.com:80/news?q=hello"));
36 EXPECT_EQ("www.foo.com/news?q=a:b",
37 UrlUtilities::GetUrlHostPath("www.foo.com/news?q=a:b"));
38 EXPECT_EQ("www.foo.com:80", UrlUtilities::GetUrlHostPath("www.foo.com:80"));
39 }
40
41 TEST(UrlUtilitiesTest, GetUrlPath) {
42 EXPECT_EQ("/", UrlUtilities::GetUrlPath("http://www.foo.com"));
43 EXPECT_EQ("/", UrlUtilities::GetUrlPath("http://www.foo.com:80"));
44 EXPECT_EQ("/", UrlUtilities::GetUrlPath("http://www.foo.com:80/"));
45 EXPECT_EQ("/news", UrlUtilities::GetUrlPath("http://www.foo.com/news"));
46 EXPECT_EQ("/news?q=hello",
47 UrlUtilities::GetUrlPath("www.foo.com:80/news?q=hello"));
48 EXPECT_EQ("/news?q=a:b", UrlUtilities::GetUrlPath("www.foo.com/news?q=a:b"));
49 EXPECT_EQ("/", UrlUtilities::GetUrlPath("www.foo.com:80"));
50 }
51
52 TEST(UrlUtilitiesTest, Unescape) {
53 // Basic examples are left alone.
54 EXPECT_EQ("http://www.foo.com", UrlUtilities::Unescape("http://www.foo.com"));
55 EXPECT_EQ("www.foo.com:80/news?q=hello",
56 UrlUtilities::Unescape("www.foo.com:80/news?q=hello"));
57
58 // All chars can be unescaped.
59 EXPECT_EQ("~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",
60 UrlUtilities::Unescape("%7E%60%21%40%23%24%25%5E%26%2A%28%29%5F%2D"
61 "%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22%27%3C%2C"
62 "%3E%2E%3F%2F"));
63 for (int c = 0; c < 256; ++c) {
64 std::string unescaped_char(1, static_cast<unsigned char>(c));
65 std::string escaped_char = base::StringPrintf("%%%02X", c);
66 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char))
67 << "escaped_char = " << escaped_char;
68 escaped_char = base::StringPrintf("%%%02x", c);
69 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char))
70 << "escaped_char = " << escaped_char;
71 }
72
73 // All non-% chars are left alone.
74 EXPECT_EQ("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/",
75 UrlUtilities::Unescape("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/"));
76 for (int c = 0; c < 256; ++c) {
77 if (c != '%') {
78 std::string just_char(1, static_cast<unsigned char>(c));
79 EXPECT_EQ(just_char, UrlUtilities::Unescape(just_char));
80 }
81 }
82
83 // Some examples to unescape.
84 EXPECT_EQ("Hello, world!", UrlUtilities::Unescape("Hello%2C world%21"));
85
86 // Not actually escapes.
87 EXPECT_EQ("%", UrlUtilities::Unescape("%"));
88 EXPECT_EQ("%www", UrlUtilities::Unescape("%www"));
89 EXPECT_EQ("%foo", UrlUtilities::Unescape("%foo"));
90 EXPECT_EQ("%1", UrlUtilities::Unescape("%1"));
91 EXPECT_EQ("%1x", UrlUtilities::Unescape("%1x"));
92 EXPECT_EQ("%%", UrlUtilities::Unescape("%%"));
93 // Escapes following non-escapes.
94 EXPECT_EQ("%!", UrlUtilities::Unescape("%%21"));
95 EXPECT_EQ("%2!", UrlUtilities::Unescape("%2%21"));
96 }
97
98 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/flip_server/url_utilities.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698