| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/fetch/FetchHeaderList.h" | 5 #include "modules/fetch/FetchHeaderList.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include "platform/wtf/StdLibExtras.h" | 8 #include "platform/wtf/StdLibExtras.h" |
| 9 #include "platform/wtf/text/WTFString.h" | 9 #include "platform/wtf/text/WTFString.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 TEST(FetchHeaderListTest, Combine) { | 80 TEST(FetchHeaderListTest, Combine) { |
| 81 FetchHeaderList* headerList = FetchHeaderList::Create(); | 81 FetchHeaderList* headerList = FetchHeaderList::Create(); |
| 82 headerList->Append("ConTenT-TyPe", "text/plain"); | 82 headerList->Append("ConTenT-TyPe", "text/plain"); |
| 83 headerList->Append("content-type", "application/xml"); | 83 headerList->Append("content-type", "application/xml"); |
| 84 headerList->Append("CONTENT-type", "foo"); | 84 headerList->Append("CONTENT-type", "foo"); |
| 85 headerList->Append("X-Foo", "bar"); | 85 headerList->Append("X-Foo", "bar"); |
| 86 String combinedValue; | 86 String combinedValue; |
| 87 EXPECT_TRUE(headerList->Get("X-Foo", combinedValue)); | 87 EXPECT_TRUE(headerList->Get("X-Foo", combinedValue)); |
| 88 EXPECT_EQ("bar", combinedValue); | 88 EXPECT_EQ("bar", combinedValue); |
| 89 EXPECT_TRUE(headerList->Get("content-TYPE", combinedValue)); | 89 EXPECT_TRUE(headerList->Get("content-TYPE", combinedValue)); |
| 90 EXPECT_EQ("text/plain,application/xml,foo", combinedValue); | 90 EXPECT_EQ("text/plain, application/xml, foo", combinedValue); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // This is going to be removed: see crbug.com/645492. | 93 // This is going to be removed: see crbug.com/645492. |
| 94 TEST(FetchHeaderListTest, GetAll) { | 94 TEST(FetchHeaderListTest, GetAll) { |
| 95 FetchHeaderList* headerList = FetchHeaderList::Create(); | 95 FetchHeaderList* headerList = FetchHeaderList::Create(); |
| 96 headerList->Append("ConTenT-TyPe", "text/plain"); | 96 headerList->Append("ConTenT-TyPe", "text/plain"); |
| 97 headerList->Append("content-type", "application/xml"); | 97 headerList->Append("content-type", "application/xml"); |
| 98 headerList->Append("CONTENT-type", "foo"); | 98 headerList->Append("CONTENT-type", "foo"); |
| 99 headerList->Append("X-Foo", "bar"); | 99 headerList->Append("X-Foo", "bar"); |
| 100 Vector<String> combinedValues; | 100 Vector<String> combinedValues; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 TEST(FetchHeaderListTest, SortAndCombine) { | 140 TEST(FetchHeaderListTest, SortAndCombine) { |
| 141 FetchHeaderList* headerList = FetchHeaderList::Create(); | 141 FetchHeaderList* headerList = FetchHeaderList::Create(); |
| 142 EXPECT_TRUE(headerList->SortAndCombine().IsEmpty()); | 142 EXPECT_TRUE(headerList->SortAndCombine().IsEmpty()); |
| 143 headerList->Append("content-type", "multipart/form-data"); | 143 headerList->Append("content-type", "multipart/form-data"); |
| 144 headerList->Append("ConTenT-TyPe", "application/xml"); | 144 headerList->Append("ConTenT-TyPe", "application/xml"); |
| 145 headerList->Append("Accept", "XYZ"); | 145 headerList->Append("Accept", "XYZ"); |
| 146 headerList->Append("X-Foo", "bar"); | 146 headerList->Append("X-Foo", "bar"); |
| 147 const std::pair<String, String> expectedHeaders[] = { | 147 const std::pair<String, String> expectedHeaders[] = { |
| 148 std::make_pair("accept", "XYZ"), | 148 std::make_pair("accept", "XYZ"), |
| 149 std::make_pair("content-type", "multipart/form-data,application/xml"), | 149 std::make_pair("content-type", "multipart/form-data, application/xml"), |
| 150 std::make_pair("x-foo", "bar")}; | 150 std::make_pair("x-foo", "bar")}; |
| 151 const Vector<FetchHeaderList::Header> sortedAndCombined = | 151 const Vector<FetchHeaderList::Header> sortedAndCombined = |
| 152 headerList->SortAndCombine(); | 152 headerList->SortAndCombine(); |
| 153 EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), sortedAndCombined.size()); | 153 EXPECT_EQ(WTF_ARRAY_LENGTH(expectedHeaders), sortedAndCombined.size()); |
| 154 size_t i = 0; | 154 size_t i = 0; |
| 155 for (const auto& headerPair : headerList->SortAndCombine()) { | 155 for (const auto& headerPair : headerList->SortAndCombine()) { |
| 156 EXPECT_EQ(expectedHeaders[i].first, headerPair.first); | 156 EXPECT_EQ(expectedHeaders[i].first, headerPair.first); |
| 157 EXPECT_EQ(expectedHeaders[i].second, headerPair.second); | 157 EXPECT_EQ(expectedHeaders[i].second, headerPair.second); |
| 158 ++i; | 158 ++i; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace | 162 } // namespace |
| 163 } // namespace blink | 163 } // namespace blink |
| OLD | NEW |