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..944ac77e60e5e6b23f1d185520c4c1ecf926b681 |
--- /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 "testing/gtest/include/gtest/gtest.h" |
+#include "wtf/StdLibExtras.h" |
+#include "wtf/text/WTFString.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 |