diff options
author | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 00:16:54 +0000 |
---|---|---|
committer | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 00:16:54 +0000 |
commit | a7206e77788f434a825828b804bf6446d797f8a8 (patch) | |
tree | f0ac52f8e41cbca071cdac1ed70bf0a8c38dc33b /net/http/http_content_disposition_unittest.cc | |
parent | b3dbcb5e2445baec0ceca5e57de9bf07621679ab (diff) | |
download | chromium_src-a7206e77788f434a825828b804bf6446d797f8a8.zip chromium_src-a7206e77788f434a825828b804bf6446d797f8a8.tar.gz chromium_src-a7206e77788f434a825828b804bf6446d797f8a8.tar.bz2 |
Add UMA for measuring Content-Dispostion header use and abuse.
BUG=162815
Review URL: https://chromiumcodereview.appspot.com/11478034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_content_disposition_unittest.cc')
-rw-r--r-- | net/http/http_content_disposition_unittest.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/net/http/http_content_disposition_unittest.cc b/net/http/http_content_disposition_unittest.cc index 240c699..66c1a7f 100644 --- a/net/http/http_content_disposition_unittest.cc +++ b/net/http/http_content_disposition_unittest.cc @@ -512,4 +512,79 @@ TEST(HttpContentDispositionTest, tc2231) { } } +TEST(HttpContentDispositionTest, ParseResult) { + const struct ParseResultTestCase { + const char* header; + int expected_flags; + } kTestCases[] = { + // Basic feature tests + { "", HttpContentDisposition::INVALID }, + { "example=x", HttpContentDisposition::INVALID }, + { "attachment; filename=", HttpContentDisposition::HAS_DISPOSITION_TYPE }, + { "attachment; name=", HttpContentDisposition::HAS_DISPOSITION_TYPE }, + { "attachment; filename*=", HttpContentDisposition::HAS_DISPOSITION_TYPE }, + { "attachment; filename==?utf-8?Q?\?=", + HttpContentDisposition::HAS_DISPOSITION_TYPE }, + { "filename=x", HttpContentDisposition::HAS_FILENAME }, + { "example; filename=x", + HttpContentDisposition::HAS_DISPOSITION_TYPE | + HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE | + HttpContentDisposition::HAS_FILENAME}, + { "attachment; filename=x", + HttpContentDisposition::HAS_DISPOSITION_TYPE | + HttpContentDisposition::HAS_FILENAME }, + { "attachment; filename=x; name=y", + HttpContentDisposition::HAS_DISPOSITION_TYPE | + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_NAME }, + { "attachment; name=y; filename*=utf-8''foo; name=x", + HttpContentDisposition::HAS_DISPOSITION_TYPE | + HttpContentDisposition::HAS_EXT_FILENAME | + HttpContentDisposition::HAS_NAME }, + + // Feature tests for 'filename' attribute. + { "filename=foo\xcc\x88", + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_NON_ASCII_STRINGS }, + { "filename=foo%cc%88", + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS }, + { "filename==?utf-8?Q?foo?=", + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, + { "filename=\"=?utf-8?Q?foo?=\"", + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, + { "filename==?utf-8?Q?foo?", HttpContentDisposition::INVALID }, + { "name=foo\xcc\x88", + HttpContentDisposition::HAS_NAME }, + + // Shouldn't set |has_non_ascii_strings| based on 'name' attribute. + { "filename=x; name=foo\xcc\x88", + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_NAME }, + { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?=", + HttpContentDisposition::HAS_FILENAME | + HttpContentDisposition::HAS_NON_ASCII_STRINGS | + HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS | + HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, + + // If 'filename' attribute is invalid, should set any flags based on it. + { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?", + HttpContentDisposition::INVALID }, + { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x", + HttpContentDisposition::HAS_NAME }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { + const ParseResultTestCase& test_case = kTestCases[i]; + HttpContentDisposition content_disposition(test_case.header, "utf-8"); + int result = content_disposition.parse_result_flags(); + + SCOPED_TRACE(testing::Message() << "Test case " << i + << " with header " << test_case.header); + EXPECT_EQ(test_case.expected_flags, result); + } +} + } // namespace net |