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

Unified Diff: third_party/WebKit/Source/modules/fetch/FetchHeaderListTest.cpp

Issue 2787003002: Fetch API: Stop lowercasing header names. (Closed)
Patch Set: Rebase for landing 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/fetch/FetchHeaderListTest.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/FetchHeaderListTest.cpp b/third_party/WebKit/Source/modules/fetch/FetchHeaderListTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..70de8233c4790bd0bb8a02d8a886df7541fd5162
--- /dev/null
+++ b/third_party/WebKit/Source/modules/fetch/FetchHeaderListTest.cpp
@@ -0,0 +1,163 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/fetch/FetchHeaderList.h"
+
+#include <utility>
+#include "platform/wtf/StdLibExtras.h"
+#include "platform/wtf/text/WTFString.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+TEST(FetchHeaderListTest, Append) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("CONTENT-type", "foo");
+ headerList->Append("X-Foo", "bar");
+ const std::pair<String, String> expectedHeaders[] = {
+ std::make_pair("ConTenT-TyPe", "text/plain"),
+ std::make_pair("ConTenT-TyPe", "application/xml"),
+ std::make_pair("ConTenT-TyPe", "foo"), std::make_pair("X-Foo", "bar"),
+ };
+ EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), headerList->size());
+ size_t i = 0;
+ for (const auto& header : headerList->List()) {
+ EXPECT_EQ(expectedHeaders[i].first, header.first);
+ EXPECT_EQ(expectedHeaders[i].second, header.second);
+ ++i;
+ }
+}
+
+TEST(FetchHeaderListTest, Set) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("CONTENT-type", "foo");
+ headerList->Append("X-Foo", "bar");
+ headerList->Set("contENT-type", "quux");
+ headerList->Set("some-header", "some value");
+ EXPECT_EQ(3U, headerList->size());
+ const std::pair<String, String> expectedHeaders[] = {
+ std::make_pair("ConTenT-TyPe", "quux"),
+ std::make_pair("some-header", "some value"),
+ std::make_pair("X-Foo", "bar"),
+ };
+ EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), headerList->size());
+ size_t i = 0;
+ for (const auto& header : headerList->List()) {
+ EXPECT_EQ(expectedHeaders[i].first, header.first);
+ EXPECT_EQ(expectedHeaders[i].second, header.second);
+ ++i;
+ }
+}
+
+TEST(FetchHeaderListTest, Erase) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ headerList->Remove("foo");
+ EXPECT_EQ(0U, headerList->size());
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("CONTENT-type", "foo");
+ headerList->Append("X-Foo", "bar");
+ headerList->Remove("content-TYPE");
+ EXPECT_EQ(1U, headerList->size());
+ const std::pair<String, String> expectedHeaders[] = {
+ std::make_pair("X-Foo", "bar"),
+ };
+ EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), headerList->size());
+ size_t i = 0;
+ for (const auto& header : headerList->List()) {
+ EXPECT_EQ(expectedHeaders[i].first, header.first);
+ EXPECT_EQ(expectedHeaders[i].second, header.second);
+ ++i;
+ }
+}
+
+TEST(FetchHeaderListTest, Combine) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("CONTENT-type", "foo");
+ headerList->Append("X-Foo", "bar");
+ String combinedValue;
+ EXPECT_TRUE(headerList->Get("X-Foo", combinedValue));
+ EXPECT_EQ("bar", combinedValue);
+ EXPECT_TRUE(headerList->Get("content-TYPE", combinedValue));
+ EXPECT_EQ("text/plain,application/xml,foo", combinedValue);
+}
+
+// This is going to be removed: see crbug.com/645492.
+TEST(FetchHeaderListTest, GetAll) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("CONTENT-type", "foo");
+ headerList->Append("X-Foo", "bar");
+ Vector<String> combinedValues;
+ headerList->GetAll("content-TYPE", combinedValues);
+ EXPECT_EQ(Vector<String>({"text/plain", "application/xml", "foo"}),
+ combinedValues);
+ headerList->GetAll("x-foo", combinedValues);
+ EXPECT_EQ(Vector<String>({"bar"}), combinedValues);
+ headerList->GetAll("Host", combinedValues);
+ EXPECT_TRUE(combinedValues.IsEmpty());
+}
+
+TEST(FetchHeaderListTest, Contains) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("X-Foo", "bar");
+ EXPECT_TRUE(headerList->Has("CONTENT-TYPE"));
+ EXPECT_TRUE(headerList->Has("X-Foo"));
+ EXPECT_FALSE(headerList->Has("X-Bar"));
+}
+
+TEST(FetchHeaderListTest, ContainsNonSimpleHeader) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ EXPECT_FALSE(headerList->ContainsNonSimpleHeader());
+
+ headerList->Append("Host", "foobar");
+ headerList->Append("X-Foo", "bar");
+ EXPECT_TRUE(headerList->ContainsNonSimpleHeader());
+
+ headerList->ClearList();
+ headerList->Append("ConTenT-TyPe", "text/plain");
+ headerList->Append("content-type", "application/xml");
+ headerList->Append("X-Foo", "bar");
+ EXPECT_TRUE(headerList->ContainsNonSimpleHeader());
+
+ headerList->ClearList();
+ headerList->Append("ConTenT-TyPe", "multipart/form-data");
+ headerList->Append("Accept", "xyz");
+ EXPECT_FALSE(headerList->ContainsNonSimpleHeader());
+}
+
+TEST(FetchHeaderListTest, SortAndCombine) {
+ FetchHeaderList* headerList = FetchHeaderList::Create();
+ EXPECT_TRUE(headerList->SortAndCombine().IsEmpty());
+ headerList->Append("content-type", "multipart/form-data");
+ headerList->Append("ConTenT-TyPe", "application/xml");
+ headerList->Append("Accept", "XYZ");
+ headerList->Append("X-Foo", "bar");
+ const std::pair<String, String> expectedHeaders[] = {
+ std::make_pair("accept", "XYZ"),
+ std::make_pair("content-type", "multipart/form-data,application/xml"),
+ std::make_pair("x-foo", "bar")};
+ const Vector<FetchHeaderList::Header> sortedAndCombined =
+ headerList->SortAndCombine();
+ EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), sortedAndCombined.size());
+ size_t i = 0;
+ for (const auto& headerPair : headerList->SortAndCombine()) {
+ EXPECT_EQ(expectedHeaders[i].first, headerPair.first);
+ EXPECT_EQ(expectedHeaders[i].second, headerPair.second);
+ ++i;
+ }
+}
+
+} // namespace
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp ('k') | third_party/WebKit/Source/modules/fetch/FetchManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698