Chromium Code Reviews| OLD | NEW |
|---|---|
| (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; | |
|
yhirano
2017/04/11 14:03:05
Unused
Raphael Kubo da Costa (rakuco)
2017/04/11 14:22:19
Hm? This is being used to iterate through |expecte
yhirano
2017/04/11 15:05:54
Ah, sorry, I misunderstood.
| |
| 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; | |
|
yhirano
2017/04/11 14:03:05
ditto
| |
| 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; | |
|
yhirano
2017/04/11 14:03:05
ditto
| |
| 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; | |
|
yhirano
2017/04/11 14:03:05
Unused
| |
| 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 | |
| OLD | NEW |