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

Side by Side Diff: third_party/WebKit/Source/platform/network/ParsedContentDispositionTest.cpp

Issue 2880543003: Implement a parser for Content-Disposition header fields (Closed)
Patch Set: Rebase Created 3 years, 7 months 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/network/ParsedContentDisposition.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace blink {
10
11 namespace {
12
13 using Mode = ParsedContentDisposition::Mode;
14
15 bool IsValid(const String& input, Mode mode = Mode::kNormal) {
16 return ParsedContentDisposition(input, mode).IsValid();
17 }
18
19 TEST(ParsedContentDispositionTest, TypeWithoutFilename) {
20 ParsedContentDisposition t("attachment");
21
22 EXPECT_TRUE(t.IsValid());
23 EXPECT_EQ("attachment", t.Type());
24 EXPECT_EQ(String(), t.Filename());
25 }
26
27 TEST(ParsedContentDispositionTest, TypeWithFilename) {
28 ParsedContentDisposition t(" attachment ; x=y; filename = file1 ");
29
30 EXPECT_TRUE(t.IsValid());
31 EXPECT_EQ("attachment", t.Type());
32 EXPECT_EQ("file1", t.Filename());
33 }
34
35 TEST(ParsedContentDispositionTest, TypeWithQuotedFilename) {
36 ParsedContentDisposition t("attachment; filename=\"x=y;y=\\\"\\pz; ;;\"");
37
38 EXPECT_TRUE(t.IsValid());
39 EXPECT_EQ("attachment", t.Type());
40 EXPECT_EQ("x=y;y=\"pz; ;;", t.Filename());
41 }
42
43 TEST(ParsedContentDispositionTest, InvalidTypeWithoutFilename) {
44 ParsedContentDisposition t(" ");
45
46 EXPECT_FALSE(t.IsValid());
47 EXPECT_EQ(String(), t.Type());
48 EXPECT_EQ(String(), t.Filename());
49 }
50
51 TEST(ParsedContentDispositionTest, InvalidTypeWithFilename) {
52 ParsedContentDisposition t("/attachment; filename=file1;");
53
54 EXPECT_FALSE(t.IsValid());
55 EXPECT_EQ(String(), t.Type());
56 EXPECT_EQ(String(), t.Filename());
57 }
58
59 TEST(ParsedContentDispositionTest, CaseInsensitiveFilename) {
60 ParsedContentDisposition t("attachment; fIlEnAmE=file1");
61
62 EXPECT_TRUE(t.IsValid());
63 EXPECT_EQ("attachment", t.Type());
64 EXPECT_EQ("file1", t.Filename());
65 }
66
67 TEST(ParsedContentDispositionTest, Validity) {
68 EXPECT_TRUE(IsValid("attachment"));
69 EXPECT_TRUE(IsValid("attachment; filename=file1"));
70 EXPECT_TRUE(IsValid("attachment; filename*=UTF-8'en'file1"));
71 EXPECT_TRUE(IsValid(" attachment ;filename=file1 "));
72 EXPECT_TRUE(IsValid(" attachment "));
73 EXPECT_TRUE(IsValid("unknown-unknown"));
74 EXPECT_TRUE(IsValid("unknown-unknown; unknown=unknown"));
75
76 EXPECT_FALSE(IsValid("A/B"));
77 EXPECT_FALSE(IsValid("attachment\r"));
78 EXPECT_FALSE(IsValid("attachment\n"));
79 EXPECT_FALSE(IsValid("attachment filename=file1"));
80 EXPECT_FALSE(IsValid("attachment;filename=file1;"));
81 EXPECT_FALSE(IsValid(""));
82 EXPECT_FALSE(IsValid(" "));
83 EXPECT_FALSE(IsValid("\"x\""));
84 EXPECT_FALSE(IsValid("attachment;"));
85 EXPECT_FALSE(IsValid("attachment; "));
86 EXPECT_FALSE(IsValid("attachment; filename"));
87 EXPECT_FALSE(IsValid("attachment; filename;"));
88 }
89
90 } // namespace
91
92 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698