summaryrefslogtreecommitdiffstats
path: root/net/http/http_content_disposition_unittest.cc
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 20:39:11 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 20:39:11 +0000
commitaab0d2e2f0167b5bb29f670c8e7229e9c5f3f57e (patch)
treeaab07ed223862bc3de70351c711f471fc8ea8d92 /net/http/http_content_disposition_unittest.cc
parentab34561dd992607626f7b7c7ee06d429de55df04 (diff)
downloadchromium_src-aab0d2e2f0167b5bb29f670c8e7229e9c5f3f57e.zip
chromium_src-aab0d2e2f0167b5bb29f670c8e7229e9c5f3f57e.tar.gz
chromium_src-aab0d2e2f0167b5bb29f670c8e7229e9c5f3f57e.tar.bz2
Import Content-Disposition parsing tests from http://greenbytes.de/tech/tc2231/
We pass the vast majority of these tests. In a future CL, I will go through and fix the ones where we disagree with tc2231 (as appropriate). Review URL: https://chromiumcodereview.appspot.com/9121044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_content_disposition_unittest.cc')
-rw-r--r--net/http/http_content_disposition_unittest.cc303
1 files changed, 303 insertions, 0 deletions
diff --git a/net/http/http_content_disposition_unittest.cc b/net/http/http_content_disposition_unittest.cc
index 3d8750e..548f9cd 100644
--- a/net/http/http_content_disposition_unittest.cc
+++ b/net/http/http_content_disposition_unittest.cc
@@ -198,4 +198,307 @@ TEST(HttpContentDispositionTest, Filename) {
}
}
+// Test cases from http://greenbytes.de/tech/tc2231/
+TEST(HttpContentDispositionTest, tc2231) {
+ const struct FileNameCDCase {
+ const char* header;
+ net::HttpContentDisposition::Type expected_type;
+ const wchar_t* expected_filename;
+ } tests[] = {
+ // http://greenbytes.de/tech/tc2231/#inlonly
+ { "inline",
+ net::HttpContentDisposition::INLINE,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#inlonlyquoted
+ { "\"inline\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#inlwithasciifilename
+ { "inline; filename=\"foo.html\"",
+ net::HttpContentDisposition::INLINE,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#inlwithfnattach
+ { "inline; filename=\"Not an attachment!\"",
+ net::HttpContentDisposition::INLINE,
+ L"Not an attachment!"
+ },
+ // http://greenbytes.de/tech/tc2231/#inlwithasciifilenamepdf
+ { "inline; filename=\"foo.pdf\"",
+ net::HttpContentDisposition::INLINE,
+ L"foo.pdf"
+ },
+ // http://greenbytes.de/tech/tc2231/#attonly
+ { "attachment",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attonlyquoted
+ { "\"attachment\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attonly403
+ // TODO(abarth): This isn't testable in this unit test.
+ // http://greenbytes.de/tech/tc2231/#attonlyucase
+ { "ATTACHMENT",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifilename
+ { "attachment; filename=\"foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifnescapedchar
+ { "attachment; filename=\"f\\oo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifnescapedquote
+ { "attachment; filename=\"\\\"quoting\\\" tested.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"\"quoting\" tested.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithquotedsemicolon
+ { "attachment; filename=\"Here's a semicolon;.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"Here's a semicolon;.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfilenameandextparam
+ { "attachment; foo=\"bar\"; filename=\"foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfilenameandextparamescaped
+ { "attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifilenameucase
+ { "attachment; FILENAME=\"foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenq
+ { "attachment; filename=foo.html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqs
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=foo.html ;",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attemptyparam
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; ;filename=foo",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqws
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=foo bar.html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo bar.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfntokensq
+ { "attachment; filename='foo.bar'",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.bar" // Should be L"'foo.bar'"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithisofnplain
+ { "attachment; filename=\"foo-\xE4html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"" // Should be L"foo-\xE4.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithutf8fnplain
+ // Note: We'll UTF-8 decode the file name, even though tc2231 says not to.
+ { "attachment; filename=\"foo-\xC3\xA4.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo-\xE4.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfnrawpctenca
+ { "attachment; filename=\"foo-%41.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo-A.html" // Should be L"foo-%41.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfnusingpct
+ { "attachment; filename=\"50%.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"50%.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfnrawpctencaq
+ { "attachment; filename=\"foo-%\\41.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo-A.html" // Should be L"foo-%41.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithnamepct
+ { "attachment; name=\"foo-%41.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo-A.html" // Should be L"foo-%41.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfilenamepctandiso
+ { "attachment; filename=\"\xE4-%41.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"" // Should be L"\xE4-%41.htm"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithfnrawpctenclong
+ { "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo-\xE4-\u20AC.html" // Should be L"foo-%c3%a4-%e2%82%ac.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwithasciifilenamews1
+ { "attachment; filename =\"foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attwith2filenames
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=\"foo.html\"; filename=\"bar.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"bar.html" // Probably should be foo.html to match other browsers.
+ },
+ // http://greenbytes.de/tech/tc2231/#attfnbrokentoken
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=foo[1](2).html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo[1](2).html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attfnbrokentokeniso
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=foo-\xE4.html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attfnbrokentokenutf
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=foo-\xC3\xA4.html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo-\xE4.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attmissingdisposition
+ // Note: tc2231 says we should fail to parse this header.
+ { "filename=foo.html",
+ net::HttpContentDisposition::INLINE,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attmissingdisposition2
+ // Note: tc2231 says we should fail to parse this header.
+ { "x=y; filename=foo.html",
+ net::HttpContentDisposition::INLINE,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attmissingdisposition3
+ // Note: tc2231 says we should fail to parse this header.
+ { "\"foo; filename=bar;baz\"; filename=qux",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"bar" // Firefox gets qux
+ },
+ // http://greenbytes.de/tech/tc2231/#attmissingdisposition4
+ // Note: tc2231 says we should fail to parse this header.
+ { "filename=foo.html, filename=bar.html",
+ net::HttpContentDisposition::INLINE,
+ L"foo.html, filename=bar.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#emptydisposition
+ // Note: tc2231 says we should fail to parse this header.
+ { "; filename=foo.html",
+ net::HttpContentDisposition::ATTACHMENT, // Should be INLINE?
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attandinline
+ // Note: tc2231 says we should fail to parse this header.
+ { "inline; attachment; filename=foo.html",
+ net::HttpContentDisposition::INLINE,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attandinline2
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; inline; filename=foo.html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=\"foo.html\".txt",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html\".txt"
+ },
+ // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn2
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=\"bar",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"bar"
+ },
+ // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn3
+ // Note: tc2231 says we should fail to parse this header.
+ { "attachment; filename=foo\"bar;baz\"qux",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo\"bar;baz\"qux"
+ },
+ // http://greenbytes.de/tech/tc2231/#attmultinstances
+ { "attachment; filename=foo.html, attachment; filename=bar.html",
+ // Note: tc2231 says we should fail to parse this header.
+ net::HttpContentDisposition::ATTACHMENT,
+ L"bar.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attmissingdelim
+ { "attachment; foo=foo filename=bar",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attreversed
+ // Note: tc2231 says we should fail to parse this header.
+ { "filename=foo.html; attachment",
+ net::HttpContentDisposition::INLINE,
+ L"foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attconfusedparam
+ { "attachment; xfilename=foo.html",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attabspath
+ { "attachment; filename=\"/foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"/foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#attabspathwin
+ { "attachment; filename=\"\\\\foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"\\foo.html"
+ },
+ // http://greenbytes.de/tech/tc2231/#dispext
+ { "foobar",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#dispextbadfn
+ { "attachment; example=\"filename=example.txt\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L""
+ },
+ // http://greenbytes.de/tech/tc2231/#attnewandfn
+ { "attachment; foobar=x; filename=\"foo.html\"",
+ net::HttpContentDisposition::ATTACHMENT,
+ L"foo.html"
+ },
+ // TODO(abarth): Add the filename* tests, but check
+ // HttpContentDispositionTest.Filename for overlap.
+ // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047token
+ // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047quoted
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ HttpContentDisposition header(tests[i].header, std::string());
+ EXPECT_EQ(tests[i].expected_type, header.type())
+ << "Failed on input: " << tests[i].header;
+ EXPECT_EQ(tests[i].expected_filename, UTF8ToWide(header.filename()))
+ << "Failed on input: " << tests[i].header;
+ }
+}
+
} // namespace net