Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: net/http/http_response_headers_unittest.cc

Issue 4660009: Remove "using namespace std" which is illegal per style guide.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 using namespace std;
14 using base::Time;
15 using net::HttpResponseHeaders;
16 using net::HttpVersion;
17
18 namespace { 13 namespace {
19 14
20 struct TestData { 15 struct TestData {
21 const char* raw_headers; 16 const char* raw_headers;
22 const char* expected_headers; 17 const char* expected_headers;
23 int expected_response_code; 18 int expected_response_code;
24 HttpVersion expected_parsed_version; 19 net::HttpVersion expected_parsed_version;
25 HttpVersion expected_version; 20 net::HttpVersion expected_version;
26 }; 21 };
27 22
28 struct ContentTypeTestData { 23 struct ContentTypeTestData {
29 const string raw_headers; 24 const std::string raw_headers;
30 const string mime_type; 25 const std::string mime_type;
31 const bool has_mimetype; 26 const bool has_mimetype;
32 const string charset; 27 const std::string charset;
33 const bool has_charset; 28 const bool has_charset;
34 const string all_content_type; 29 const std::string all_content_type;
35 }; 30 };
36 31
37 class HttpResponseHeadersTest : public testing::Test { 32 class HttpResponseHeadersTest : public testing::Test {
38 }; 33 };
39 34
40 // Transform "normal"-looking headers (\n-separated) to the appropriate 35 // Transform "normal"-looking headers (\n-separated) to the appropriate
41 // input format for ParseRawHeaders (\0-separated). 36 // input format for ParseRawHeaders (\0-separated).
42 void HeadersToRaw(std::string* headers) { 37 void HeadersToRaw(std::string* headers) {
43 replace(headers->begin(), headers->end(), '\n', '\0'); 38 replace(headers->begin(), headers->end(), '\n', '\0');
44 if (!headers->empty()) 39 if (!headers->empty())
45 *headers += '\0'; 40 *headers += '\0';
46 } 41 }
47 42
48 void TestCommon(const TestData& test) { 43 void TestCommon(const TestData& test) {
49 string raw_headers(test.raw_headers); 44 std::string raw_headers(test.raw_headers);
50 HeadersToRaw(&raw_headers); 45 HeadersToRaw(&raw_headers);
51 string expected_headers(test.expected_headers); 46 std::string expected_headers(test.expected_headers);
52 47
53 string headers; 48 std::string headers;
54 scoped_refptr<HttpResponseHeaders> parsed( 49 scoped_refptr<net::HttpResponseHeaders> parsed(
55 new HttpResponseHeaders(raw_headers)); 50 new net::HttpResponseHeaders(raw_headers));
56 parsed->GetNormalizedHeaders(&headers); 51 parsed->GetNormalizedHeaders(&headers);
57 52
58 // Transform to readable output format (so it's easier to see diffs). 53 // Transform to readable output format (so it's easier to see diffs).
59 replace(headers.begin(), headers.end(), ' ', '_'); 54 replace(headers.begin(), headers.end(), ' ', '_');
60 replace(headers.begin(), headers.end(), '\n', '\\'); 55 replace(headers.begin(), headers.end(), '\n', '\\');
61 replace(expected_headers.begin(), expected_headers.end(), ' ', '_'); 56 replace(expected_headers.begin(), expected_headers.end(), ' ', '_');
62 replace(expected_headers.begin(), expected_headers.end(), '\n', '\\'); 57 replace(expected_headers.begin(), expected_headers.end(), '\n', '\\');
63 58
64 EXPECT_EQ(expected_headers, headers); 59 EXPECT_EQ(expected_headers, headers);
65 60
(...skipping 11 matching lines...) Expand all
77 "HTTP/1.1 202 Accepted \n" 72 "HTTP/1.1 202 Accepted \n"
78 "Content-TYPE : text/html; charset=utf-8 \n" 73 "Content-TYPE : text/html; charset=utf-8 \n"
79 "Set-Cookie: a \n" 74 "Set-Cookie: a \n"
80 "Set-Cookie: b \n", 75 "Set-Cookie: b \n",
81 76
82 "HTTP/1.1 202 Accepted\n" 77 "HTTP/1.1 202 Accepted\n"
83 "Content-TYPE: text/html; charset=utf-8\n" 78 "Content-TYPE: text/html; charset=utf-8\n"
84 "Set-Cookie: a, b\n", 79 "Set-Cookie: a, b\n",
85 80
86 202, 81 202,
87 HttpVersion(1,1), 82 net::HttpVersion(1,1),
88 HttpVersion(1,1) 83 net::HttpVersion(1,1)
89 }; 84 };
90 TestCommon(test); 85 TestCommon(test);
91 } 86 }
92 87
93 // Check that we normalize headers properly (header name is invalid if starts 88 // Check that we normalize headers properly (header name is invalid if starts
94 // with LWS). 89 // with LWS).
95 TEST(HttpResponseHeadersTest, NormalizeHeadersLeadingWhitespace) { 90 TEST(HttpResponseHeadersTest, NormalizeHeadersLeadingWhitespace) {
96 TestData test = { 91 TestData test = {
97 "HTTP/1.1 202 Accepted \n" 92 "HTTP/1.1 202 Accepted \n"
98 // Starts with space -- will be skipped as invalid. 93 // Starts with space -- will be skipped as invalid.
99 " Content-TYPE : text/html; charset=utf-8 \n" 94 " Content-TYPE : text/html; charset=utf-8 \n"
100 "Set-Cookie: a \n" 95 "Set-Cookie: a \n"
101 "Set-Cookie: b \n", 96 "Set-Cookie: b \n",
102 97
103 "HTTP/1.1 202 Accepted\n" 98 "HTTP/1.1 202 Accepted\n"
104 "Set-Cookie: a, b\n", 99 "Set-Cookie: a, b\n",
105 100
106 202, 101 202,
107 HttpVersion(1,1), 102 net::HttpVersion(1,1),
108 HttpVersion(1,1) 103 net::HttpVersion(1,1)
109 }; 104 };
110 TestCommon(test); 105 TestCommon(test);
111 } 106 }
112 107
113 TEST(HttpResponseHeadersTest, BlankHeaders) { 108 TEST(HttpResponseHeadersTest, BlankHeaders) {
114 TestData test = { 109 TestData test = {
115 "HTTP/1.1 200 OK\n" 110 "HTTP/1.1 200 OK\n"
116 "Header1 : \n" 111 "Header1 : \n"
117 "Header2: \n" 112 "Header2: \n"
118 "Header3:\n" 113 "Header3:\n"
119 "Header4\n" 114 "Header4\n"
120 "Header5 :\n", 115 "Header5 :\n",
121 116
122 "HTTP/1.1 200 OK\n" 117 "HTTP/1.1 200 OK\n"
123 "Header1: \n" 118 "Header1: \n"
124 "Header2: \n" 119 "Header2: \n"
125 "Header3: \n" 120 "Header3: \n"
126 "Header5: \n", 121 "Header5: \n",
127 122
128 200, 123 200,
129 HttpVersion(1,1), 124 net::HttpVersion(1,1),
130 HttpVersion(1,1) 125 net::HttpVersion(1,1)
131 }; 126 };
132 TestCommon(test); 127 TestCommon(test);
133 } 128 }
134 129
135 TEST(HttpResponseHeadersTest, NormalizeHeadersVersion) { 130 TEST(HttpResponseHeadersTest, NormalizeHeadersVersion) {
136 // Don't believe the http/0.9 version if there are headers! 131 // Don't believe the http/0.9 version if there are headers!
137 TestData test = { 132 TestData test = {
138 "hTtP/0.9 201\n" 133 "hTtP/0.9 201\n"
139 "Content-TYPE: text/html; charset=utf-8\n", 134 "Content-TYPE: text/html; charset=utf-8\n",
140 135
141 "HTTP/1.0 201 OK\n" 136 "HTTP/1.0 201 OK\n"
142 "Content-TYPE: text/html; charset=utf-8\n", 137 "Content-TYPE: text/html; charset=utf-8\n",
143 138
144 201, 139 201,
145 HttpVersion(0,9), 140 net::HttpVersion(0,9),
146 HttpVersion(1,0) 141 net::HttpVersion(1,0)
147 }; 142 };
148 TestCommon(test); 143 TestCommon(test);
149 } 144 }
150 145
151 TEST(HttpResponseHeadersTest, PreserveHttp09) { 146 TEST(HttpResponseHeadersTest, PreserveHttp09) {
152 // Accept the HTTP/0.9 version number if there are no headers. 147 // Accept the HTTP/0.9 version number if there are no headers.
153 // This is how HTTP/0.9 responses get constructed from HttpNetworkTransaction. 148 // This is how HTTP/0.9 responses get constructed from HttpNetworkTransaction.
154 TestData test = { 149 TestData test = {
155 "hTtP/0.9 200 OK\n", 150 "hTtP/0.9 200 OK\n",
156 151
157 "HTTP/0.9 200 OK\n", 152 "HTTP/0.9 200 OK\n",
158 153
159 200, 154 200,
160 HttpVersion(0,9), 155 net::HttpVersion(0,9),
161 HttpVersion(0,9) 156 net::HttpVersion(0,9)
162 }; 157 };
163 TestCommon(test); 158 TestCommon(test);
164 } 159 }
165 160
166 TEST(HttpResponseHeadersTest, NormalizeHeadersMissingOK) { 161 TEST(HttpResponseHeadersTest, NormalizeHeadersMissingOK) {
167 TestData test = { 162 TestData test = {
168 "HTTP/1.1 201\n" 163 "HTTP/1.1 201\n"
169 "Content-TYPE: text/html; charset=utf-8\n", 164 "Content-TYPE: text/html; charset=utf-8\n",
170 165
171 "HTTP/1.1 201 OK\n" 166 "HTTP/1.1 201 OK\n"
172 "Content-TYPE: text/html; charset=utf-8\n", 167 "Content-TYPE: text/html; charset=utf-8\n",
173 168
174 201, 169 201,
175 HttpVersion(1,1), 170 net::HttpVersion(1,1),
176 HttpVersion(1,1) 171 net::HttpVersion(1,1)
177 }; 172 };
178 TestCommon(test); 173 TestCommon(test);
179 } 174 }
180 175
181 TEST(HttpResponseHeadersTest, NormalizeHeadersBadStatus) { 176 TEST(HttpResponseHeadersTest, NormalizeHeadersBadStatus) {
182 TestData test = { 177 TestData test = {
183 "SCREWED_UP_STATUS_LINE\n" 178 "SCREWED_UP_STATUS_LINE\n"
184 "Content-TYPE: text/html; charset=utf-8\n", 179 "Content-TYPE: text/html; charset=utf-8\n",
185 180
186 "HTTP/1.0 200 OK\n" 181 "HTTP/1.0 200 OK\n"
187 "Content-TYPE: text/html; charset=utf-8\n", 182 "Content-TYPE: text/html; charset=utf-8\n",
188 183
189 200, 184 200,
190 HttpVersion(0,0), // Parse error 185 net::HttpVersion(0,0), // Parse error
191 HttpVersion(1,0) 186 net::HttpVersion(1,0)
192 }; 187 };
193 TestCommon(test); 188 TestCommon(test);
194 } 189 }
195 190
196 TEST(HttpResponseHeadersTest, NormalizeHeadersEmpty) { 191 TEST(HttpResponseHeadersTest, NormalizeHeadersEmpty) {
197 TestData test = { 192 TestData test = {
198 "", 193 "",
199 194
200 "HTTP/1.0 200 OK\n", 195 "HTTP/1.0 200 OK\n",
201 196
202 200, 197 200,
203 HttpVersion(0,0), // Parse Error 198 net::HttpVersion(0,0), // Parse Error
204 HttpVersion(1,0) 199 net::HttpVersion(1,0)
205 }; 200 };
206 TestCommon(test); 201 TestCommon(test);
207 } 202 }
208 203
209 TEST(HttpResponseHeadersTest, NormalizeHeadersStartWithColon) { 204 TEST(HttpResponseHeadersTest, NormalizeHeadersStartWithColon) {
210 TestData test = { 205 TestData test = {
211 "HTTP/1.1 202 Accepted \n" 206 "HTTP/1.1 202 Accepted \n"
212 "foo: bar\n" 207 "foo: bar\n"
213 ": a \n" 208 ": a \n"
214 " : b\n" 209 " : b\n"
215 "baz: blat \n", 210 "baz: blat \n",
216 211
217 "HTTP/1.1 202 Accepted\n" 212 "HTTP/1.1 202 Accepted\n"
218 "foo: bar\n" 213 "foo: bar\n"
219 "baz: blat\n", 214 "baz: blat\n",
220 215
221 202, 216 202,
222 HttpVersion(1,1), 217 net::HttpVersion(1,1),
223 HttpVersion(1,1) 218 net::HttpVersion(1,1)
224 }; 219 };
225 TestCommon(test); 220 TestCommon(test);
226 } 221 }
227 222
228 TEST(HttpResponseHeadersTest, NormalizeHeadersStartWithColonAtEOL) { 223 TEST(HttpResponseHeadersTest, NormalizeHeadersStartWithColonAtEOL) {
229 TestData test = { 224 TestData test = {
230 "HTTP/1.1 202 Accepted \n" 225 "HTTP/1.1 202 Accepted \n"
231 "foo: \n" 226 "foo: \n"
232 "bar:\n" 227 "bar:\n"
233 "baz: blat \n" 228 "baz: blat \n"
234 "zip:\n", 229 "zip:\n",
235 230
236 "HTTP/1.1 202 Accepted\n" 231 "HTTP/1.1 202 Accepted\n"
237 "foo: \n" 232 "foo: \n"
238 "bar: \n" 233 "bar: \n"
239 "baz: blat\n" 234 "baz: blat\n"
240 "zip: \n", 235 "zip: \n",
241 236
242 202, 237 202,
243 HttpVersion(1,1), 238 net::HttpVersion(1,1),
244 HttpVersion(1,1) 239 net::HttpVersion(1,1)
245 }; 240 };
246 TestCommon(test); 241 TestCommon(test);
247 } 242 }
248 243
249 TEST(HttpResponseHeadersTest, NormalizeHeadersOfWhitepace) { 244 TEST(HttpResponseHeadersTest, NormalizeHeadersOfWhitepace) {
250 TestData test = { 245 TestData test = {
251 "\n \n", 246 "\n \n",
252 247
253 "HTTP/1.0 200 OK\n", 248 "HTTP/1.0 200 OK\n",
254 249
255 200, 250 200,
256 HttpVersion(0,0), // Parse error 251 net::HttpVersion(0,0), // Parse error
257 HttpVersion(1,0) 252 net::HttpVersion(1,0)
258 }; 253 };
259 TestCommon(test); 254 TestCommon(test);
260 } 255 }
261 256
262 TEST(HttpResponseHeadersTest, RepeatedSetCookie) { 257 TEST(HttpResponseHeadersTest, RepeatedSetCookie) {
263 TestData test = { 258 TestData test = {
264 "HTTP/1.1 200 OK\n" 259 "HTTP/1.1 200 OK\n"
265 "Set-Cookie: x=1\n" 260 "Set-Cookie: x=1\n"
266 "Set-Cookie: y=2\n", 261 "Set-Cookie: y=2\n",
267 262
268 "HTTP/1.1 200 OK\n" 263 "HTTP/1.1 200 OK\n"
269 "Set-Cookie: x=1, y=2\n", 264 "Set-Cookie: x=1, y=2\n",
270 265
271 200, 266 200,
272 HttpVersion(1,1), 267 net::HttpVersion(1,1),
273 HttpVersion(1,1) 268 net::HttpVersion(1,1)
274 }; 269 };
275 TestCommon(test); 270 TestCommon(test);
276 } 271 }
277 272
278 TEST(HttpResponseHeadersTest, GetNormalizedHeader) { 273 TEST(HttpResponseHeadersTest, GetNormalizedHeader) {
279 std::string headers = 274 std::string headers =
280 "HTTP/1.1 200 OK\n" 275 "HTTP/1.1 200 OK\n"
281 "Cache-control: private\n" 276 "Cache-control: private\n"
282 "cache-Control: no-store\n"; 277 "cache-Control: no-store\n";
283 HeadersToRaw(&headers); 278 HeadersToRaw(&headers);
284 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 279 scoped_refptr<net::HttpResponseHeaders> parsed(
280 new net::HttpResponseHeaders(headers));
285 281
286 std::string value; 282 std::string value;
287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value)); 283 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value));
288 EXPECT_EQ("private, no-store", value); 284 EXPECT_EQ("private, no-store", value);
289 } 285 }
290 286
291 TEST(HttpResponseHeadersTest, Persist) { 287 TEST(HttpResponseHeadersTest, Persist) {
292 const struct { 288 const struct {
293 net::HttpResponseHeaders::PersistOptions options; 289 net::HttpResponseHeaders::PersistOptions options;
294 const char* raw_headers; 290 const char* raw_headers;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 437
442 "HTTP/1.1 200 OK\n" 438 "HTTP/1.1 200 OK\n"
443 "Content-Length: 450\n" 439 "Content-Length: 450\n"
444 "Content-Encoding: gzip\n" 440 "Content-Encoding: gzip\n"
445 }, 441 },
446 }; 442 };
447 443
448 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 444 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
449 std::string headers = tests[i].raw_headers; 445 std::string headers = tests[i].raw_headers;
450 HeadersToRaw(&headers); 446 HeadersToRaw(&headers);
451 scoped_refptr<HttpResponseHeaders> parsed1( 447 scoped_refptr<net::HttpResponseHeaders> parsed1(
452 new HttpResponseHeaders(headers)); 448 new net::HttpResponseHeaders(headers));
453 449
454 Pickle pickle; 450 Pickle pickle;
455 parsed1->Persist(&pickle, tests[i].options); 451 parsed1->Persist(&pickle, tests[i].options);
456 452
457 void* iter = NULL; 453 void* iter = NULL;
458 scoped_refptr<HttpResponseHeaders> parsed2( 454 scoped_refptr<net::HttpResponseHeaders> parsed2(
459 new HttpResponseHeaders(pickle, &iter)); 455 new net::HttpResponseHeaders(pickle, &iter));
460 456
461 std::string h2; 457 std::string h2;
462 parsed2->GetNormalizedHeaders(&h2); 458 parsed2->GetNormalizedHeaders(&h2);
463 EXPECT_EQ(string(tests[i].expected_headers), h2); 459 EXPECT_EQ(std::string(tests[i].expected_headers), h2);
464 } 460 }
465 } 461 }
466 462
467 TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) { 463 TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) {
468 // Ensure that commas in quoted strings are not regarded as value separators. 464 // Ensure that commas in quoted strings are not regarded as value separators.
469 // Ensure that whitespace following a value is trimmed properly 465 // Ensure that whitespace following a value is trimmed properly
470 std::string headers = 466 std::string headers =
471 "HTTP/1.1 200 OK\n" 467 "HTTP/1.1 200 OK\n"
472 "Cache-control:private , no-cache=\"set-cookie,server\" \n" 468 "Cache-control:private , no-cache=\"set-cookie,server\" \n"
473 "cache-Control: no-store\n"; 469 "cache-Control: no-store\n";
474 HeadersToRaw(&headers); 470 HeadersToRaw(&headers);
475 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 471 scoped_refptr<net::HttpResponseHeaders> parsed(
472 new net::HttpResponseHeaders(headers));
476 473
477 void* iter = NULL; 474 void* iter = NULL;
478 std::string value; 475 std::string value;
479 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 476 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
480 EXPECT_EQ("private", value); 477 EXPECT_EQ("private", value);
481 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 478 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
482 EXPECT_EQ("no-cache=\"set-cookie,server\"", value); 479 EXPECT_EQ("no-cache=\"set-cookie,server\"", value);
483 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 480 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value));
484 EXPECT_EQ("no-store", value); 481 EXPECT_EQ("no-store", value);
485 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "cache-control", &value)); 482 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "cache-control", &value));
486 } 483 }
487 484
488 TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) { 485 TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) {
489 // Even though WWW-Authenticate has commas, it should not be treated as 486 // Even though WWW-Authenticate has commas, it should not be treated as
490 // coalesced values. 487 // coalesced values.
491 std::string headers = 488 std::string headers =
492 "HTTP/1.1 401 OK\n" 489 "HTTP/1.1 401 OK\n"
493 "WWW-Authenticate:Digest realm=foobar, nonce=x, domain=y\n" 490 "WWW-Authenticate:Digest realm=foobar, nonce=x, domain=y\n"
494 "WWW-Authenticate:Basic realm=quatar\n"; 491 "WWW-Authenticate:Basic realm=quatar\n";
495 HeadersToRaw(&headers); 492 HeadersToRaw(&headers);
496 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 493 scoped_refptr<net::HttpResponseHeaders> parsed(
494 new net::HttpResponseHeaders(headers));
497 495
498 void* iter = NULL; 496 void* iter = NULL;
499 std::string value; 497 std::string value;
500 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); 498 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
501 EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value); 499 EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value);
502 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); 500 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
503 EXPECT_EQ("Basic realm=quatar", value); 501 EXPECT_EQ("Basic realm=quatar", value);
504 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); 502 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value));
505 } 503 }
506 504
507 TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) { 505 TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) {
508 // The comma in a date valued header should not be treated as a 506 // The comma in a date valued header should not be treated as a
509 // field-value separator 507 // field-value separator
510 std::string headers = 508 std::string headers =
511 "HTTP/1.1 200 OK\n" 509 "HTTP/1.1 200 OK\n"
512 "Date: Tue, 07 Aug 2007 23:10:55 GMT\n" 510 "Date: Tue, 07 Aug 2007 23:10:55 GMT\n"
513 "Last-Modified: Wed, 01 Aug 2007 23:23:45 GMT\n"; 511 "Last-Modified: Wed, 01 Aug 2007 23:23:45 GMT\n";
514 HeadersToRaw(&headers); 512 HeadersToRaw(&headers);
515 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 513 scoped_refptr<net::HttpResponseHeaders> parsed(
514 new net::HttpResponseHeaders(headers));
516 515
517 std::string value; 516 std::string value;
518 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "date", &value)); 517 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "date", &value));
519 EXPECT_EQ("Tue, 07 Aug 2007 23:10:55 GMT", value); 518 EXPECT_EQ("Tue, 07 Aug 2007 23:10:55 GMT", value);
520 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "last-modified", &value)); 519 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "last-modified", &value));
521 EXPECT_EQ("Wed, 01 Aug 2007 23:23:45 GMT", value); 520 EXPECT_EQ("Wed, 01 Aug 2007 23:23:45 GMT", value);
522 } 521 }
523 522
524 TEST(HttpResponseHeadersTest, GetMimeType) { 523 TEST(HttpResponseHeadersTest, GetMimeType) {
525 const ContentTypeTestData tests[] = { 524 const ContentTypeTestData tests[] = {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 "texthtml" }, 646 "texthtml" },
648 // Invalid media type: */* 647 // Invalid media type: */*
649 { "HTTP/1.1 200 OK\n" 648 { "HTTP/1.1 200 OK\n"
650 "Content-type: */*\n", 649 "Content-type: */*\n",
651 "", false, 650 "", false,
652 "", false, 651 "", false,
653 "*/*" }, 652 "*/*" },
654 }; 653 };
655 654
656 for (size_t i = 0; i < arraysize(tests); ++i) { 655 for (size_t i = 0; i < arraysize(tests); ++i) {
657 string headers(tests[i].raw_headers); 656 std::string headers(tests[i].raw_headers);
658 HeadersToRaw(&headers); 657 HeadersToRaw(&headers);
659 scoped_refptr<HttpResponseHeaders> parsed( 658 scoped_refptr<net::HttpResponseHeaders> parsed(
660 new HttpResponseHeaders(headers)); 659 new net::HttpResponseHeaders(headers));
661 660
662 std::string value; 661 std::string value;
663 EXPECT_EQ(tests[i].has_mimetype, parsed->GetMimeType(&value)); 662 EXPECT_EQ(tests[i].has_mimetype, parsed->GetMimeType(&value));
664 EXPECT_EQ(tests[i].mime_type, value); 663 EXPECT_EQ(tests[i].mime_type, value);
665 value.clear(); 664 value.clear();
666 EXPECT_EQ(tests[i].has_charset, parsed->GetCharset(&value)); 665 EXPECT_EQ(tests[i].has_charset, parsed->GetCharset(&value));
667 EXPECT_EQ(tests[i].charset, value); 666 EXPECT_EQ(tests[i].charset, value);
668 EXPECT_TRUE(parsed->GetNormalizedHeader("content-type", &value)); 667 EXPECT_TRUE(parsed->GetNormalizedHeader("content-type", &value));
669 EXPECT_EQ(tests[i].all_content_type, value); 668 EXPECT_EQ(tests[i].all_content_type, value);
670 } 669 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 // pragma: no-cache overrides last-modified heuristic 791 // pragma: no-cache overrides last-modified heuristic
793 { "HTTP/1.1 200 OK\n" 792 { "HTTP/1.1 200 OK\n"
794 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" 793 "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
795 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" 794 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n"
796 "pragma: no-cache\n" 795 "pragma: no-cache\n"
797 "\n", 796 "\n",
798 true 797 true
799 }, 798 },
800 // TODO(darin): add many many more tests here 799 // TODO(darin): add many many more tests here
801 }; 800 };
802 Time request_time, response_time, current_time; 801 base::Time request_time, response_time, current_time;
803 Time::FromString(L"Wed, 28 Nov 2007 00:40:09 GMT", &request_time); 802 base::Time::FromString(L"Wed, 28 Nov 2007 00:40:09 GMT", &request_time);
804 Time::FromString(L"Wed, 28 Nov 2007 00:40:12 GMT", &response_time); 803 base::Time::FromString(L"Wed, 28 Nov 2007 00:40:12 GMT", &response_time);
805 Time::FromString(L"Wed, 28 Nov 2007 00:45:20 GMT", &current_time); 804 base::Time::FromString(L"Wed, 28 Nov 2007 00:45:20 GMT", &current_time);
806 805
807 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 806 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
808 string headers(tests[i].headers); 807 std::string headers(tests[i].headers);
809 HeadersToRaw(&headers); 808 HeadersToRaw(&headers);
810 scoped_refptr<HttpResponseHeaders> parsed( 809 scoped_refptr<net::HttpResponseHeaders> parsed(
811 new HttpResponseHeaders(headers)); 810 new net::HttpResponseHeaders(headers));
812 811
813 bool requires_validation = 812 bool requires_validation =
814 parsed->RequiresValidation(request_time, response_time, current_time); 813 parsed->RequiresValidation(request_time, response_time, current_time);
815 EXPECT_EQ(tests[i].requires_validation, requires_validation); 814 EXPECT_EQ(tests[i].requires_validation, requires_validation);
816 } 815 }
817 } 816 }
818 817
819 TEST(HttpResponseHeadersTest, Update) { 818 TEST(HttpResponseHeadersTest, Update) {
820 const struct { 819 const struct {
821 const char* orig_headers; 820 const char* orig_headers;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 "connection: keep-alive\n" 861 "connection: keep-alive\n"
863 "Cache-control: max-age=10001 \n", 862 "Cache-control: max-age=10001 \n",
864 863
865 "HTTP/1.1 200 OK\n" 864 "HTTP/1.1 200 OK\n"
866 "Cache-control: max-age=10001\n" 865 "Cache-control: max-age=10001\n"
867 "Content-Length: 450\n" 866 "Content-Length: 450\n"
868 }, 867 },
869 }; 868 };
870 869
871 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 870 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
872 string orig_headers(tests[i].orig_headers); 871 std::string orig_headers(tests[i].orig_headers);
873 HeadersToRaw(&orig_headers); 872 HeadersToRaw(&orig_headers);
874 scoped_refptr<HttpResponseHeaders> parsed( 873 scoped_refptr<net::HttpResponseHeaders> parsed(
875 new HttpResponseHeaders(orig_headers)); 874 new net::HttpResponseHeaders(orig_headers));
876 875
877 string new_headers(tests[i].new_headers); 876 std::string new_headers(tests[i].new_headers);
878 HeadersToRaw(&new_headers); 877 HeadersToRaw(&new_headers);
879 scoped_refptr<HttpResponseHeaders> new_parsed( 878 scoped_refptr<net::HttpResponseHeaders> new_parsed(
880 new HttpResponseHeaders(new_headers)); 879 new net::HttpResponseHeaders(new_headers));
881 880
882 parsed->Update(*new_parsed); 881 parsed->Update(*new_parsed);
883 882
884 string resulting_headers; 883 std::string resulting_headers;
885 parsed->GetNormalizedHeaders(&resulting_headers); 884 parsed->GetNormalizedHeaders(&resulting_headers);
886 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); 885 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
887 } 886 }
888 } 887 }
889 888
890 TEST(HttpResponseHeadersTest, EnumerateHeaderLines) { 889 TEST(HttpResponseHeadersTest, EnumerateHeaderLines) {
891 const struct { 890 const struct {
892 const char* headers; 891 const char* headers;
893 const char* expected_lines; 892 const char* expected_lines;
894 } tests[] = { 893 } tests[] = {
895 { "HTTP/1.1 200 OK\n", 894 { "HTTP/1.1 200 OK\n",
896 895
(...skipping 11 matching lines...) Expand all
908 907
909 "Foo: 1\nBar: 2\nFoo: 3\n" 908 "Foo: 1\nBar: 2\nFoo: 3\n"
910 }, 909 },
911 { "HTTP/1.1 200 OK\n" 910 { "HTTP/1.1 200 OK\n"
912 "Foo: 1, 2, 3\n", 911 "Foo: 1, 2, 3\n",
913 912
914 "Foo: 1, 2, 3\n" 913 "Foo: 1, 2, 3\n"
915 }, 914 },
916 }; 915 };
917 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 916 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
918 string headers(tests[i].headers); 917 std::string headers(tests[i].headers);
919 HeadersToRaw(&headers); 918 HeadersToRaw(&headers);
920 scoped_refptr<HttpResponseHeaders> parsed( 919 scoped_refptr<net::HttpResponseHeaders> parsed(
921 new HttpResponseHeaders(headers)); 920 new net::HttpResponseHeaders(headers));
922 921
923 string name, value, lines; 922 std::string name, value, lines;
924 923
925 void* iter = NULL; 924 void* iter = NULL;
926 while (parsed->EnumerateHeaderLines(&iter, &name, &value)) { 925 while (parsed->EnumerateHeaderLines(&iter, &name, &value)) {
927 lines.append(name); 926 lines.append(name);
928 lines.append(": "); 927 lines.append(": ");
929 lines.append(value); 928 lines.append(value);
930 lines.append("\n"); 929 lines.append("\n");
931 } 930 }
932 931
933 EXPECT_EQ(string(tests[i].expected_lines), lines); 932 EXPECT_EQ(std::string(tests[i].expected_lines), lines);
934 } 933 }
935 } 934 }
936 935
937 TEST(HttpResponseHeadersTest, IsRedirect) { 936 TEST(HttpResponseHeadersTest, IsRedirect) {
938 const struct { 937 const struct {
939 const char* headers; 938 const char* headers;
940 const char* location; 939 const char* location;
941 bool is_redirect; 940 bool is_redirect;
942 } tests[] = { 941 } tests[] = {
943 { "HTTP/1.1 200 OK\n", 942 { "HTTP/1.1 200 OK\n",
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 "http://foo/bar?key=%82@%BD%C4", 991 "http://foo/bar?key=%82@%BD%C4",
993 true 992 true
994 }, 993 },
995 { "HTTP/1.1 301 Moved\n" 994 { "HTTP/1.1 301 Moved\n"
996 "Location: http://foo/bar?key=\x83\x5C\x82\x5D\xCB\xD7\n", 995 "Location: http://foo/bar?key=\x83\x5C\x82\x5D\xCB\xD7\n",
997 "http://foo/bar?key=%83\\%82]%CB%D7", 996 "http://foo/bar?key=%83\\%82]%CB%D7",
998 true 997 true
999 }, 998 },
1000 }; 999 };
1001 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1000 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1002 string headers(tests[i].headers); 1001 std::string headers(tests[i].headers);
1003 HeadersToRaw(&headers); 1002 HeadersToRaw(&headers);
1004 scoped_refptr<HttpResponseHeaders> parsed( 1003 scoped_refptr<net::HttpResponseHeaders> parsed(
1005 new HttpResponseHeaders(headers)); 1004 new net::HttpResponseHeaders(headers));
1006 1005
1007 std::string location; 1006 std::string location;
1008 EXPECT_EQ(parsed->IsRedirect(&location), tests[i].is_redirect); 1007 EXPECT_EQ(parsed->IsRedirect(&location), tests[i].is_redirect);
1009 EXPECT_EQ(location, tests[i].location); 1008 EXPECT_EQ(location, tests[i].location);
1010 } 1009 }
1011 } 1010 }
1012 1011
1013 TEST(HttpResponseHeadersTest, GetContentLength) { 1012 TEST(HttpResponseHeadersTest, GetContentLength) {
1014 const struct { 1013 const struct {
1015 const char* headers; 1014 const char* headers;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 { "HTTP/1.1 200 OK\n" 1077 { "HTTP/1.1 200 OK\n"
1079 "cOnTeNt-LENgth: 33\n", 1078 "cOnTeNt-LENgth: 33\n",
1080 33 1079 33
1081 }, 1080 },
1082 { "HTTP/1.1 200 OK\n" 1081 { "HTTP/1.1 200 OK\n"
1083 "Content-Length: 34\r\n", 1082 "Content-Length: 34\r\n",
1084 -1 1083 -1
1085 }, 1084 },
1086 }; 1085 };
1087 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1086 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1088 string headers(tests[i].headers); 1087 std::string headers(tests[i].headers);
1089 HeadersToRaw(&headers); 1088 HeadersToRaw(&headers);
1090 scoped_refptr<HttpResponseHeaders> parsed( 1089 scoped_refptr<net::HttpResponseHeaders> parsed(
1091 new HttpResponseHeaders(headers)); 1090 new net::HttpResponseHeaders(headers));
1092 1091
1093 EXPECT_EQ(tests[i].expected_len, parsed->GetContentLength()); 1092 EXPECT_EQ(tests[i].expected_len, parsed->GetContentLength());
1094 } 1093 }
1095 } 1094 }
1096 1095
1097 TEST(HttpResponseHeaders, GetContentRange) { 1096 TEST(HttpResponseHeaders, GetContentRange) {
1098 const struct { 1097 const struct {
1099 const char* headers; 1098 const char* headers;
1100 bool expected_return_value; 1099 bool expected_return_value;
1101 int64 expected_first_byte_position; 1100 int64 expected_first_byte_position;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 }, 1328 },
1330 { "HTTP/1.1 206 Partial Content\n" 1329 { "HTTP/1.1 206 Partial Content\n"
1331 "Content-Range: bytes -123 - -1/100", 1330 "Content-Range: bytes -123 - -1/100",
1332 false, 1331 false,
1333 -1, 1332 -1,
1334 -1, 1333 -1,
1335 -1 1334 -1
1336 }, 1335 },
1337 }; 1336 };
1338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1337 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1339 string headers(tests[i].headers); 1338 std::string headers(tests[i].headers);
1340 HeadersToRaw(&headers); 1339 HeadersToRaw(&headers);
1341 scoped_refptr<HttpResponseHeaders> parsed( 1340 scoped_refptr<net::HttpResponseHeaders> parsed(
1342 new HttpResponseHeaders(headers)); 1341 new net::HttpResponseHeaders(headers));
1343 1342
1344 int64 first_byte_position; 1343 int64 first_byte_position;
1345 int64 last_byte_position; 1344 int64 last_byte_position;
1346 int64 instance_size; 1345 int64 instance_size;
1347 bool return_value = parsed->GetContentRange(&first_byte_position, 1346 bool return_value = parsed->GetContentRange(&first_byte_position,
1348 &last_byte_position, 1347 &last_byte_position,
1349 &instance_size); 1348 &instance_size);
1350 EXPECT_EQ(tests[i].expected_return_value, return_value); 1349 EXPECT_EQ(tests[i].expected_return_value, return_value);
1351 EXPECT_EQ(tests[i].expected_first_byte_position, first_byte_position); 1350 EXPECT_EQ(tests[i].expected_first_byte_position, first_byte_position);
1352 EXPECT_EQ(tests[i].expected_last_byte_position, last_byte_position); 1351 EXPECT_EQ(tests[i].expected_last_byte_position, last_byte_position);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 { "HTTP/1.1 200 OK\n" 1410 { "HTTP/1.1 200 OK\n"
1412 "proxy-connection: close\n", 1411 "proxy-connection: close\n",
1413 false 1412 false
1414 }, 1413 },
1415 { "HTTP/1.1 200 OK\n" 1414 { "HTTP/1.1 200 OK\n"
1416 "proxy-connection: keep-alive\n", 1415 "proxy-connection: keep-alive\n",
1417 true 1416 true
1418 }, 1417 },
1419 }; 1418 };
1420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1419 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1421 string headers(tests[i].headers); 1420 std::string headers(tests[i].headers);
1422 HeadersToRaw(&headers); 1421 HeadersToRaw(&headers);
1423 scoped_refptr<HttpResponseHeaders> parsed( 1422 scoped_refptr<net::HttpResponseHeaders> parsed(
1424 new HttpResponseHeaders(headers)); 1423 new net::HttpResponseHeaders(headers));
1425 1424
1426 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); 1425 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive());
1427 } 1426 }
1428 } 1427 }
1429 1428
1430 TEST(HttpResponseHeadersTest, HasStrongValidators) { 1429 TEST(HttpResponseHeadersTest, HasStrongValidators) {
1431 const struct { 1430 const struct {
1432 const char* headers; 1431 const char* headers;
1433 bool expected_result; 1432 bool expected_result;
1434 } tests[] = { 1433 } tests[] = {
(...skipping 29 matching lines...) Expand all
1464 { "HTTP/1.1 200 OK\n" 1463 { "HTTP/1.1 200 OK\n"
1465 "etag: w/\"foo\"\n", 1464 "etag: w/\"foo\"\n",
1466 false 1465 false
1467 }, 1466 },
1468 { "HTTP/1.1 200 OK\n" 1467 { "HTTP/1.1 200 OK\n"
1469 "etag: W / \"foo\"\n", 1468 "etag: W / \"foo\"\n",
1470 false 1469 false
1471 } 1470 }
1472 }; 1471 };
1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1472 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1474 string headers(tests[i].headers); 1473 std::string headers(tests[i].headers);
1475 HeadersToRaw(&headers); 1474 HeadersToRaw(&headers);
1476 scoped_refptr<HttpResponseHeaders> parsed( 1475 scoped_refptr<net::HttpResponseHeaders> parsed(
1477 new HttpResponseHeaders(headers)); 1476 new net::HttpResponseHeaders(headers));
1478 1477
1479 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) << 1478 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) <<
1480 "Failed test case " << i; 1479 "Failed test case " << i;
1481 } 1480 }
1482 } 1481 }
1483 1482
1484 TEST(HttpResponseHeadersTest, GetStatusText) { 1483 TEST(HttpResponseHeadersTest, GetStatusText) {
1485 std::string headers("HTTP/1.1 404 Not Found"); 1484 std::string headers("HTTP/1.1 404 Not Found");
1486 HeadersToRaw(&headers); 1485 HeadersToRaw(&headers);
1487 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 1486 scoped_refptr<net::HttpResponseHeaders> parsed(
1487 new net::HttpResponseHeaders(headers));
1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); 1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText());
1489 } 1489 }
1490 1490
1491 TEST(HttpResponseHeadersTest, GetStatusTextMissing) { 1491 TEST(HttpResponseHeadersTest, GetStatusTextMissing) {
1492 std::string headers("HTTP/1.1 404"); 1492 std::string headers("HTTP/1.1 404");
1493 HeadersToRaw(&headers); 1493 HeadersToRaw(&headers);
1494 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 1494 scoped_refptr<net::HttpResponseHeaders> parsed(
1495 new net::HttpResponseHeaders(headers));
1495 // Since the status line gets normalized, we have OK 1496 // Since the status line gets normalized, we have OK
1496 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); 1497 EXPECT_EQ(std::string("OK"), parsed->GetStatusText());
1497 } 1498 }
1498 1499
1499 TEST(HttpResponseHeadersTest, GetStatusTextMultiSpace) { 1500 TEST(HttpResponseHeadersTest, GetStatusTextMultiSpace) {
1500 std::string headers("HTTP/1.0 404 Not Found"); 1501 std::string headers("HTTP/1.0 404 Not Found");
1501 HeadersToRaw(&headers); 1502 HeadersToRaw(&headers);
1502 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 1503 scoped_refptr<net::HttpResponseHeaders> parsed(
1504 new net::HttpResponseHeaders(headers));
1503 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); 1505 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText());
1504 } 1506 }
1505 1507
1506 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { 1508 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) {
1507 std::string headers("Foo bar."); 1509 std::string headers("Foo bar.");
1508 HeadersToRaw(&headers); 1510 HeadersToRaw(&headers);
1509 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 1511 scoped_refptr<net::HttpResponseHeaders> parsed(
1512 new net::HttpResponseHeaders(headers));
1510 // The bad status line would have gotten rewritten as 1513 // The bad status line would have gotten rewritten as
1511 // HTTP/1.0 200 OK. 1514 // HTTP/1.0 200 OK.
1512 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); 1515 EXPECT_EQ(std::string("OK"), parsed->GetStatusText());
1513 } 1516 }
1514 1517
1515 TEST(HttpResponseHeadersTest, AddHeader) { 1518 TEST(HttpResponseHeadersTest, AddHeader) {
1516 const struct { 1519 const struct {
1517 const char* orig_headers; 1520 const char* orig_headers;
1518 const char* new_header; 1521 const char* new_header;
1519 const char* expected_headers; 1522 const char* expected_headers;
(...skipping 16 matching lines...) Expand all
1536 "Content-Length: 450 ", 1539 "Content-Length: 450 ",
1537 1540
1538 "HTTP/1.1 200 OK\n" 1541 "HTTP/1.1 200 OK\n"
1539 "connection: keep-alive\n" 1542 "connection: keep-alive\n"
1540 "Cache-control: max-age=10000\n" 1543 "Cache-control: max-age=10000\n"
1541 "Content-Length: 450\n" 1544 "Content-Length: 450\n"
1542 }, 1545 },
1543 }; 1546 };
1544 1547
1545 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1548 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1546 string orig_headers(tests[i].orig_headers); 1549 std::string orig_headers(tests[i].orig_headers);
1547 HeadersToRaw(&orig_headers); 1550 HeadersToRaw(&orig_headers);
1548 scoped_refptr<HttpResponseHeaders> parsed( 1551 scoped_refptr<net::HttpResponseHeaders> parsed(
1549 new HttpResponseHeaders(orig_headers)); 1552 new net::HttpResponseHeaders(orig_headers));
1550 1553
1551 string new_header(tests[i].new_header); 1554 std::string new_header(tests[i].new_header);
1552 parsed->AddHeader(new_header); 1555 parsed->AddHeader(new_header);
1553 1556
1554 string resulting_headers; 1557 std::string resulting_headers;
1555 parsed->GetNormalizedHeaders(&resulting_headers); 1558 parsed->GetNormalizedHeaders(&resulting_headers);
1556 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); 1559 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1557 } 1560 }
1558 } 1561 }
1559 1562
1560 TEST(HttpResponseHeadersTest, RemoveHeader) { 1563 TEST(HttpResponseHeadersTest, RemoveHeader) {
1561 const struct { 1564 const struct {
1562 const char* orig_headers; 1565 const char* orig_headers;
1563 const char* to_remove; 1566 const char* to_remove;
1564 const char* expected_headers; 1567 const char* expected_headers;
1565 } tests[] = { 1568 } tests[] = {
1566 { "HTTP/1.1 200 OK\n" 1569 { "HTTP/1.1 200 OK\n"
(...skipping 14 matching lines...) Expand all
1581 1584
1582 "Content-Length", 1585 "Content-Length",
1583 1586
1584 "HTTP/1.1 200 OK\n" 1587 "HTTP/1.1 200 OK\n"
1585 "connection: keep-alive\n" 1588 "connection: keep-alive\n"
1586 "Cache-control: max-age=10000\n" 1589 "Cache-control: max-age=10000\n"
1587 }, 1590 },
1588 }; 1591 };
1589 1592
1590 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1593 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1591 string orig_headers(tests[i].orig_headers); 1594 std::string orig_headers(tests[i].orig_headers);
1592 HeadersToRaw(&orig_headers); 1595 HeadersToRaw(&orig_headers);
1593 scoped_refptr<HttpResponseHeaders> parsed( 1596 scoped_refptr<net::HttpResponseHeaders> parsed(
1594 new HttpResponseHeaders(orig_headers)); 1597 new net::HttpResponseHeaders(orig_headers));
1595 1598
1596 string name(tests[i].to_remove); 1599 std::string name(tests[i].to_remove);
1597 parsed->RemoveHeader(name); 1600 parsed->RemoveHeader(name);
1598 1601
1599 string resulting_headers; 1602 std::string resulting_headers;
1600 parsed->GetNormalizedHeaders(&resulting_headers); 1603 parsed->GetNormalizedHeaders(&resulting_headers);
1601 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); 1604 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1602 } 1605 }
1603 } 1606 }
1604 1607
1605 TEST(HttpResponseHeadersTest, ReplaceStatus) { 1608 TEST(HttpResponseHeadersTest, ReplaceStatus) {
1606 const struct { 1609 const struct {
1607 const char* orig_headers; 1610 const char* orig_headers;
1608 const char* new_status; 1611 const char* new_status;
1609 const char* expected_headers; 1612 const char* expected_headers;
1610 } tests[] = { 1613 } tests[] = {
1611 { "HTTP/1.1 206 Partial Content\n" 1614 { "HTTP/1.1 206 Partial Content\n"
(...skipping 24 matching lines...) Expand all
1636 "HTTP/1//1 304 Not Modified", 1639 "HTTP/1//1 304 Not Modified",
1637 1640
1638 "HTTP/1.0 304 Not Modified\n" 1641 "HTTP/1.0 304 Not Modified\n"
1639 "connection: keep-alive\n" 1642 "connection: keep-alive\n"
1640 "Content-Length: 450\n" 1643 "Content-Length: 450\n"
1641 "Cache-control: max-age=10000\n" 1644 "Cache-control: max-age=10000\n"
1642 }, 1645 },
1643 }; 1646 };
1644 1647
1645 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 1648 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
1646 string orig_headers(tests[i].orig_headers); 1649 std::string orig_headers(tests[i].orig_headers);
1647 HeadersToRaw(&orig_headers); 1650 HeadersToRaw(&orig_headers);
1648 scoped_refptr<HttpResponseHeaders> parsed( 1651 scoped_refptr<net::HttpResponseHeaders> parsed(
1649 new HttpResponseHeaders(orig_headers)); 1652 new net::HttpResponseHeaders(orig_headers));
1650 1653
1651 string name(tests[i].new_status); 1654 std::string name(tests[i].new_status);
1652 parsed->ReplaceStatusLine(name); 1655 parsed->ReplaceStatusLine(name);
1653 1656
1654 string resulting_headers; 1657 std::string resulting_headers;
1655 parsed->GetNormalizedHeaders(&resulting_headers); 1658 parsed->GetNormalizedHeaders(&resulting_headers);
1656 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); 1659 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
1657 } 1660 }
1658 } 1661 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698