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

Side by Side Diff: net/base/mac/url_conversions_unittest.mm

Issue 773373002: Update from https://crrev.com/306706 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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/base/mac/url_conversions.mm ('k') | net/base/mime_util_unittest.cc » ('j') | 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 2012 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 #import <Foundation/Foundation.h>
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/sys_string_conversions.h"
9 #import "net/base/mac/url_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/gtest_mac.h"
12 #include "url/gurl.h"
13
14 namespace {
15
16 class URLConversionTest : public ::testing::Test {
17 protected:
18 virtual void SetUp() {
19 testData_.reset([[NSArray alloc]
20 initWithObjects:
21 // Simple URL with protocol
22 @"https://www.google.com/", @"https://www.google.com/",
23
24 // Simple URL with protocol and query string
25 @"https://www.google.com/search?q=gtest",
26 @"https://www.google.com/search?q=gtest",
27
28 // Simple URL with protocol and query string multiple params
29 @"https://www.google.com/search?hl=en&q=gtest",
30 @"https://www.google.com/search?hl=en&q=gtest",
31
32 // Simple URL with protocol and query string and fragment
33 @"https://www.google.com/search?q=gtest#123",
34 @"https://www.google.com/search?q=gtest#123",
35
36 // URL with ~
37 @"http://www.mysite.com/~user", @"http://www.mysite.com/~user",
38
39 // URL with #
40 @"http://www.mysite.com/#123456", @"http://www.mysite.com/#123456",
41
42 // URL with # before ?
43 @"http://www.mysite.com/test#test?test",
44 @"http://www.mysite.com/test#test?test",
45
46 // URL with ? before #
47 @"http://www.mysite.com/test?test#test",
48 @"http://www.mysite.com/test?test#test",
49
50 // URL with two #s
51 @"http://www.mysite.com/test#test#test",
52 @"http://www.mysite.com/test#test%23test",
53
54 // URL with two ?s
55 @"http://www.mysite.com/test?test?test",
56 @"http://www.mysite.com/test?test?test",
57
58 // URL with pattern ? # ?
59 @"http://www.mysite.com/test?test#test?test",
60 @"http://www.mysite.com/test?test#test?test",
61
62 // URL with pattern # ? #
63 @"http://www.mysite.com/test#test?test#test",
64 @"http://www.mysite.com/test#test?test%23test",
65
66 // URL with %
67 @"http://www.mysite.com/%123", @"http://www.mysite.com/%123",
68
69 // URL with [
70 @"http://www.mysite.com/[123", @"http://www.mysite.com/%5B123",
71
72 // URL with ]
73 @"http://www.mysite.com/]123", @"http://www.mysite.com/%5D123",
74
75 // URL with `
76 @"http://www.mysite.com/`123", @"http://www.mysite.com/%60123",
77
78 // URL with ^
79 @"http://www.mysite.com/^123", @"http://www.mysite.com/%5E123",
80
81 // URL with backslash (GURL canonicallizes unescaped \ to /)
82 @"http://www.mysite.com/\\123", @"http://www.mysite.com//123",
83
84 // URL with space
85 @"http://www.mysite.com/~user name",
86 @"http://www.mysite.com/~user%20name",
87
88 // URL with <
89 @"http://www.mysite.com/123<456",
90 @"http://www.mysite.com/123%3C456",
91
92 // URL with >
93 @"http://www.mysite.com/456>123",
94 @"http://www.mysite.com/456%3E123",
95
96 // URL with |
97 @"http://www.mysite.com/|123", @"http://www.mysite.com/%7C123",
98
99 // URL with !
100 @"http://www.mysite.com/!123", @"http://www.mysite.com/!123",
101
102 // URL with ~
103 @"http://www.mysite.com/~user", @"http://www.mysite.com/~user",
104
105 // URL with & (no ?)
106 @"http://www.mysite.com/&123", @"http://www.mysite.com/&123",
107
108 // URL with '
109 @"http://www.mysite.com/'user", @"http://www.mysite.com/'user",
110
111 // URL with "
112 @"http://www.mysite.com/\"user", @"http://www.mysite.com/%22user",
113
114 // URL with (
115 @"http://www.mysite.com/(123", @"http://www.mysite.com/(123",
116
117 // URL with )
118 @"http://www.mysite.com/)123", @"http://www.mysite.com/)123",
119
120 // URL with +
121 @"http://www.mysite.com/+123", @"http://www.mysite.com/+123",
122
123 // URL with *
124 @"http://www.mysite.com/*123", @"http://www.mysite.com/*123",
125
126 // URL with space
127 @"http://www.mysite.com/user name",
128 @"http://www.mysite.com/user%20name",
129
130 // URL with unescaped European accented characters
131 @"http://fr.news.yahoo.com/bactérie-e-coli-ajouter-vinaigre-leau-"
132 "rinçage-légumes-061425535.html",
133 @"http://fr.news.yahoo.com/bact%C3%A9rie-e-coli-ajouter-vinaigre-"
134 "leau-rin%C3%A7age-l%C3%A9gumes-061425535.html",
135
136 // URL with mix of unescaped European accented characters
137 @"http://fr.news.yahoo.com/bactérie-e-coli-ajouter-vinaigre-leau-"
138 "rinçage-l%C3%A9gumes-061425535.html",
139 @"http://fr.news.yahoo.com/bact%C3%A9rie-e-coli-ajouter-vinaigre-"
140 "leau-rin%C3%A7age-l%C3%A9gumes-061425535.html",
141
142 // URL with unescaped Asian unicode characters
143 @"http://www.baidu.com/s?cl=3&fr=tb01000&wd=鍜嬩箞鍠傞",
144 @"http://www.baidu.com/s?cl=3&fr=tb01000&wd="
145 "%E9%8D%9C%E5%AC%A9%E7%AE%9E%E9%8D%A0%E5%82%9E",
146
147 // URL containing every character in the range 20->7F
148 @"http://google.com/ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM"
149 "NOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
150 @"http://google.com/%20!%22#$%25&'()*+,-./0123456789:;%3C=%3E?@ABCD"
151 "EFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
152 "%7B%7C%7D~",
153
154 // URL containing every accented character from the range 80->FF
155 @"http://google.com/¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìí"
156 "îïðñòóôõö÷øùúûüýþÿ",
157 @"http://google.com/%C2%BF%C3%80%C3%81%C3%82%C3%83%C3%84%C3%85%C3"
158 "%86%C3%87%C3%88%C3%89%C3%8A%C3%8B%C3%8C%C3%8D%C3%8E%C3%8F%C3%90"
159 "%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3"
160 "%9B%C3%9C%C3%9D%C3%9E%C3%9F%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5"
161 "%C3%A6%C3%A7%C3%A8%C3%A9%C3%AA%C3%AB%C3%AC%C3%AD%C3%AE%C3%AF%C3"
162 "%B0%C3%B1%C3%B2%C3%B3%C3%B4%C3%B5%C3%B6%C3%B7%C3%B8%C3%B9%C3%BA"
163 "%C3%BB%C3%BC%C3%BD%C3%BE%C3%BF",
164
165 // URL containing every character in the range 20->7F repeated twice
166 @"http://google.com/ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM"
167 "NOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !\"#$%&'()*+,-"
168 "./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm"
169 "nopqrstuvwxyz{|}~",
170 @"http://google.com/%20!%22#$%25&'()*+,-./0123456789:;%3C=%3E?@ABCD"
171 "EFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
172 "%7B%7C%7D~%20!%22%23$%25&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJ"
173 "KLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C"
174 "%7D~",
175
176 // Special case 7F. the weird out of place control character for DEL
177 @"data:,\177", @"data:,%7F",
178
179 // URL with some common control characters.
180 // GURL simply removes most control characters.
181 @"data:,\a\b\t\r\n", @"data:,",
182
183 // All control characters but \000.
184 @"data:,\001\002\003\004\005\006\007\010\011\012\013\014\015\016"
185 "\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036"
186 "\037",
187 @"data:,",
188
189 // Square brackets shouldn't be escaped in IPv6 literal.
190 @"http://[::1]/path/", @"http://[::1]/path/",
191
192 // Test all possible features of a URL.
193 @"http://foobar:nicate@example.com:8080/some/path/"
194 "file.html;params-here?foo=bar#baz",
195 @"http://foobar:nicate@example.com:8080/some/path/"
196 "file.html;params-here?foo=bar#baz",
197
198 // Test a username and password that require escaping.
199 @"http://john!<]:bar[@foo.com/path",
200 @"http://john!%3C%5D:bar%5B@foo.com/path",
201
202 nil]);
203 }
204
205 // NSArray of NSString pairs used for running the tests.
206 // Each pair is in the form <input value, expected result>.
207 base::scoped_nsobject<NSArray> testData_;
208 };
209
210 TEST_F(URLConversionTest, TestNSURLCreationFromStrings) {
211 for (NSUInteger i = 0; i < [testData_ count]; i += 2) {
212 NSString* inputStr = [testData_ objectAtIndex:i];
213 NSString* expected = [testData_ objectAtIndex:(i + 1)];
214 NSURL* url = net::NSURLWithGURL(GURL(base::SysNSStringToUTF8(inputStr)));
215 EXPECT_NSEQ(expected, [url absoluteString]);
216 }
217 }
218
219 TEST_F(URLConversionTest, TestURLWithStringDoesNotModifyAlreadyEscapedURLs) {
220 for (NSUInteger i = 0; i < [testData_ count]; i += 2) {
221 NSString* inputStr = [testData_ objectAtIndex:i + 1];
222 NSURL* url = net::NSURLWithGURL(GURL(base::SysNSStringToUTF8(inputStr)));
223 NSString* expected = [testData_ objectAtIndex:i + 1];
224 // Test the expected URL is created.
225 EXPECT_NSEQ(expected, [url absoluteString]);
226 }
227 }
228
229 } // anonymous namespace
OLDNEW
« no previous file with comments | « net/base/mac/url_conversions.mm ('k') | net/base/mime_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698