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

Side by Side Diff: net/http/http_content_disposition_unittest.cc

Issue 11478034: Add UMA for measuring Content-Dispostion header use and abuse. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Suppress accidental trigraph Created 8 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_content_disposition.cc ('k') | no next file » | 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) 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
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 const struct ParseResultTestCase {
517 const char* header;
518 int expected_flags;
519 } kTestCases[] = {
520 // Basic feature tests
521 { "", HttpContentDisposition::INVALID },
522 { "example=x", HttpContentDisposition::INVALID },
523 { "attachment; filename=", HttpContentDisposition::HAS_DISPOSITION_TYPE },
524 { "attachment; name=", HttpContentDisposition::HAS_DISPOSITION_TYPE },
525 { "attachment; filename*=", HttpContentDisposition::HAS_DISPOSITION_TYPE },
526 { "attachment; filename==?utf-8?Q?\?=",
527 HttpContentDisposition::HAS_DISPOSITION_TYPE },
528 { "filename=x", HttpContentDisposition::HAS_FILENAME },
529 { "example; filename=x",
530 HttpContentDisposition::HAS_DISPOSITION_TYPE |
531 HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE |
532 HttpContentDisposition::HAS_FILENAME},
533 { "attachment; filename=x",
534 HttpContentDisposition::HAS_DISPOSITION_TYPE |
535 HttpContentDisposition::HAS_FILENAME },
536 { "attachment; filename=x; name=y",
537 HttpContentDisposition::HAS_DISPOSITION_TYPE |
538 HttpContentDisposition::HAS_FILENAME |
539 HttpContentDisposition::HAS_NAME },
540 { "attachment; name=y; filename*=utf-8''foo; name=x",
541 HttpContentDisposition::HAS_DISPOSITION_TYPE |
542 HttpContentDisposition::HAS_EXT_FILENAME |
543 HttpContentDisposition::HAS_NAME },
544
545 // Feature tests for 'filename' attribute.
546 { "filename=foo\xcc\x88",
547 HttpContentDisposition::HAS_FILENAME |
548 HttpContentDisposition::HAS_NON_ASCII_STRINGS },
549 { "filename=foo%cc%88",
550 HttpContentDisposition::HAS_FILENAME |
551 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS },
552 { "filename==?utf-8?Q?foo?=",
553 HttpContentDisposition::HAS_FILENAME |
554 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS },
555 { "filename=\"=?utf-8?Q?foo?=\"",
556 HttpContentDisposition::HAS_FILENAME |
557 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS },
558 { "filename==?utf-8?Q?foo?", HttpContentDisposition::INVALID },
559 { "name=foo\xcc\x88",
560 HttpContentDisposition::HAS_NAME },
561
562 // Shouldn't set |has_non_ascii_strings| based on 'name' attribute.
563 { "filename=x; name=foo\xcc\x88",
564 HttpContentDisposition::HAS_FILENAME |
565 HttpContentDisposition::HAS_NAME },
566 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?=",
567 HttpContentDisposition::HAS_FILENAME |
568 HttpContentDisposition::HAS_NON_ASCII_STRINGS |
569 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS |
570 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS },
571
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?",
574 HttpContentDisposition::INVALID },
575 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x",
576 HttpContentDisposition::HAS_NAME },
577 };
578
579 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
580 const ParseResultTestCase& test_case = kTestCases[i];
581 HttpContentDisposition content_disposition(test_case.header, "utf-8");
582 int result = content_disposition.parse_result_flags();
583
584 SCOPED_TRACE(testing::Message() << "Test case " << i
585 << " with header " << test_case.header);
586 EXPECT_EQ(test_case.expected_flags, result);
587 }
588 }
589
515 } // namespace net 590 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_content_disposition.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698