Chromium Code Reviews| 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/utf_string_conversions.h" | 7 #include "base/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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 }; | 505 }; |
| 506 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 506 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(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, UTF8ToWide(header.filename())) | 510 EXPECT_EQ(tests[i].expected_filename, 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) { | |
| 516 enum ParseResultFlags { | |
|
rvargas (doing something else)
2012/12/14 22:49:54
Funny... I was actually thinking that I would have
asanka
2012/12/15 01:57:32
Yeah. I changed the interface to use this. :)
rvargas (doing something else)
2012/12/15 02:46:57
wow, I was not expecting you to change it.
| |
| 517 INVALID = 0, | |
| 518 HAS_DISPOSITION_TYPE = 1 << 0, | |
| 519 HAS_UNKNOWN_DISPOSITION_TYPE = 1 << 1, | |
| 520 HAS_NAME = 1 << 2, | |
| 521 HAS_FILENAME = 1 << 3, | |
| 522 HAS_EXT_FILENAME = 1 << 4, | |
| 523 HAS_NON_ASCII_STRINGS = 1 << 5, | |
| 524 HAS_PERCENT_ENCODED_STRINGS = 1 << 6, | |
| 525 HAS_RFC2047_ENCODED_STRINGS = 1 << 7 | |
| 526 }; | |
| 527 | |
| 528 const struct ParseResultTestCase { | |
| 529 const char* header; | |
| 530 int expected_flags; | |
| 531 } kTestCases[] = { | |
| 532 // Basic feature tests | |
| 533 { "", INVALID }, | |
| 534 { "example=x", INVALID }, | |
| 535 { "attachment; filename=", HAS_DISPOSITION_TYPE }, | |
| 536 { "attachment; name=", HAS_DISPOSITION_TYPE }, | |
| 537 { "attachment; filename*=", HAS_DISPOSITION_TYPE }, | |
| 538 { "attachment; filename==?utf-8?Q??=", HAS_DISPOSITION_TYPE }, | |
| 539 { "filename=x", HAS_FILENAME }, | |
| 540 { "example; filename=x", | |
| 541 HAS_DISPOSITION_TYPE | HAS_UNKNOWN_DISPOSITION_TYPE | | |
| 542 HAS_FILENAME}, | |
| 543 { "attachment; filename=x", | |
| 544 HAS_DISPOSITION_TYPE | HAS_FILENAME }, | |
| 545 { "attachment; filename=x; name=y", | |
| 546 HAS_DISPOSITION_TYPE | HAS_FILENAME | HAS_NAME }, | |
| 547 { "attachment; name=y; filename*=utf-8''foo; name=x", | |
| 548 HAS_DISPOSITION_TYPE | HAS_EXT_FILENAME | HAS_NAME }, | |
| 549 | |
| 550 // Feature tests for 'filename' attribute. | |
| 551 { "filename=foo\xcc\x88", | |
| 552 HAS_FILENAME | HAS_NON_ASCII_STRINGS }, | |
| 553 { "filename=foo%cc%88", | |
| 554 HAS_FILENAME | HAS_PERCENT_ENCODED_STRINGS }, | |
| 555 { "filename==?utf-8?Q?foo?=", | |
| 556 HAS_FILENAME | HAS_RFC2047_ENCODED_STRINGS }, | |
| 557 { "filename=\"=?utf-8?Q?foo?=\"", | |
| 558 HAS_FILENAME | HAS_RFC2047_ENCODED_STRINGS }, | |
| 559 { "filename==?utf-8?Q?foo?", INVALID }, | |
| 560 { "name=foo\xcc\x88", | |
| 561 HAS_NAME }, | |
| 562 | |
| 563 // Shouldn't set |has_non_ascii_strings| based on 'name' attribute. | |
| 564 { "filename=x; name=foo\xcc\x88", | |
| 565 HAS_FILENAME | HAS_NAME }, | |
| 566 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?=", | |
| 567 HAS_FILENAME | HAS_NON_ASCII_STRINGS | HAS_PERCENT_ENCODED_STRINGS | | |
| 568 HAS_RFC2047_ENCODED_STRINGS }, | |
| 569 | |
| 570 // If 'filename' attribute is invalid, should set any flags based on it. | |
| 571 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?", | |
| 572 INVALID }, | |
| 573 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x", | |
| 574 HAS_NAME }, | |
| 575 }; | |
| 576 | |
| 577 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | |
| 578 const ParseResultTestCase& test_case = kTestCases[i]; | |
| 579 HttpContentDisposition content_disposition(test_case.header, "utf-8"); | |
| 580 const HttpContentDisposition::ParseResult& result = | |
| 581 content_disposition.parse_result(); | |
| 582 | |
| 583 SCOPED_TRACE(testing::Message() << "Test case " << i | |
| 584 << " with header " << test_case.header); | |
| 585 | |
| 586 EXPECT_EQ(!!(test_case.expected_flags & HAS_DISPOSITION_TYPE), | |
| 587 result.has_disposition_type); | |
| 588 EXPECT_EQ(!!(test_case.expected_flags & HAS_UNKNOWN_DISPOSITION_TYPE), | |
| 589 result.has_unknown_disposition_type); | |
| 590 EXPECT_EQ(!!(test_case.expected_flags & HAS_NAME), | |
| 591 result.has_name); | |
| 592 EXPECT_EQ(!!(test_case.expected_flags & HAS_FILENAME), | |
| 593 result.has_filename); | |
| 594 EXPECT_EQ(!!(test_case.expected_flags & HAS_EXT_FILENAME), | |
| 595 result.has_ext_filename); | |
| 596 EXPECT_EQ(!!(test_case.expected_flags & HAS_NON_ASCII_STRINGS), | |
| 597 result.has_non_ascii_strings); | |
| 598 EXPECT_EQ(!!(test_case.expected_flags & HAS_PERCENT_ENCODED_STRINGS), | |
| 599 result.has_percent_encoded_strings); | |
| 600 EXPECT_EQ(!!(test_case.expected_flags & HAS_RFC2047_ENCODED_STRINGS), | |
| 601 result.has_rfc2047_encoded_strings); | |
| 602 } | |
| 603 } | |
| 604 | |
| 515 } // namespace net | 605 } // namespace net |
| OLD | NEW |