OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "HTTPParsers.h" | 6 #include "HTTPParsers.h" |
7 | 7 |
8 #include "wtf/MathExtras.h" | 8 #include "wtf/MathExtras.h" |
9 #include "wtf/testing/WTFTestHelpers.h" | 9 #include "wtf/testing/WTFTestHelpers.h" |
10 #include "wtf/text/AtomicString.h" | 10 #include "wtf/text/AtomicString.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 EXPECT_TRUE(header.containsNoCache); | 101 EXPECT_TRUE(header.containsNoCache); |
102 EXPECT_FALSE(header.containsNoStore); | 102 EXPECT_FALSE(header.containsNoStore); |
103 EXPECT_FALSE(header.containsMustRevalidate); | 103 EXPECT_FALSE(header.containsMustRevalidate); |
104 EXPECT_TRUE(std::isnan(header.maxAge)); | 104 EXPECT_TRUE(std::isnan(header.maxAge)); |
105 } | 105 } |
106 | 106 |
107 TEST(HTTPParsersTest, parseHTTPHeaderSimple) | 107 TEST(HTTPParsersTest, parseHTTPHeaderSimple) |
108 { | 108 { |
109 String failureReason; | 109 String failureReason; |
110 AtomicString name, value; | 110 AtomicString name, value; |
111 EXPECT_EQ(11u, parseHTTPHeader("foo: bar\r\notherdata", failureReason, nam
e, value)); | 111 EXPECT_EQ(12u, parseHTTPHeader("foo: bar\r\notherdata", failureReason, nam
e, value)); |
112 EXPECT_TRUE(failureReason.isEmpty()); | 112 EXPECT_TRUE(failureReason.isEmpty()); |
113 EXPECT_EQ("foo", name.string()); | 113 EXPECT_EQ("foo", name.string()); |
114 EXPECT_EQ("bar", value.string()); | 114 EXPECT_EQ("bar", value.string()); |
115 } | 115 } |
116 | 116 |
117 TEST(HTTPParsersTest, parseHTTPHeaderEmptyName) | 117 TEST(HTTPParsersTest, parseHTTPHeaderEmptyName) |
118 { | 118 { |
119 String failureReason; | 119 String failureReason; |
120 AtomicString name, value; | 120 AtomicString name, value; |
121 EXPECT_EQ(0u, parseHTTPHeader(": bar\r\notherdata", failureReason, name, val
ue)); | 121 EXPECT_EQ(0u, parseHTTPHeader(": bar\r\notherdata", failureReason, name, val
ue)); |
122 EXPECT_EQ("Header name is missing", failureReason); | 122 EXPECT_EQ("Header name is missing", failureReason); |
123 } | 123 } |
124 | 124 |
125 TEST(HTTPParsersTest, parseHTTPHeaderEmptyValue) | 125 TEST(HTTPParsersTest, parseHTTPHeaderEmptyValue) |
126 { | 126 { |
127 String failureReason; | 127 String failureReason; |
128 AtomicString name, value; | 128 AtomicString name, value; |
129 EXPECT_EQ(6u, parseHTTPHeader("foo: \r\notherdata", failureReason, name, val
ue)); | 129 EXPECT_EQ(7u, parseHTTPHeader("foo: \r\notherdata", failureReason, name, val
ue)); |
130 EXPECT_TRUE(failureReason.isEmpty()); | 130 EXPECT_TRUE(failureReason.isEmpty()); |
131 EXPECT_EQ("foo", name.string()); | 131 EXPECT_EQ("foo", name.string()); |
132 EXPECT_TRUE(value.isEmpty()); | 132 EXPECT_TRUE(value.isEmpty()); |
133 } | 133 } |
134 | 134 |
135 TEST(HTTPParsersTest, parseHTTPHeaderInvalidName) | 135 TEST(HTTPParsersTest, parseHTTPHeaderInvalidName) |
136 { | 136 { |
137 String failureReason; | 137 String failureReason; |
138 AtomicString name, value; | 138 AtomicString name, value; |
139 EXPECT_EQ(0u, parseHTTPHeader("\xfa: \r\notherdata", failureReason, name, va
lue)); | 139 EXPECT_EQ(0u, parseHTTPHeader("\xfa: \r\notherdata", failureReason, name, va
lue)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 EXPECT_EQ(0u, parseHTTPHeader("foo: bar\rhoge\r\n", failureReason, name, val
ue)); | 205 EXPECT_EQ(0u, parseHTTPHeader("foo: bar\rhoge\r\n", failureReason, name, val
ue)); |
206 EXPECT_EQ("LF doesn't follow CR after value at hoge\r\n", failureReason); | 206 EXPECT_EQ("LF doesn't follow CR after value at hoge\r\n", failureReason); |
207 } | 207 } |
208 | 208 |
209 TEST(HTTPParsersTest, parseHTTPHeaderTwoLines) | 209 TEST(HTTPParsersTest, parseHTTPHeaderTwoLines) |
210 { | 210 { |
211 const char data[] = "foo: bar\r\nhoge: fuga\r\nxxx"; | 211 const char data[] = "foo: bar\r\nhoge: fuga\r\nxxx"; |
212 String failureReason; | 212 String failureReason; |
213 AtomicString name, value; | 213 AtomicString name, value; |
214 | 214 |
215 EXPECT_EQ(9u, parseHTTPHeader(data, failureReason, name, value)); | 215 EXPECT_EQ(10u, parseHTTPHeader(data, failureReason, name, value)); |
216 EXPECT_TRUE(failureReason.isEmpty()); | 216 EXPECT_TRUE(failureReason.isEmpty()); |
217 EXPECT_EQ("foo", name.string()); | 217 EXPECT_EQ("foo", name.string()); |
218 EXPECT_EQ("bar", value.string()); | 218 EXPECT_EQ("bar", value.string()); |
219 | 219 |
220 EXPECT_EQ(11u, parseHTTPHeader(data + 10, failureReason, name, value)); | 220 EXPECT_EQ(12u, parseHTTPHeader(data + 10, failureReason, name, value)); |
221 EXPECT_TRUE(failureReason.isEmpty()); | 221 EXPECT_TRUE(failureReason.isEmpty()); |
222 EXPECT_EQ("hoge", name.string()); | 222 EXPECT_EQ("hoge", name.string()); |
223 EXPECT_EQ("fuga", value.string()); | 223 EXPECT_EQ("fuga", value.string()); |
224 } | 224 } |
225 | 225 |
226 } // namespace WebCore | 226 } // namespace WebCore |
227 | 227 |
OLD | NEW |