OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/http_content_disposition.h" | 5 #include "net/http/http_content_disposition.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // attfnboth | 188 // attfnboth |
189 {"attachment; filename=\"foo-ae.html\"; " | 189 {"attachment; filename=\"foo-ae.html\"; " |
190 "filename*=UTF-8''foo-%c3%a4.html", "", L"foo-\xe4.html"}, | 190 "filename*=UTF-8''foo-%c3%a4.html", "", L"foo-\xe4.html"}, |
191 // attfnboth2 | 191 // attfnboth2 |
192 {"attachment; filename*=UTF-8''foo-%c3%a4.html; " | 192 {"attachment; filename*=UTF-8''foo-%c3%a4.html; " |
193 "filename=\"foo-ae.html\"", "", L"foo-\xe4.html"}, | 193 "filename=\"foo-ae.html\"", "", L"foo-\xe4.html"}, |
194 // attnewandfn | 194 // attnewandfn |
195 {"attachment; foobar=x; filename=\"foo.html\"", "", | 195 {"attachment; foobar=x; filename=\"foo.html\"", "", |
196 L"foo.html"}, | 196 L"foo.html"}, |
197 }; | 197 }; |
198 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 198 for (size_t i = 0; i < arraysize(tests); ++i) { |
199 HttpContentDisposition header(tests[i].header, tests[i].referrer_charset); | 199 HttpContentDisposition header(tests[i].header, tests[i].referrer_charset); |
200 EXPECT_EQ(tests[i].expected, | 200 EXPECT_EQ(tests[i].expected, |
201 base::UTF8ToWide(header.filename())) | 201 base::UTF8ToWide(header.filename())) |
202 << "Failed on input: " << tests[i].header; | 202 << "Failed on input: " << tests[i].header; |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 // Test cases from http://greenbytes.de/tech/tc2231/ | 206 // Test cases from http://greenbytes.de/tech/tc2231/ |
207 TEST(HttpContentDispositionTest, tc2231) { | 207 TEST(HttpContentDispositionTest, tc2231) { |
208 const struct FileNameCDCase { | 208 const struct FileNameCDCase { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 // http://greenbytes.de/tech/tc2231/#attnewandfn | 496 // http://greenbytes.de/tech/tc2231/#attnewandfn |
497 { "attachment; foobar=x; filename=\"foo.html\"", | 497 { "attachment; foobar=x; filename=\"foo.html\"", |
498 net::HttpContentDisposition::ATTACHMENT, | 498 net::HttpContentDisposition::ATTACHMENT, |
499 L"foo.html" | 499 L"foo.html" |
500 }, | 500 }, |
501 // TODO(abarth): Add the filename* tests, but check | 501 // TODO(abarth): Add the filename* tests, but check |
502 // HttpContentDispositionTest.Filename for overlap. | 502 // HttpContentDispositionTest.Filename for overlap. |
503 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047token | 503 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047token |
504 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047quoted | 504 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047quoted |
505 }; | 505 }; |
506 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 506 for (size_t i = 0; i < arraysize(tests); ++i) { |
507 HttpContentDisposition header(tests[i].header, std::string()); | 507 HttpContentDisposition header(tests[i].header, std::string()); |
508 EXPECT_EQ(tests[i].expected_type, header.type()) | 508 EXPECT_EQ(tests[i].expected_type, header.type()) |
509 << "Failed on input: " << tests[i].header; | 509 << "Failed on input: " << tests[i].header; |
510 EXPECT_EQ(tests[i].expected_filename, base::UTF8ToWide(header.filename())) | 510 EXPECT_EQ(tests[i].expected_filename, base::UTF8ToWide(header.filename())) |
511 << "Failed on input: " << tests[i].header; | 511 << "Failed on input: " << tests[i].header; |
512 } | 512 } |
513 } | 513 } |
514 | 514 |
515 TEST(HttpContentDispositionTest, ParseResult) { | 515 TEST(HttpContentDispositionTest, ParseResult) { |
516 const struct ParseResultTestCase { | 516 const struct ParseResultTestCase { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS | | 569 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS | |
570 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, | 570 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, |
571 | 571 |
572 // If 'filename' attribute is invalid, should set any flags based on it. | 572 // If 'filename' attribute is invalid, should set any flags based on it. |
573 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?", | 573 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?", |
574 HttpContentDisposition::INVALID }, | 574 HttpContentDisposition::INVALID }, |
575 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x", | 575 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x", |
576 HttpContentDisposition::HAS_NAME }, | 576 HttpContentDisposition::HAS_NAME }, |
577 }; | 577 }; |
578 | 578 |
579 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 579 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
580 const ParseResultTestCase& test_case = kTestCases[i]; | 580 const ParseResultTestCase& test_case = kTestCases[i]; |
581 HttpContentDisposition content_disposition(test_case.header, "utf-8"); | 581 HttpContentDisposition content_disposition(test_case.header, "utf-8"); |
582 int result = content_disposition.parse_result_flags(); | 582 int result = content_disposition.parse_result_flags(); |
583 | 583 |
584 SCOPED_TRACE(testing::Message() << "Test case " << i | 584 SCOPED_TRACE(testing::Message() << "Test case " << i |
585 << " with header " << test_case.header); | 585 << " with header " << test_case.header); |
586 EXPECT_EQ(test_case.expected_flags, result); | 586 EXPECT_EQ(test_case.expected_flags, result); |
587 } | 587 } |
588 } | 588 } |
589 | 589 |
590 } // namespace net | 590 } // namespace net |
OLD | NEW |