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 "platform/network/HTTPParsers.h" | 5 #include "platform/network/HTTPParsers.h" |
6 | 6 |
7 #include "platform/heap/Handle.h" | 7 #include "platform/heap/Handle.h" |
8 #include "platform/network/ResourceResponse.h" | 8 #include "platform/network/ResourceResponse.h" |
9 #include "platform/weborigin/Suborigin.h" | 9 #include "platform/weborigin/Suborigin.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 EXPECT_FALSE(blink::isValidHTTPToken("()")); | 153 EXPECT_FALSE(blink::isValidHTTPToken("()")); |
154 EXPECT_FALSE(blink::isValidHTTPToken("(foobar)")); | 154 EXPECT_FALSE(blink::isValidHTTPToken("(foobar)")); |
155 EXPECT_FALSE(blink::isValidHTTPToken(String("\0", 1))); | 155 EXPECT_FALSE(blink::isValidHTTPToken(String("\0", 1))); |
156 EXPECT_FALSE(blink::isValidHTTPToken(String(hiraganaA))); | 156 EXPECT_FALSE(blink::isValidHTTPToken(String(hiraganaA))); |
157 } | 157 } |
158 | 158 |
159 TEST(HTTPParsersTest, ExtractMIMETypeFromMediaType) { | 159 TEST(HTTPParsersTest, ExtractMIMETypeFromMediaType) { |
160 const AtomicString textHtml("text/html"); | 160 const AtomicString textHtml("text/html"); |
161 | 161 |
162 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType(AtomicString("text/html"))); | 162 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType(AtomicString("text/html"))); |
163 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType( | 163 EXPECT_EQ(textHtml, |
164 AtomicString("text/html; charset=iso-8859-1"))); | 164 extractMIMETypeFromMediaType( |
| 165 AtomicString("text/html; charset=iso-8859-1"))); |
165 | 166 |
166 // Quoted charset parameter | 167 // Quoted charset parameter |
167 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType( | 168 EXPECT_EQ(textHtml, |
168 AtomicString("text/html; charset=\"quoted\""))); | 169 extractMIMETypeFromMediaType( |
| 170 AtomicString("text/html; charset=\"quoted\""))); |
169 | 171 |
170 // Multiple parameters | 172 // Multiple parameters |
171 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType( | 173 EXPECT_EQ(textHtml, |
172 AtomicString("text/html; charset=x; foo=bar"))); | 174 extractMIMETypeFromMediaType( |
| 175 AtomicString("text/html; charset=x; foo=bar"))); |
173 | 176 |
174 // OWSes are trimmed. | 177 // OWSes are trimmed. |
175 EXPECT_EQ(textHtml, | 178 EXPECT_EQ(textHtml, |
176 extractMIMETypeFromMediaType(AtomicString(" text/html "))); | 179 extractMIMETypeFromMediaType(AtomicString(" text/html "))); |
177 EXPECT_EQ(textHtml, | 180 EXPECT_EQ(textHtml, |
178 extractMIMETypeFromMediaType(AtomicString("\ttext/html \t"))); | 181 extractMIMETypeFromMediaType(AtomicString("\ttext/html \t"))); |
179 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType( | 182 EXPECT_EQ(textHtml, |
180 AtomicString("text/html ; charset=iso-8859-1"))); | 183 extractMIMETypeFromMediaType( |
| 184 AtomicString("text/html ; charset=iso-8859-1"))); |
181 | 185 |
182 // Non-standard multiple type/subtype listing using a comma as a separator | 186 // Non-standard multiple type/subtype listing using a comma as a separator |
183 // is accepted. | 187 // is accepted. |
184 EXPECT_EQ(textHtml, | 188 EXPECT_EQ(textHtml, |
185 extractMIMETypeFromMediaType(AtomicString("text/html,text/plain"))); | 189 extractMIMETypeFromMediaType(AtomicString("text/html,text/plain"))); |
186 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType( | 190 EXPECT_EQ( |
187 AtomicString("text/html , text/plain"))); | 191 textHtml, |
188 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType( | 192 extractMIMETypeFromMediaType(AtomicString("text/html , text/plain"))); |
189 AtomicString("text/html\t,\ttext/plain"))); | 193 EXPECT_EQ( |
190 EXPECT_EQ(textHtml, extractMIMETypeFromMediaType(AtomicString( | 194 textHtml, |
191 "text/html,text/plain;charset=iso-8859-1"))); | 195 extractMIMETypeFromMediaType(AtomicString("text/html\t,\ttext/plain"))); |
| 196 EXPECT_EQ(textHtml, |
| 197 extractMIMETypeFromMediaType( |
| 198 AtomicString("text/html,text/plain;charset=iso-8859-1"))); |
192 | 199 |
193 // Preserves case. | 200 // Preserves case. |
194 EXPECT_EQ("tExt/hTMl", | 201 EXPECT_EQ("tExt/hTMl", |
195 extractMIMETypeFromMediaType(AtomicString("tExt/hTMl"))); | 202 extractMIMETypeFromMediaType(AtomicString("tExt/hTMl"))); |
196 | 203 |
197 EXPECT_EQ(emptyString, | 204 EXPECT_EQ(emptyString, |
198 extractMIMETypeFromMediaType(AtomicString(", text/html"))); | 205 extractMIMETypeFromMediaType(AtomicString(", text/html"))); |
199 EXPECT_EQ(emptyString, | 206 EXPECT_EQ(emptyString, |
200 extractMIMETypeFromMediaType(AtomicString("; text/html"))); | 207 extractMIMETypeFromMediaType(AtomicString("; text/html"))); |
201 | 208 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 parseMultipartHeadersFromBody(data, strlen(data), &response, &end); | 501 parseMultipartHeadersFromBody(data, strlen(data), &response, &end); |
495 | 502 |
496 EXPECT_TRUE(result); | 503 EXPECT_TRUE(result); |
497 EXPECT_EQ(strlen(data), end); | 504 EXPECT_EQ(strlen(data), end); |
498 EXPECT_EQ("text/html; charset=utf-8", | 505 EXPECT_EQ("text/html; charset=utf-8", |
499 response.httpHeaderField("content-type")); | 506 response.httpHeaderField("content-type")); |
500 EXPECT_EQ("utf-8", response.textEncodingName()); | 507 EXPECT_EQ("utf-8", response.textEncodingName()); |
501 } | 508 } |
502 | 509 |
503 } // namespace blink | 510 } // namespace blink |
OLD | NEW |