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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FetchHeaderListTest.cpp

Issue 2787003002: Fetch API: Stop lowercasing header names. (Closed)
Patch Set: Fix failing tests Created 3 years, 8 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 "modules/fetch/FetchHeaderList.h"
6
7 #include <utility>
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "wtf/StdLibExtras.h"
10 #include "wtf/text/WTFString.h"
11
12 namespace blink {
13 namespace {
14
15 TEST(FetchHeaderListTest, Append) {
16 FetchHeaderList* headerList = FetchHeaderList::create();
17 headerList->append("ConTenT-TyPe", "text/plain");
18 headerList->append("content-type", "application/xml");
19 headerList->append("CONTENT-type", "foo");
20 headerList->append("X-Foo", "bar");
21 const std::pair<String, String> expectedHeaders[] = {
22 std::make_pair("ConTenT-TyPe", "text/plain"),
23 std::make_pair("ConTenT-TyPe", "application/xml"),
24 std::make_pair("ConTenT-TyPe", "foo"), std::make_pair("X-Foo", "bar"),
25 };
26 EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), headerList->size());
27 size_t i = 0;
28 for (const auto& header : headerList->list()) {
29 EXPECT_EQ(expectedHeaders[i].first, header.first);
30 EXPECT_EQ(expectedHeaders[i].second, header.second);
31 ++i;
32 }
33 }
34
35 TEST(FetchHeaderListTest, Set) {
36 FetchHeaderList* headerList = FetchHeaderList::create();
37 headerList->append("ConTenT-TyPe", "text/plain");
38 headerList->append("content-type", "application/xml");
39 headerList->append("CONTENT-type", "foo");
40 headerList->append("X-Foo", "bar");
41 headerList->set("contENT-type", "quux");
42 headerList->set("some-header", "some value");
43 EXPECT_EQ(3U, headerList->size());
44 const std::pair<String, String> expectedHeaders[] = {
45 std::make_pair("ConTenT-TyPe", "quux"),
46 std::make_pair("some-header", "some value"),
47 std::make_pair("X-Foo", "bar"),
48 };
49 EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), headerList->size());
50 size_t i = 0;
51 for (const auto& header : headerList->list()) {
52 EXPECT_EQ(expectedHeaders[i].first, header.first);
53 EXPECT_EQ(expectedHeaders[i].second, header.second);
54 ++i;
55 }
56 }
57
58 TEST(FetchHeaderListTest, Erase) {
59 FetchHeaderList* headerList = FetchHeaderList::create();
60 headerList->remove("foo");
61 EXPECT_EQ(0U, headerList->size());
62 headerList->append("ConTenT-TyPe", "text/plain");
63 headerList->append("content-type", "application/xml");
64 headerList->append("CONTENT-type", "foo");
65 headerList->append("X-Foo", "bar");
66 headerList->remove("content-TYPE");
67 EXPECT_EQ(1U, headerList->size());
68 const std::pair<String, String> expectedHeaders[] = {
69 std::make_pair("X-Foo", "bar"),
70 };
71 EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), headerList->size());
72 size_t i = 0;
73 for (const auto& header : headerList->list()) {
74 EXPECT_EQ(expectedHeaders[i].first, header.first);
75 EXPECT_EQ(expectedHeaders[i].second, header.second);
76 ++i;
77 }
78 }
79
80 TEST(FetchHeaderListTest, Combine) {
81 FetchHeaderList* headerList = FetchHeaderList::create();
82 headerList->append("ConTenT-TyPe", "text/plain");
83 headerList->append("content-type", "application/xml");
84 headerList->append("CONTENT-type", "foo");
85 headerList->append("X-Foo", "bar");
86 String combinedValue;
87 EXPECT_TRUE(headerList->get("X-Foo", combinedValue));
88 EXPECT_EQ("bar", combinedValue);
89 EXPECT_TRUE(headerList->get("content-TYPE", combinedValue));
90 EXPECT_EQ("text/plain,application/xml,foo", combinedValue);
91 }
92
93 // This is going to be removed: see crbug.com/645492.
94 TEST(FetchHeaderListTest, GetAll) {
95 FetchHeaderList* headerList = FetchHeaderList::create();
96 headerList->append("ConTenT-TyPe", "text/plain");
97 headerList->append("content-type", "application/xml");
98 headerList->append("CONTENT-type", "foo");
99 headerList->append("X-Foo", "bar");
100 Vector<String> combinedValues;
101 headerList->getAll("content-TYPE", combinedValues);
102 EXPECT_EQ(Vector<String>({"text/plain", "application/xml", "foo"}),
103 combinedValues);
104 headerList->getAll("x-foo", combinedValues);
105 EXPECT_EQ(Vector<String>({"bar"}), combinedValues);
106 headerList->getAll("Host", combinedValues);
107 EXPECT_TRUE(combinedValues.isEmpty());
108 }
109
110 TEST(FetchHeaderListTest, Contains) {
111 FetchHeaderList* headerList = FetchHeaderList::create();
112 headerList->append("ConTenT-TyPe", "text/plain");
113 headerList->append("content-type", "application/xml");
114 headerList->append("X-Foo", "bar");
115 EXPECT_TRUE(headerList->has("CONTENT-TYPE"));
116 EXPECT_TRUE(headerList->has("X-Foo"));
117 EXPECT_FALSE(headerList->has("X-Bar"));
118 }
119
120 TEST(FetchHeaderListTest, ContainsNonSimpleHeader) {
121 FetchHeaderList* headerList = FetchHeaderList::create();
122 EXPECT_FALSE(headerList->containsNonSimpleHeader());
123
124 headerList->append("Host", "foobar");
125 headerList->append("X-Foo", "bar");
126 EXPECT_TRUE(headerList->containsNonSimpleHeader());
127
128 headerList->clearList();
129 headerList->append("ConTenT-TyPe", "text/plain");
130 headerList->append("content-type", "application/xml");
131 headerList->append("X-Foo", "bar");
132 EXPECT_TRUE(headerList->containsNonSimpleHeader());
133
134 headerList->clearList();
135 headerList->append("ConTenT-TyPe", "multipart/form-data");
136 headerList->append("Accept", "xyz");
137 EXPECT_FALSE(headerList->containsNonSimpleHeader());
138 }
139
140 TEST(FetchHeaderListTest, SortAndCombine) {
141 FetchHeaderList* headerList = FetchHeaderList::create();
142 EXPECT_TRUE(headerList->sortAndCombine().isEmpty());
143 headerList->append("content-type", "multipart/form-data");
144 headerList->append("ConTenT-TyPe", "application/xml");
145 headerList->append("Accept", "XYZ");
146 headerList->append("X-Foo", "bar");
147 const std::pair<String, String> expectedHeaders[] = {
148 std::make_pair("accept", "XYZ"),
149 std::make_pair("content-type", "multipart/form-data,application/xml"),
150 std::make_pair("x-foo", "bar")};
151 const Vector<FetchHeaderList::Header> sortedAndCombined =
152 headerList->sortAndCombine();
153 EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), sortedAndCombined.size());
154 size_t i = 0;
155 for (const auto& headerPair : headerList->sortAndCombine()) {
156 EXPECT_EQ(expectedHeaders[i].first, headerPair.first);
157 EXPECT_EQ(expectedHeaders[i].second, headerPair.second);
158 ++i;
159 }
160 }
161
162 } // namespace
163 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698