OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return ai; | 109 return ai; |
110 } | 110 } |
111 | 111 |
112 } // anonymous namespace | 112 } // anonymous namespace |
113 | 113 |
114 TEST(NetUtilTest, FileURLConversion) { | 114 TEST(NetUtilTest, FileURLConversion) { |
115 // a list of test file names and the corresponding URLs | 115 // a list of test file names and the corresponding URLs |
116 const FileCase round_trip_cases[] = { | 116 const FileCase round_trip_cases[] = { |
117 #if defined(OS_WIN) | 117 #if defined(OS_WIN) |
118 {L"C:\\foo\\bar.txt", L"file:///C:/foo/bar.txt"}, | 118 {L"C:\\foo\\bar.txt", L"file:///C:/foo/bar.txt"}, |
119 {L"\\\\some computer\\foo\\bar.txt", L"file://some%20computer/foo/bar.txt"},
// UNC | 119 {L"\\\\some computer\\foo\\bar.txt", |
120 {L"D:\\Name;with%some symbols*#", L"file:///D:/Name%3Bwith%25some%20symbols*
%23"}, | 120 L"file://some%20computer/foo/bar.txt"}, // UNC |
121 {L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", L"file:///D:/Chin
ese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91%E9%A1%B5.doc"}, | 121 {L"D:\\Name;with%some symbols*#", |
| 122 L"file:///D:/Name%3Bwith%25some%20symbols*%23"}, |
| 123 {L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", |
| 124 L"file:///D:/Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91" |
| 125 L"%E9%A1%B5.doc"}, |
122 #elif defined(OS_POSIX) | 126 #elif defined(OS_POSIX) |
123 {L"/foo/bar.txt", L"file:///foo/bar.txt"}, | 127 {L"/foo/bar.txt", L"file:///foo/bar.txt"}, |
124 {L"/foo/BAR.txt", L"file:///foo/BAR.txt"}, | 128 {L"/foo/BAR.txt", L"file:///foo/BAR.txt"}, |
125 {L"/C:/foo/bar.txt", L"file:///C:/foo/bar.txt"}, | 129 {L"/C:/foo/bar.txt", L"file:///C:/foo/bar.txt"}, |
126 {L"/some computer/foo/bar.txt", L"file:///some%20computer/foo/bar.txt"}, | 130 {L"/some computer/foo/bar.txt", L"file:///some%20computer/foo/bar.txt"}, |
127 {L"/Name;with%some symbols*#", L"file:///Name%3Bwith%25some%20symbols*%23"}, | 131 {L"/Name;with%some symbols*#", L"file:///Name%3Bwith%25some%20symbols*%23"}, |
128 {L"/Chinese/\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", L"file:///Chinese/%E6
%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91%E9%A1%B5.doc"}, | 132 {L"/Chinese/\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", |
| 133 L"file:///Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD" |
| 134 L"%91%E9%A1%B5.doc"}, |
129 #endif | 135 #endif |
130 }; | 136 }; |
131 | 137 |
132 // First, we'll test that we can round-trip all of the above cases of URLs | 138 // First, we'll test that we can round-trip all of the above cases of URLs |
133 std::wstring output; | 139 std::wstring output; |
134 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(round_trip_cases); i++) { | 140 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(round_trip_cases); i++) { |
135 // convert to the file URL | 141 // convert to the file URL |
136 GURL file_url(net::FilePathToFileURL(round_trip_cases[i].file)); | 142 GURL file_url(net::FilePathToFileURL(round_trip_cases[i].file)); |
137 EXPECT_EQ(std::wstring(round_trip_cases[i].url), | 143 EXPECT_EQ(std::wstring(round_trip_cases[i].url), |
138 UTF8ToWide(file_url.spec())); | 144 UTF8ToWide(file_url.spec())); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 #endif | 183 #endif |
178 }; | 184 }; |
179 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_cases); i++) { | 185 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_cases); i++) { |
180 net::FileURLToFilePath(GURL(WideToUTF8(url_cases[i].url)), &output); | 186 net::FileURLToFilePath(GURL(WideToUTF8(url_cases[i].url)), &output); |
181 EXPECT_EQ(std::wstring(url_cases[i].file), output); | 187 EXPECT_EQ(std::wstring(url_cases[i].file), output); |
182 } | 188 } |
183 | 189 |
184 // Here, we test that UTF-8 encoded strings get decoded properly, even when | 190 // Here, we test that UTF-8 encoded strings get decoded properly, even when |
185 // they might be stored with wide characters. On posix systems, just treat | 191 // they might be stored with wide characters. On posix systems, just treat |
186 // this as a stream of bytes. | 192 // this as a stream of bytes. |
187 const wchar_t utf8[] = L"file:///d:/Chinese/\xe6\x89\x80\xe6\x9c\x89\xe4\xb8\x
ad\xe6\x96\x87\xe7\xbd\x91\xe9\xa1\xb5.doc"; | 193 const wchar_t utf8[] = L"file:///d:/Chinese/\xe6\x89\x80\xe6\x9c\x89\xe4\xb8" |
| 194 L"\xad\xe6\x96\x87\xe7\xbd\x91\xe9\xa1\xb5.doc"; |
188 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
189 const wchar_t wide[] = L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc
"; | 196 const wchar_t wide[] = |
| 197 L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc"; |
190 #elif defined(OS_POSIX) | 198 #elif defined(OS_POSIX) |
191 const wchar_t wide[] = L"/d:/Chinese/\xe6\x89\x80\xe6\x9c\x89\xe4\xb8\xad\xe6\
x96\x87\xe7\xbd\x91\xe9\xa1\xb5.doc"; | 199 const wchar_t wide[] = L"/d:/Chinese/\xe6\x89\x80\xe6\x9c\x89\xe4\xb8\xad\xe6" |
| 200 L"\x96\x87\xe7\xbd\x91\xe9\xa1\xb5.doc"; |
192 #endif | 201 #endif |
193 EXPECT_TRUE(net::FileURLToFilePath(GURL(WideToUTF8(utf8)), &output)); | 202 EXPECT_TRUE(net::FileURLToFilePath(GURL(WideToUTF8(utf8)), &output)); |
194 EXPECT_EQ(std::wstring(wide), output); | 203 EXPECT_EQ(std::wstring(wide), output); |
195 | 204 |
196 // Unfortunately, UTF8ToWide discards invalid UTF8 input. | 205 // Unfortunately, UTF8ToWide discards invalid UTF8 input. |
197 #ifdef BUG_878908_IS_FIXED | 206 #ifdef BUG_878908_IS_FIXED |
198 // Test that no conversion happens if the UTF-8 input is invalid, and that | 207 // Test that no conversion happens if the UTF-8 input is invalid, and that |
199 // the input is preserved in UTF-8 | 208 // the input is preserved in UTF-8 |
200 const char invalid_utf8[] = "file:///d:/Blah/\xff.doc"; | 209 const char invalid_utf8[] = "file:///d:/Blah/\xff.doc"; |
201 const wchar_t invalid_wide[] = L"D:\\Blah\\\xff.doc"; | 210 const wchar_t invalid_wide[] = L"D:\\Blah\\\xff.doc"; |
(...skipping 11 matching lines...) Expand all Loading... |
213 L"HTTP/1.1 200 OK\n" | 222 L"HTTP/1.1 200 OK\n" |
214 L"Content-TYPE: text/html; charset=utf-8\n" | 223 L"Content-TYPE: text/html; charset=utf-8\n" |
215 L"Content-disposition: attachment; filename=\"download.pdf\"\n" | 224 L"Content-disposition: attachment; filename=\"download.pdf\"\n" |
216 L"Content-Length: 378557\n" | 225 L"Content-Length: 378557\n" |
217 L"X-Google-Google1: 314159265\n" | 226 L"X-Google-Google1: 314159265\n" |
218 L"X-Google-Google2: aaaa2:7783,bbb21:9441\n" | 227 L"X-Google-Google2: aaaa2:7783,bbb21:9441\n" |
219 L"X-Google-Google4: home\n" | 228 L"X-Google-Google4: home\n" |
220 L"Transfer-Encoding: chunked\n" | 229 L"Transfer-Encoding: chunked\n" |
221 L"Set-Cookie: HEHE_AT=6666x66beef666x6-66xx6666x66; Path=/mail\n" | 230 L"Set-Cookie: HEHE_AT=6666x66beef666x6-66xx6666x66; Path=/mail\n" |
222 L"Set-Cookie: HEHE_HELP=owned:0;Path=/\n" | 231 L"Set-Cookie: HEHE_HELP=owned:0;Path=/\n" |
223 L"Set-Cookie: S=gmail=Xxx-beefbeefbeef_beefb:gmail_yj=beefbeef000beefbeefbee
:gmproxy=bee-fbeefbe; Domain=.google.com; Path=/\n" | 232 L"Set-Cookie: S=gmail=Xxx-beefbeefbeef_beefb:gmail_yj=beefbeef000beefbee" |
| 233 L"fbee:gmproxy=bee-fbeefbe; Domain=.google.com; Path=/\n" |
224 L"X-Google-Google2: /one/two/three/four/five/six/seven-height/nine:9411\n" | 234 L"X-Google-Google2: /one/two/three/four/five/six/seven-height/nine:9411\n" |
225 L"Server: GFE/1.3\n" | 235 L"Server: GFE/1.3\n" |
226 L"Transfer-Encoding: chunked\n" | 236 L"Transfer-Encoding: chunked\n" |
227 L"Date: Mon, 13 Nov 2006 21:38:09 GMT\n" | 237 L"Date: Mon, 13 Nov 2006 21:38:09 GMT\n" |
228 L"Expires: Tue, 14 Nov 2006 19:23:58 GMT\n" | 238 L"Expires: Tue, 14 Nov 2006 19:23:58 GMT\n" |
229 L"X-Malformed: bla; arg=test\"\n" | 239 L"X-Malformed: bla; arg=test\"\n" |
230 L"X-Malformed2: bla; arg=\n" | 240 L"X-Malformed2: bla; arg=\n" |
231 L"X-Test: bla; arg1=val1; arg2=val2"; | 241 L"X-Test: bla; arg1=val1; arg2=val2"; |
232 | 242 |
233 TEST(NetUtilTest, GetSpecificHeader) { | 243 TEST(NetUtilTest, GetSpecificHeader) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 {"content-disposition: attachment; filename=abc,de.pdf", L"abc,de.pdf"}, | 306 {"content-disposition: attachment; filename=abc,de.pdf", L"abc,de.pdf"}, |
297 {"content-disposition: filename=abcde.pdf", L"abcde.pdf"}, | 307 {"content-disposition: filename=abcde.pdf", L"abcde.pdf"}, |
298 {"content-disposition: filename= abcde.pdf", L"abcde.pdf"}, | 308 {"content-disposition: filename= abcde.pdf", L"abcde.pdf"}, |
299 {"content-disposition: filename =abcde.pdf", L"abcde.pdf"}, | 309 {"content-disposition: filename =abcde.pdf", L"abcde.pdf"}, |
300 {"content-disposition: filename = abcde.pdf", L"abcde.pdf"}, | 310 {"content-disposition: filename = abcde.pdf", L"abcde.pdf"}, |
301 {"content-disposition: filename\t=abcde.pdf", L"abcde.pdf"}, | 311 {"content-disposition: filename\t=abcde.pdf", L"abcde.pdf"}, |
302 {"content-disposition: filename \t\t =abcde.pdf", L"abcde.pdf"}, | 312 {"content-disposition: filename \t\t =abcde.pdf", L"abcde.pdf"}, |
303 {"content-disposition: name=abcde.pdf", L"abcde.pdf"}, | 313 {"content-disposition: name=abcde.pdf", L"abcde.pdf"}, |
304 {"content-disposition: inline; filename=\"abc%20de.pdf\"", L"abc de.pdf"}, | 314 {"content-disposition: inline; filename=\"abc%20de.pdf\"", L"abc de.pdf"}, |
305 // Whitespaces are converted to a space. | 315 // Whitespaces are converted to a space. |
306 {"content-disposition: inline; filename=\"abc \t\nde.pdf\"", L"abc de.pd
f"}, | 316 {"content-disposition: inline; filename=\"abc \t\nde.pdf\"", |
| 317 L"abc de.pdf"}, |
307 // %-escaped UTF-8 | 318 // %-escaped UTF-8 |
308 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" | 319 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" |
309 "%EC%98%88%EC%88%A0.jpg\"", L"\xc608\xc220 \xc608\xc220.jpg"}, | 320 "%EC%98%88%EC%88%A0.jpg\"", L"\xc608\xc220 \xc608\xc220.jpg"}, |
310 {"Content-Disposition: attachment; filename=\"%F0%90%8C%B0%F0%90%8C%B1" | 321 {"Content-Disposition: attachment; filename=\"%F0%90%8C%B0%F0%90%8C%B1" |
311 "abc.jpg\"", L"\U00010330\U00010331abc.jpg"}, | 322 "abc.jpg\"", L"\U00010330\U00010331abc.jpg"}, |
312 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0 \n" | 323 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0 \n" |
313 "%EC%98%88%EC%88%A0.jpg\"", L"\xc608\xc220 \xc608\xc220.jpg"}, | 324 "%EC%98%88%EC%88%A0.jpg\"", L"\xc608\xc220 \xc608\xc220.jpg"}, |
314 // RFC 2047 with various charsets and Q/B encodings | 325 // RFC 2047 with various charsets and Q/B encodings |
315 {"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" | 326 {"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" |
316 "D13=2Epng?=\"", L"\x82b8\x8853" L"3.png"}, | 327 "D13=2Epng?=\"", L"\x82b8\x8853" L"3.png"}, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 false, false, false, false, false, | 587 false, false, false, false, false, |
577 false}}, | 588 false}}, |
578 // <Greek rho><Cyrillic a><Cyrillic u>.ru | 589 // <Greek rho><Cyrillic a><Cyrillic u>.ru |
579 {"xn--2xa6t2b.ru", L"\x03c1\x0430\x0443.ru", | 590 {"xn--2xa6t2b.ru", L"\x03c1\x0430\x0443.ru", |
580 {false, false, false, false, false, | 591 {false, false, false, false, false, |
581 false, false, false, false, false, | 592 false, false, false, false, false, |
582 false, false, false, false, false, | 593 false, false, false, false, false, |
583 false, false, false, false, false, | 594 false, false, false, false, false, |
584 false}}, | 595 false}}, |
585 // One that's really long that will force a buffer realloc | 596 // One that's really long that will force a buffer realloc |
586 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaa", | 597 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
587 L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaa", | 598 "aaaaaaa", |
| 599 L"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
| 600 L"aaaaaaaa", |
588 {true, true, true, true, true, | 601 {true, true, true, true, true, |
589 true, true, true, true, true, | 602 true, true, true, true, true, |
590 true, true, true, true, true, | 603 true, true, true, true, true, |
591 true, true, true, true, true, | 604 true, true, true, true, true, |
592 true}}, | 605 true}}, |
593 // Test cases for characters we blacklisted although allowed in IDN. | 606 // Test cases for characters we blacklisted although allowed in IDN. |
594 // Embedded spaces will be turned to %20 in the display. | 607 // Embedded spaces will be turned to %20 in the display. |
595 // TODO(jungshik): We need to have more cases. This is a typical | 608 // TODO(jungshik): We need to have more cases. This is a typical |
596 // data-driven trap. The following test cases need to be separated | 609 // data-driven trap. The following test cases need to be separated |
597 // and tested only for a couple of languages. | 610 // and tested only for a couple of languages. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 const GetDirectoryListingEntryCase test_cases[] = { | 781 const GetDirectoryListingEntryCase test_cases[] = { |
769 {"Foo", | 782 {"Foo", |
770 false, | 783 false, |
771 10000, | 784 10000, |
772 base::Time(), | 785 base::Time(), |
773 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"}, | 786 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"}, |
774 {"quo\"tes", | 787 {"quo\"tes", |
775 false, | 788 false, |
776 10000, | 789 10000, |
777 base::Time(), | 790 base::Time(), |
778 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>\n
"}, | 791 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" |
| 792 "\n"}, |
779 }; | 793 }; |
780 | 794 |
781 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 795 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
782 const std::string results = net::GetDirectoryListingEntry( | 796 const std::string results = net::GetDirectoryListingEntry( |
783 test_cases[i].name, | 797 test_cases[i].name, |
784 test_cases[i].is_dir, | 798 test_cases[i].is_dir, |
785 test_cases[i].filesize, | 799 test_cases[i].filesize, |
786 test_cases[i].time); | 800 test_cases[i].time); |
787 EXPECT_EQ(test_cases[i].expected, results); | 801 EXPECT_EQ(test_cases[i].expected, results); |
788 } | 802 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 } | 884 } |
871 } | 885 } |
872 | 886 |
873 TEST(NetUtilTest, GetMyHostName) { | 887 TEST(NetUtilTest, GetMyHostName) { |
874 // We can't check the result of GetMyHostName() directly, since the result | 888 // We can't check the result of GetMyHostName() directly, since the result |
875 // will differ across machines. Our goal here is to simply exercise the | 889 // will differ across machines. Our goal here is to simply exercise the |
876 // code path, and check that things "look about right". | 890 // code path, and check that things "look about right". |
877 std::string my_hostname = net::GetMyHostName(); | 891 std::string my_hostname = net::GetMyHostName(); |
878 EXPECT_FALSE(my_hostname.empty()); | 892 EXPECT_FALSE(my_hostname.empty()); |
879 } | 893 } |
OLD | NEW |