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

Side by Side Diff: net/base/net_util_unittest.cc

Issue 83002: download filename fix (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.cc ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_path.h" 6 #include "base/file_path.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 21 matching lines...) Expand all
32 }; 32 };
33 33
34 struct HeaderParamCase { 34 struct HeaderParamCase {
35 const wchar_t* header_name; 35 const wchar_t* header_name;
36 const wchar_t* param_name; 36 const wchar_t* param_name;
37 const wchar_t* expected; 37 const wchar_t* expected;
38 }; 38 };
39 39
40 struct FileNameCDCase { 40 struct FileNameCDCase {
41 const char* header_field; 41 const char* header_field;
42 const char* referrer_charset;
42 const wchar_t* expected; 43 const wchar_t* expected;
43 }; 44 };
44 45
45 const wchar_t* kLanguages[] = { 46 const wchar_t* kLanguages[] = {
46 L"", L"en", L"zh-CN", L"ja", L"ko", 47 L"", L"en", L"zh-CN", L"ja", L"ko",
47 L"he", L"ar", L"ru", L"el", L"fr", 48 L"he", L"ar", L"ru", L"el", L"fr",
48 L"de", L"pt", L"sv", L"th", L"hi", 49 L"de", L"pt", L"sv", L"th", L"hi",
49 L"de,en", L"el,en", L"zh,zh-TW,en", L"ko,ja", L"he,ru,en", 50 L"de,en", L"el,en", L"zh,zh-TW,en", L"ko,ja", L"he,ru,en",
50 L"zh,ru,en" 51 L"zh,ru,en"
51 }; 52 };
52 53
53 struct IDNTestCase { 54 struct IDNTestCase {
54 const char* input; 55 const char* input;
55 const wchar_t* unicode_output; 56 const wchar_t* unicode_output;
56 const bool unicode_allowed[arraysize(kLanguages)]; 57 const bool unicode_allowed[arraysize(kLanguages)];
57 }; 58 };
58 59
59 struct SuggestedFilenameCase { 60 struct SuggestedFilenameCase {
60 const char* url; 61 const char* url;
61 const wchar_t* content_disp_header; 62 const char* content_disp_header;
63 const char* referrer_charset;
62 const wchar_t* default_filename; 64 const wchar_t* default_filename;
63 const wchar_t* expected_filename; 65 const wchar_t* expected_filename;
64 }; 66 };
65 67
66 // Returns an addrinfo for the given 32-bit address (IPv4.) 68 // Returns an addrinfo for the given 32-bit address (IPv4.)
67 // The result lives in static storage, so don't delete it. 69 // The result lives in static storage, so don't delete it.
68 const struct addrinfo* GetIPv4Address(const uint8 bytes[4]) { 70 const struct addrinfo* GetIPv4Address(const uint8 bytes[4]) {
69 static struct addrinfo static_ai; 71 static struct addrinfo static_ai;
70 static struct sockaddr_in static_addr4; 72 static struct sockaddr_in static_addr4;
71 73
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 net::GetSpecificHeader(L"", tests[i].header_name); 294 net::GetSpecificHeader(L"", tests[i].header_name);
293 std::wstring result = 295 std::wstring result =
294 net::GetHeaderParamValue(header_value, tests[i].param_name); 296 net::GetHeaderParamValue(header_value, tests[i].param_name);
295 EXPECT_EQ(result, std::wstring()); 297 EXPECT_EQ(result, std::wstring());
296 } 298 }
297 } 299 }
298 300
299 TEST(NetUtilTest, GetFileNameFromCD) { 301 TEST(NetUtilTest, GetFileNameFromCD) {
300 const FileNameCDCase tests[] = { 302 const FileNameCDCase tests[] = {
301 // Test various forms of C-D header fields emitted by web servers. 303 // Test various forms of C-D header fields emitted by web servers.
302 {"content-disposition: inline; filename=\"abcde.pdf\"", L"abcde.pdf"}, 304 {"content-disposition: inline; filename=\"abcde.pdf\"", "", L"abcde.pdf"},
303 {"content-disposition: inline; name=\"abcde.pdf\"", L"abcde.pdf"}, 305 {"content-disposition: inline; name=\"abcde.pdf\"", "", L"abcde.pdf"},
304 {"content-disposition: attachment; filename=abcde.pdf", L"abcde.pdf"}, 306 {"content-disposition: attachment; filename=abcde.pdf", "", L"abcde.pdf"},
305 {"content-disposition: attachment; name=abcde.pdf", L"abcde.pdf"}, 307 {"content-disposition: attachment; name=abcde.pdf", "", L"abcde.pdf"},
306 {"content-disposition: attachment; filename=abc,de.pdf", L"abc,de.pdf"}, 308 {"content-disposition: attachment; filename=abc,de.pdf", "", L"abc,de.pdf"},
307 {"content-disposition: filename=abcde.pdf", L"abcde.pdf"}, 309 {"content-disposition: filename=abcde.pdf", "", L"abcde.pdf"},
308 {"content-disposition: filename= abcde.pdf", L"abcde.pdf"}, 310 {"content-disposition: filename= abcde.pdf", "", L"abcde.pdf"},
309 {"content-disposition: filename =abcde.pdf", L"abcde.pdf"}, 311 {"content-disposition: filename =abcde.pdf", "", L"abcde.pdf"},
310 {"content-disposition: filename = abcde.pdf", L"abcde.pdf"}, 312 {"content-disposition: filename = abcde.pdf", "", L"abcde.pdf"},
311 {"content-disposition: filename\t=abcde.pdf", L"abcde.pdf"}, 313 {"content-disposition: filename\t=abcde.pdf", "", L"abcde.pdf"},
312 {"content-disposition: filename \t\t =abcde.pdf", L"abcde.pdf"}, 314 {"content-disposition: filename \t\t =abcde.pdf", "", L"abcde.pdf"},
313 {"content-disposition: name=abcde.pdf", L"abcde.pdf"}, 315 {"content-disposition: name=abcde.pdf", "", L"abcde.pdf"},
314 {"content-disposition: inline; filename=\"abc%20de.pdf\"", L"abc de.pdf"}, 316 {"content-disposition: inline; filename=\"abc%20de.pdf\"", "",
317 L"abc de.pdf"},
315 // Whitespaces are converted to a space. 318 // Whitespaces are converted to a space.
316 {"content-disposition: inline; filename=\"abc \t\nde.pdf\"", 319 {"content-disposition: inline; filename=\"abc \t\nde.pdf\"", "",
317 L"abc de.pdf"}, 320 L"abc de.pdf"},
318 // %-escaped UTF-8 321 // %-escaped UTF-8
319 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" 322 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20"
320 "%EC%98%88%EC%88%A0.jpg\"", L"\xc608\xc220 \xc608\xc220.jpg"}, 323 "%EC%98%88%EC%88%A0.jpg\"", "", L"\xc608\xc220 \xc608\xc220.jpg"},
321 {"Content-Disposition: attachment; filename=\"%F0%90%8C%B0%F0%90%8C%B1" 324 {"Content-Disposition: attachment; filename=\"%F0%90%8C%B0%F0%90%8C%B1"
322 "abc.jpg\"", L"\U00010330\U00010331abc.jpg"}, 325 "abc.jpg\"", "", L"\U00010330\U00010331abc.jpg"},
323 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0 \n" 326 {"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0 \n"
324 "%EC%98%88%EC%88%A0.jpg\"", L"\xc608\xc220 \xc608\xc220.jpg"}, 327 "%EC%98%88%EC%88%A0.jpg\"", "", L"\xc608\xc220 \xc608\xc220.jpg"},
325 // RFC 2047 with various charsets and Q/B encodings 328 // RFC 2047 with various charsets and Q/B encodings
326 {"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" 329 {"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD="
327 "D13=2Epng?=\"", L"\x82b8\x8853" L"3.png"}, 330 "D13=2Epng?=\"", "", L"\x82b8\x8853" L"3.png"},
328 {"Content-Disposition: attachment; filename==?eUc-Kr?b?v7m8+iAzLnBuZw==?=", 331 {"Content-Disposition: attachment; filename==?eUc-Kr?b?v7m8+iAzLnBuZw==?=",
329 L"\xc608\xc220 3.png"}, 332 "", L"\xc608\xc220 3.png"},
330 {"Content-Disposition: attachment; filename==?utf-8?Q?=E8=8A=B8=E8" 333 {"Content-Disposition: attachment; filename==?utf-8?Q?=E8=8A=B8=E8"
331 "=A1=93_3=2Epng?=", L"\x82b8\x8853 3.png"}, 334 "=A1=93_3=2Epng?=", "", L"\x82b8\x8853 3.png"},
332 {"Content-Disposition: attachment; filename==?utf-8?Q?=F0=90=8C=B0" 335 {"Content-Disposition: attachment; filename==?utf-8?Q?=F0=90=8C=B0"
333 "_3=2Epng?=", L"\U00010330 3.png"}, 336 "_3=2Epng?=", "", L"\U00010330 3.png"},
334 {"Content-Disposition: inline; filename=\"=?iso88591?Q?caf=e3_=2epng?=\"", 337 {"Content-Disposition: inline; filename=\"=?iso88591?Q?caf=e9_=2epng?=\"",
335 L"caf\x00e3 .png"}, 338 "", L"caf\x00e9 .png"},
336 // Space after an encode word should be removed. 339 // Space after an encode word should be removed.
337 {"Content-Disposition: inline; filename=\"=?iso88591?Q?caf=E3_?= .png\"", 340 {"Content-Disposition: inline; filename=\"=?iso88591?Q?caf=E9_?= .png\"",
338 L"caf\x00e3 .png"}, 341 "", L"caf\x00e9 .png"},
339 // Two encoded words with different charsets (not very likely to be emitted 342 // Two encoded words with different charsets (not very likely to be emitted
340 // by web servers in the wild). Spaces between them are removed. 343 // by web servers in the wild). Spaces between them are removed.
341 {"Content-Disposition: inline; filename=\"=?euc-kr?b?v7m8+iAz?=" 344 {"Content-Disposition: inline; filename=\"=?euc-kr?b?v7m8+iAz?="
342 " =?ksc5601?q?=BF=B9=BC=FA=2Epng?=\"", L"\xc608\xc220 3\xc608\xc220.png"}, 345 " =?ksc5601?q?=BF=B9=BC=FA=2Epng?=\"", "",
343 {"Content-Disposition: attachment; filename=\"=?windows-1252?Q?caf=E3?=" 346 L"\xc608\xc220 3\xc608\xc220.png"},
344 " =?iso-8859-7?b?4eI=?= .png\"", L"caf\x00e3\x03b1\x03b2.png"}, 347 {"Content-Disposition: attachment; filename=\"=?windows-1252?Q?caf=E9?="
345 // Non-ASCII string is passed through (and treated as UTF-8). 348 " =?iso-8859-7?b?4eI=?= .png\"", "", L"caf\x00e9\x03b1\x03b2.png"},
346 {"Content-Disposition: attachment; filename=caf\xc3\xa3.png", 349 // Non-ASCII string is passed through and treated as UTF-8 as long as
347 L"caf\x00e3.png"}, 350 // it's valid as UTF-8 and regardless of |referrer_charset|.
351 {"Content-Disposition: attachment; filename=caf\xc3\xa9.png",
352 "iso-8859-1", L"caf\x00e9.png"},
353 {"Content-Disposition: attachment; filename=caf\xc3\xa9.png",
354 "", L"caf\x00e9.png"},
355 // Non-ASCII/Non-UTF-8 string. Fall back to the referrer charset.
356 {"Content-Disposition: attachment; filename=caf\xe5.png",
357 "windows-1253", L"caf\x03b5.png"},
358 #if 0
359 // Non-ASCII/Non-UTF-8 string. Fall back to the native codepage.
360 // TODO(jungshik): We need to set the OS default codepage
361 // to a specific value before testing. On Windows, we can use
362 // SetThreadLocale().
363 {"Content-Disposition: attachment; filename=\xb0\xa1\xb0\xa2.png",
364 "", L"\xac00\xac01.png"},
365 #endif
348 // Failure cases 366 // Failure cases
349 // Invalid hex-digit "G" 367 // Invalid hex-digit "G"
350 {"Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", L""}, 368 {"Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", "",
369 L""},
351 // Incomplete RFC 2047 encoded-word (missing '='' at the end) 370 // Incomplete RFC 2047 encoded-word (missing '='' at the end)
352 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?", L""}, 371 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?", "", L""},
353 // Extra character at the end of an encoded word 372 // Extra character at the end of an encoded word
354 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?==", L""}, 373 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?==",
374 "", L""},
355 // Extra token at the end of an encoded word 375 // Extra token at the end of an encoded word
356 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?=?", L""}, 376 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?=?",
357 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?=?=", L""}, 377 "", L""},
378 {"Content-Disposition: attachment; filename==?iso88591?Q?caf=E3?=?=",
379 "", L""},
358 // Incomplete hex-escaped chars 380 // Incomplete hex-escaped chars
359 {"Content-Disposition: attachment; filename==?windows-1252?Q?=63=61=E?=", 381 {"Content-Disposition: attachment; filename==?windows-1252?Q?=63=61=E?=",
360 L""}, 382 "", L""},
361 {"Content-Disposition: attachment; filename=%EC%98%88%EC%88%A", L""}, 383 {"Content-Disposition: attachment; filename=%EC%98%88%EC%88%A", "", L""},
362 // %-escaped non-UTF-8 encoding is an "error" 384 // %-escaped non-UTF-8 encoding is an "error"
363 {"Content-Disposition: attachment; filename=%B7%DD%BD%D1.png", L""}, 385 {"Content-Disposition: attachment; filename=%B7%DD%BD%D1.png", "", L""},
364 // Two RFC 2047 encoded words in a row without a space is an error. 386 // Two RFC 2047 encoded words in a row without a space is an error.
365 {"Content-Disposition: attachment; filename==?windows-1252?Q?caf=E3?=" 387 {"Content-Disposition: attachment; filename==?windows-1252?Q?caf=E3?="
366 "=?iso-8859-7?b?4eIucG5nCg==?=", L""}, 388 "=?iso-8859-7?b?4eIucG5nCg==?=", "", L""},
367 }; 389 };
368 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 390 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
369 EXPECT_EQ(tests[i].expected, 391 EXPECT_EQ(tests[i].expected,
370 net::GetFileNameFromCD(tests[i].header_field)); 392 net::GetFileNameFromCD(tests[i].header_field,
393 tests[i].referrer_charset));
371 } 394 }
372 } 395 }
373 396
374 TEST(NetUtilTest, IDNToUnicode) { 397 TEST(NetUtilTest, IDNToUnicode) {
375 // TODO(jungshik) This is just a random sample of languages and is far 398 // TODO(jungshik) This is just a random sample of languages and is far
376 // from exhaustive. We may have to generate all the combinations 399 // from exhaustive. We may have to generate all the combinations
377 // of languages (powerset of a set of all the languages). 400 // of languages (powerset of a set of all the languages).
378 const IDNTestCase idn_cases[] = { 401 const IDNTestCase idn_cases[] = {
379 // No IDN 402 // No IDN
380 {"www.google.com", L"www.google.com", 403 {"www.google.com", L"www.google.com",
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 TEST(NetUtilTest, StripWWW) { 685 TEST(NetUtilTest, StripWWW) {
663 EXPECT_EQ(L"", net::StripWWW(L"")); 686 EXPECT_EQ(L"", net::StripWWW(L""));
664 EXPECT_EQ(L"", net::StripWWW(L"www.")); 687 EXPECT_EQ(L"", net::StripWWW(L"www."));
665 EXPECT_EQ(L"blah", net::StripWWW(L"www.blah")); 688 EXPECT_EQ(L"blah", net::StripWWW(L"www.blah"));
666 EXPECT_EQ(L"blah", net::StripWWW(L"blah")); 689 EXPECT_EQ(L"blah", net::StripWWW(L"blah"));
667 } 690 }
668 691
669 TEST(NetUtilTest, GetSuggestedFilename) { 692 TEST(NetUtilTest, GetSuggestedFilename) {
670 const SuggestedFilenameCase test_cases[] = { 693 const SuggestedFilenameCase test_cases[] = {
671 {"http://www.google.com/", 694 {"http://www.google.com/",
672 L"Content-disposition: attachment; filename=test.html", 695 "Content-disposition: attachment; filename=test.html",
696 "",
673 L"", 697 L"",
674 L"test.html"}, 698 L"test.html"},
675 {"http://www.google.com/", 699 {"http://www.google.com/",
676 L"Content-disposition: attachment; filename=\"test.html\"", 700 "Content-disposition: attachment; filename=\"test.html\"",
701 "",
677 L"", 702 L"",
678 L"test.html"}, 703 L"test.html"},
679 {"http://www.google.com/path/test.html", 704 {"http://www.google.com/path/test.html",
680 L"Content-disposition: attachment", 705 "Content-disposition: attachment",
706 "",
681 L"", 707 L"",
682 L"test.html"}, 708 L"test.html"},
683 {"http://www.google.com/path/test.html", 709 {"http://www.google.com/path/test.html",
684 L"Content-disposition: attachment;", 710 "Content-disposition: attachment;",
711 "",
685 L"", 712 L"",
686 L"test.html"}, 713 L"test.html"},
687 {"http://www.google.com/", 714 {"http://www.google.com/",
688 L"", 715 "",
716 "",
689 L"", 717 L"",
690 L"www.google.com"}, 718 L"www.google.com"},
691 {"http://www.google.com/test.html", 719 {"http://www.google.com/test.html",
692 L"", 720 "",
721 "",
693 L"", 722 L"",
694 L"test.html"}, 723 L"test.html"},
695 // Now that we use googleurl's ExtractFileName, this case falls back 724 // Now that we use googleurl's ExtractFileName, this case falls back
696 // to the hostname. If this behavior is not desirable, we'd better 725 // to the hostname. If this behavior is not desirable, we'd better
697 // change ExtractFileName (in url_parse). 726 // change ExtractFileName (in url_parse).
698 {"http://www.google.com/path/", 727 {"http://www.google.com/path/",
699 L"", 728 "",
729 "",
700 L"", 730 L"",
701 L"www.google.com"}, 731 L"www.google.com"},
702 {"http://www.google.com/path", 732 {"http://www.google.com/path",
703 L"", 733 "",
734 "",
704 L"", 735 L"",
705 L"path"}, 736 L"path"},
706 {"file:///", 737 {"file:///",
707 L"", 738 "",
739 "",
708 L"", 740 L"",
709 L"download"}, 741 L"download"},
710 {"view-cache:", 742 {"view-cache:",
711 L"", 743 "",
744 "",
712 L"", 745 L"",
713 L"download"}, 746 L"download"},
714 {"http://www.google.com/", 747 {"http://www.google.com/",
715 L"Content-disposition: attachment; filename =\"test.html\"", 748 "Content-disposition: attachment; filename =\"test.html\"",
749 "",
716 L"download", 750 L"download",
717 L"test.html"}, 751 L"test.html"},
718 {"http://www.google.com/", 752 {"http://www.google.com/",
719 L"", 753 "",
754 "",
720 L"download", 755 L"download",
721 L"download"}, 756 L"download"},
722 {"http://www.google.com/", 757 {"http://www.google.com/",
723 L"Content-disposition: attachment; filename=\"../test.html\"", 758 "Content-disposition: attachment; filename=\"../test.html\"",
759 "",
724 L"", 760 L"",
725 L"test.html"}, 761 L"test.html"},
726 {"http://www.google.com/", 762 {"http://www.google.com/",
727 L"Content-disposition: attachment; filename=\"..\"", 763 "Content-disposition: attachment; filename=\"..\"",
764 "",
728 L"download", 765 L"download",
729 L"download"}, 766 L"download"},
730 {"http://www.google.com/test.html", 767 {"http://www.google.com/test.html",
731 L"Content-disposition: attachment; filename=\"..\"", 768 "Content-disposition: attachment; filename=\"..\"",
769 "",
732 L"download", 770 L"download",
733 L"test.html"}, 771 L"test.html"},
734 // Below is a small subset of cases taken from GetFileNameFromCD test above. 772 // Below is a small subset of cases taken from GetFileNameFromCD test above.
735 {"http://www.google.com/", 773 {"http://www.google.com/",
736 L"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" 774 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20"
737 L"%EC%98%88%EC%88%A0.jpg\"", 775 "%EC%98%88%EC%88%A0.jpg\"",
776 "",
738 L"", 777 L"",
739 L"\uc608\uc220 \uc608\uc220.jpg"}, 778 L"\uc608\uc220 \uc608\uc220.jpg"},
740 {"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", 779 {"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg",
741 L"", 780 "",
781 "",
742 L"download", 782 L"download",
743 L"\uc608\uc220 \uc608\uc220.jpg"}, 783 L"\uc608\uc220 \uc608\uc220.jpg"},
744 {"http://www.google.com/", 784 {"http://www.google.com/",
745 L"Content-disposition: attachment;", 785 "Content-disposition: attachment;",
786 "",
746 L"\uB2E4\uC6B4\uB85C\uB4DC", 787 L"\uB2E4\uC6B4\uB85C\uB4DC",
747 L"\uB2E4\uC6B4\uB85C\uB4DC"}, 788 L"\uB2E4\uC6B4\uB85C\uB4DC"},
748 {"http://www.google.com/", 789 {"http://www.google.com/",
749 L"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" 790 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD="
750 L"D13=2Epng?=\"", 791 "D13=2Epng?=\"",
792 "",
751 L"download", 793 L"download",
752 L"\u82b8\u88533.png"}, 794 L"\u82b8\u88533.png"},
795 {"http://www.example.com/images?id=3",
796 "Content-Disposition: attachment; filename=caf\xc3\xa9.png",
797 "iso-8859-1",
798 L"",
799 L"caf\u00e9.png"},
800 {"http://www.example.com/images?id=3",
801 "Content-Disposition: attachment; filename=caf\xe5.png",
802 "windows-1253",
803 L"",
804 L"caf\u03b5.png"},
805 {"http://www.example.com/file?id=3",
806 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip",
807 "GBK",
808 L"",
809 L"\u4e0b\u8f7d.zip"},
753 // Invalid C-D header. Extracts filename from url. 810 // Invalid C-D header. Extracts filename from url.
754 {"http://www.google.com/test.html", 811 {"http://www.google.com/test.html",
755 L"Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", 812 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=",
813 "",
756 L"", 814 L"",
757 L"test.html"}, 815 L"test.html"},
758 }; 816 };
759 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 817 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
760 std::wstring filename = net::GetSuggestedFilename( 818 std::wstring filename = net::GetSuggestedFilename(
761 GURL(test_cases[i].url), test_cases[i].content_disp_header, 819 GURL(test_cases[i].url), test_cases[i].content_disp_header,
762 test_cases[i].default_filename); 820 test_cases[i].referrer_charset, test_cases[i].default_filename);
763 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename); 821 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename);
764 } 822 }
765 } 823 }
766 824
767 // This is currently a windows specific function. 825 // This is currently a windows specific function.
768 #if defined(OS_WIN) 826 #if defined(OS_WIN)
769 namespace { 827 namespace {
770 828
771 struct GetDirectoryListingEntryCase { 829 struct GetDirectoryListingEntryCase {
772 const char* name; 830 const char* name;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 942 }
885 } 943 }
886 944
887 TEST(NetUtilTest, GetHostName) { 945 TEST(NetUtilTest, GetHostName) {
888 // We can't check the result of GetHostName() directly, since the result 946 // We can't check the result of GetHostName() directly, since the result
889 // will differ across machines. Our goal here is to simply exercise the 947 // will differ across machines. Our goal here is to simply exercise the
890 // code path, and check that things "look about right". 948 // code path, and check that things "look about right".
891 std::string hostname = net::GetHostName(); 949 std::string hostname = net::GetHostName();
892 EXPECT_FALSE(hostname.empty()); 950 EXPECT_FALSE(hostname.empty());
893 } 951 }
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698