OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/url_request/url_request_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 return it != haystack.end(); | 76 return it != haystack.end(); |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 81 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
82 class URLRequestTest : public PlatformTest { | 82 class URLRequestTest : public PlatformTest { |
83 }; | 83 }; |
84 | 84 |
85 TEST_F(URLRequestTest, GetTest_NoCache) { | 85 TEST_F(URLRequestTest, GetTest_NoCache) { |
86 scoped_refptr<HTTPTestServer> server = | 86 TestServer server(L""); |
87 HTTPTestServer::CreateServer(L""); | 87 ASSERT_TRUE(server.init_successful()); |
88 ASSERT_TRUE(NULL != server.get()); | |
89 TestDelegate d; | 88 TestDelegate d; |
90 { | 89 { |
91 TestURLRequest r(server->TestServerPage(""), &d); | 90 TestURLRequest r(server.TestServerPage(""), &d); |
92 | 91 |
93 r.Start(); | 92 r.Start(); |
94 EXPECT_TRUE(r.is_pending()); | 93 EXPECT_TRUE(r.is_pending()); |
95 | 94 |
96 MessageLoop::current()->Run(); | 95 MessageLoop::current()->Run(); |
97 | 96 |
98 EXPECT_EQ(1, d.response_started_count()); | 97 EXPECT_EQ(1, d.response_started_count()); |
99 EXPECT_FALSE(d.received_data_before_response()); | 98 EXPECT_FALSE(d.received_data_before_response()); |
100 EXPECT_NE(0, d.bytes_received()); | 99 EXPECT_NE(0, d.bytes_received()); |
101 } | 100 } |
102 #ifndef NDEBUG | 101 #ifndef NDEBUG |
103 DCHECK_EQ(url_request_metrics.object_count,0); | 102 DCHECK_EQ(url_request_metrics.object_count,0); |
104 #endif | 103 #endif |
105 } | 104 } |
106 | 105 |
107 TEST_F(URLRequestTest, GetTest) { | 106 TEST_F(URLRequestTest, GetTest) { |
108 scoped_refptr<HTTPTestServer> server = | 107 TestServer server(L""); |
109 HTTPTestServer::CreateServer(L""); | 108 ASSERT_TRUE(server.init_successful()); |
110 ASSERT_TRUE(NULL != server.get()); | |
111 TestDelegate d; | 109 TestDelegate d; |
112 { | 110 { |
113 TestURLRequest r(server->TestServerPage(""), &d); | 111 TestURLRequest r(server.TestServerPage(""), &d); |
114 | 112 |
115 r.Start(); | 113 r.Start(); |
116 EXPECT_TRUE(r.is_pending()); | 114 EXPECT_TRUE(r.is_pending()); |
117 | 115 |
118 MessageLoop::current()->Run(); | 116 MessageLoop::current()->Run(); |
119 | 117 |
120 EXPECT_EQ(1, d.response_started_count()); | 118 EXPECT_EQ(1, d.response_started_count()); |
121 EXPECT_FALSE(d.received_data_before_response()); | 119 EXPECT_FALSE(d.received_data_before_response()); |
122 EXPECT_NE(0, d.bytes_received()); | 120 EXPECT_NE(0, d.bytes_received()); |
123 } | 121 } |
124 #ifndef NDEBUG | 122 #ifndef NDEBUG |
125 DCHECK_EQ(url_request_metrics.object_count,0); | 123 DCHECK_EQ(url_request_metrics.object_count,0); |
126 #endif | 124 #endif |
127 } | 125 } |
128 | 126 |
129 class HTTPSRequestTest : public testing::Test { | 127 class HTTPSRequestTest : public testing::Test { |
130 protected: | 128 protected: |
131 HTTPSRequestTest() : util_() {}; | 129 HTTPSRequestTest() : util_() {}; |
132 | 130 |
133 SSLTestUtil util_; | 131 SSLTestUtil util_; |
134 }; | 132 }; |
135 | 133 |
136 #if defined(OS_MACOSX) | 134 #if defined(OS_MACOSX) |
137 // TODO(port): support temporary root cert on mac | 135 // TODO(port): support temporary root cert on mac |
138 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest | 136 #define MAYBE_HTTPSGetTest DISABLED_HTTPSGetTest |
139 #else | 137 #else |
140 #define MAYBE_HTTPSGetTest HTTPSGetTest | 138 #define MAYBE_HTTPSGetTest HTTPSGetTest |
141 #endif | 139 #endif |
142 | 140 |
143 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { | 141 TEST_F(HTTPSRequestTest, MAYBE_HTTPSGetTest) { |
144 // Note: tools/testserver/testserver.py does not need | 142 // Note: tools/testserver/testserver.py does not need |
145 // a working document root to server the pages / and /hello.html, | 143 // a working document root to server the pages / and /hello.html, |
146 // so this test doesn't really need to specify a document root. | 144 // so this test doesn't really need to specify a document root. |
147 // But if it did, a good one would be net/data/ssl. | 145 // But if it did, a good one would be net/data/ssl. |
148 scoped_refptr<HTTPSTestServer> server = | 146 HTTPSTestServer https_server(util_.kHostName, util_.kOKHTTPSPort, |
149 HTTPSTestServer::CreateServer(util_.kHostName, util_.kOKHTTPSPort, | 147 L"net/data/ssl", |
150 L"net/data/ssl", util_.GetOKCertPath().ToWStringHack()); | 148 util_.GetOKCertPath().ToWStringHack()); |
151 ASSERT_TRUE(NULL != server.get()); | |
152 | 149 |
153 EXPECT_TRUE(util_.CheckCATrusted()); | 150 EXPECT_TRUE(util_.CheckCATrusted()); |
154 TestDelegate d; | 151 TestDelegate d; |
155 { | 152 { |
156 TestURLRequest r(server->TestServerPage(""), &d); | 153 TestURLRequest r(https_server.TestServerPage(""), &d); |
157 | 154 |
158 r.Start(); | 155 r.Start(); |
159 EXPECT_TRUE(r.is_pending()); | 156 EXPECT_TRUE(r.is_pending()); |
160 | 157 |
161 MessageLoop::current()->Run(); | 158 MessageLoop::current()->Run(); |
162 | 159 |
163 EXPECT_EQ(1, d.response_started_count()); | 160 EXPECT_EQ(1, d.response_started_count()); |
164 EXPECT_FALSE(d.received_data_before_response()); | 161 EXPECT_FALSE(d.received_data_before_response()); |
165 EXPECT_NE(0, d.bytes_received()); | 162 EXPECT_NE(0, d.bytes_received()); |
166 } | 163 } |
(...skipping 19 matching lines...) Expand all Loading... |
186 EXPECT_EQ(1, d.response_started_count()); | 183 EXPECT_EQ(1, d.response_started_count()); |
187 EXPECT_EQ(0, d.bytes_received()); | 184 EXPECT_EQ(0, d.bytes_received()); |
188 EXPECT_FALSE(d.received_data_before_response()); | 185 EXPECT_FALSE(d.received_data_before_response()); |
189 } | 186 } |
190 #ifndef NDEBUG | 187 #ifndef NDEBUG |
191 DCHECK_EQ(url_request_metrics.object_count,0); | 188 DCHECK_EQ(url_request_metrics.object_count,0); |
192 #endif | 189 #endif |
193 } | 190 } |
194 | 191 |
195 TEST_F(URLRequestTest, CancelTest2) { | 192 TEST_F(URLRequestTest, CancelTest2) { |
196 scoped_refptr<HTTPTestServer> server = | 193 TestServer server(L""); |
197 HTTPTestServer::CreateServer(L""); | 194 ASSERT_TRUE(server.init_successful()); |
198 ASSERT_TRUE(NULL != server.get()); | |
199 | |
200 // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' | |
201 // to 'const int' | |
202 | |
203 TestDelegate d; | 195 TestDelegate d; |
204 { | 196 { |
205 TestURLRequest r(server->TestServerPage(""), &d); | 197 TestURLRequest r(server.TestServerPage(""), &d); |
206 | 198 |
207 d.set_cancel_in_response_started(true); | 199 d.set_cancel_in_response_started(true); |
208 | 200 |
209 r.Start(); | 201 r.Start(); |
210 EXPECT_TRUE(r.is_pending()); | 202 EXPECT_TRUE(r.is_pending()); |
211 | 203 |
212 MessageLoop::current()->Run(); | 204 MessageLoop::current()->Run(); |
213 | 205 |
214 EXPECT_EQ(1, d.response_started_count()); | 206 EXPECT_EQ(1, d.response_started_count()); |
215 EXPECT_EQ(0, d.bytes_received()); | 207 EXPECT_EQ(0, d.bytes_received()); |
216 EXPECT_FALSE(d.received_data_before_response()); | 208 EXPECT_FALSE(d.received_data_before_response()); |
217 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 209 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
218 } | 210 } |
219 #ifndef NDEBUG | 211 #ifndef NDEBUG |
220 DCHECK_EQ(url_request_metrics.object_count,0); | 212 DCHECK_EQ(url_request_metrics.object_count,0); |
221 #endif | 213 #endif |
222 } | 214 } |
223 | 215 |
224 TEST_F(URLRequestTest, CancelTest3) { | 216 TEST_F(URLRequestTest, CancelTest3) { |
225 scoped_refptr<HTTPTestServer> server = | 217 TestServer server(L""); |
226 HTTPTestServer::CreateServer(L""); | 218 ASSERT_TRUE(server.init_successful()); |
227 ASSERT_TRUE(NULL != server.get()); | |
228 TestDelegate d; | 219 TestDelegate d; |
229 { | 220 { |
230 TestURLRequest r(server->TestServerPage(""), &d); | 221 TestURLRequest r(server.TestServerPage(""), &d); |
231 | 222 |
232 d.set_cancel_in_received_data(true); | 223 d.set_cancel_in_received_data(true); |
233 | 224 |
234 r.Start(); | 225 r.Start(); |
235 EXPECT_TRUE(r.is_pending()); | 226 EXPECT_TRUE(r.is_pending()); |
236 | 227 |
237 MessageLoop::current()->Run(); | 228 MessageLoop::current()->Run(); |
238 | 229 |
239 EXPECT_EQ(1, d.response_started_count()); | 230 EXPECT_EQ(1, d.response_started_count()); |
240 // There is no guarantee about how much data was received | 231 // There is no guarantee about how much data was received |
241 // before the cancel was issued. It could have been 0 bytes, | 232 // before the cancel was issued. It could have been 0 bytes, |
242 // or it could have been all the bytes. | 233 // or it could have been all the bytes. |
243 // EXPECT_EQ(0, d.bytes_received()); | 234 // EXPECT_EQ(0, d.bytes_received()); |
244 EXPECT_FALSE(d.received_data_before_response()); | 235 EXPECT_FALSE(d.received_data_before_response()); |
245 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 236 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
246 } | 237 } |
247 #ifndef NDEBUG | 238 #ifndef NDEBUG |
248 DCHECK_EQ(url_request_metrics.object_count,0); | 239 DCHECK_EQ(url_request_metrics.object_count,0); |
249 #endif | 240 #endif |
250 } | 241 } |
251 | 242 |
252 TEST_F(URLRequestTest, CancelTest4) { | 243 TEST_F(URLRequestTest, CancelTest4) { |
253 scoped_refptr<HTTPTestServer> server = | 244 TestServer server(L""); |
254 HTTPTestServer::CreateServer(L""); | 245 ASSERT_TRUE(server.init_successful()); |
255 ASSERT_TRUE(NULL != server.get()); | |
256 TestDelegate d; | 246 TestDelegate d; |
257 { | 247 { |
258 TestURLRequest r(server->TestServerPage(""), &d); | 248 TestURLRequest r(server.TestServerPage(""), &d); |
259 | 249 |
260 r.Start(); | 250 r.Start(); |
261 EXPECT_TRUE(r.is_pending()); | 251 EXPECT_TRUE(r.is_pending()); |
262 | 252 |
263 // The request will be implicitly canceled when it is destroyed. The | 253 // The request will be implicitly canceled when it is destroyed. The |
264 // test delegate must not post a quit message when this happens because | 254 // test delegate must not post a quit message when this happens because |
265 // this test doesn't actually have a message loop. The quit message would | 255 // this test doesn't actually have a message loop. The quit message would |
266 // get put on this thread's message queue and the next test would exit | 256 // get put on this thread's message queue and the next test would exit |
267 // early, causing problems. | 257 // early, causing problems. |
268 d.set_quit_on_complete(false); | 258 d.set_quit_on_complete(false); |
269 } | 259 } |
270 // expect things to just cleanup properly. | 260 // expect things to just cleanup properly. |
271 | 261 |
272 // we won't actually get a received reponse here because we've never run the | 262 // we won't actually get a received reponse here because we've never run the |
273 // message loop | 263 // message loop |
274 EXPECT_FALSE(d.received_data_before_response()); | 264 EXPECT_FALSE(d.received_data_before_response()); |
275 EXPECT_EQ(0, d.bytes_received()); | 265 EXPECT_EQ(0, d.bytes_received()); |
276 } | 266 } |
277 | 267 |
278 TEST_F(URLRequestTest, CancelTest5) { | 268 TEST_F(URLRequestTest, CancelTest5) { |
279 scoped_refptr<HTTPTestServer> server = | 269 TestServer server(L""); |
280 HTTPTestServer::CreateServer(L""); | 270 ASSERT_TRUE(server.init_successful()); |
281 ASSERT_TRUE(NULL != server.get()); | |
282 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); | 271 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); |
283 | 272 |
284 // populate cache | 273 // populate cache |
285 { | 274 { |
286 TestDelegate d; | 275 TestDelegate d; |
287 URLRequest r(server->TestServerPage("cachetime"), &d); | 276 URLRequest r(server.TestServerPage("cachetime"), &d); |
288 r.set_context(context); | 277 r.set_context(context); |
289 r.Start(); | 278 r.Start(); |
290 MessageLoop::current()->Run(); | 279 MessageLoop::current()->Run(); |
291 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 280 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
292 } | 281 } |
293 | 282 |
294 // cancel read from cache (see bug 990242) | 283 // cancel read from cache (see bug 990242) |
295 { | 284 { |
296 TestDelegate d; | 285 TestDelegate d; |
297 URLRequest r(server->TestServerPage("cachetime"), &d); | 286 URLRequest r(server.TestServerPage("cachetime"), &d); |
298 r.set_context(context); | 287 r.set_context(context); |
299 r.Start(); | 288 r.Start(); |
300 r.Cancel(); | 289 r.Cancel(); |
301 MessageLoop::current()->Run(); | 290 MessageLoop::current()->Run(); |
302 | 291 |
303 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 292 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
304 EXPECT_EQ(1, d.response_started_count()); | 293 EXPECT_EQ(1, d.response_started_count()); |
305 EXPECT_EQ(0, d.bytes_received()); | 294 EXPECT_EQ(0, d.bytes_received()); |
306 EXPECT_FALSE(d.received_data_before_response()); | 295 EXPECT_FALSE(d.received_data_before_response()); |
307 } | 296 } |
308 | 297 |
309 #ifndef NDEBUG | 298 #ifndef NDEBUG |
310 DCHECK_EQ(url_request_metrics.object_count, 0); | 299 DCHECK_EQ(url_request_metrics.object_count, 0); |
311 #endif | 300 #endif |
312 } | 301 } |
313 | 302 |
314 TEST_F(URLRequestTest, PostTest) { | 303 TEST_F(URLRequestTest, PostTest) { |
315 scoped_refptr<HTTPTestServer> server = | 304 TestServer server(L"net/data"); |
316 HTTPTestServer::CreateServer(L"net/data"); | 305 ASSERT_TRUE(server.init_successful()); |
317 ASSERT_TRUE(NULL != server.get()); | 306 |
318 const int kMsgSize = 20000; // multiple of 10 | 307 const int kMsgSize = 20000; // multiple of 10 |
319 const int kIterations = 50; | 308 const int kIterations = 50; |
320 char *uploadBytes = new char[kMsgSize+1]; | 309 char *uploadBytes = new char[kMsgSize+1]; |
321 char *ptr = uploadBytes; | 310 char *ptr = uploadBytes; |
322 char marker = 'a'; | 311 char marker = 'a'; |
323 for(int idx=0; idx<kMsgSize/10; idx++) { | 312 for(int idx=0; idx<kMsgSize/10; idx++) { |
324 memcpy(ptr, "----------", 10); | 313 memcpy(ptr, "----------", 10); |
325 ptr += 10; | 314 ptr += 10; |
326 if (idx % 100 == 0) { | 315 if (idx % 100 == 0) { |
327 ptr--; | 316 ptr--; |
328 *ptr++ = marker; | 317 *ptr++ = marker; |
329 if (++marker > 'z') | 318 if (++marker > 'z') |
330 marker = 'a'; | 319 marker = 'a'; |
331 } | 320 } |
332 | 321 |
333 } | 322 } |
334 uploadBytes[kMsgSize] = '\0'; | 323 uploadBytes[kMsgSize] = '\0'; |
335 | 324 |
336 scoped_refptr<URLRequestContext> context = | 325 scoped_refptr<URLRequestContext> context = |
337 new URLRequestHttpCacheContext(); | 326 new URLRequestHttpCacheContext(); |
338 | 327 |
339 for (int i = 0; i < kIterations; ++i) { | 328 for (int i = 0; i < kIterations; ++i) { |
340 TestDelegate d; | 329 TestDelegate d; |
341 URLRequest r(server->TestServerPage("echo"), &d); | 330 URLRequest r(server.TestServerPage("echo"), &d); |
342 r.set_context(context); | 331 r.set_context(context); |
343 r.set_method("POST"); | 332 r.set_method("POST"); |
344 | 333 |
345 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 334 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
346 | 335 |
347 r.Start(); | 336 r.Start(); |
348 EXPECT_TRUE(r.is_pending()); | 337 EXPECT_TRUE(r.is_pending()); |
349 | 338 |
350 MessageLoop::current()->Run(); | 339 MessageLoop::current()->Run(); |
351 | 340 |
352 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 341 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
353 (int) r.status().status() << ", os error: " << r.status().os_error(); | 342 (int) r.status().status() << ", os error: " << r.status().os_error(); |
354 | 343 |
355 EXPECT_FALSE(d.received_data_before_response()); | 344 EXPECT_FALSE(d.received_data_before_response()); |
356 EXPECT_EQ(uploadBytes, d.data_received()); | 345 EXPECT_EQ(uploadBytes, d.data_received()); |
357 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize),0); | 346 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize),0); |
358 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); | 347 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); |
359 } | 348 } |
360 delete[] uploadBytes; | 349 delete[] uploadBytes; |
361 #ifndef NDEBUG | 350 #ifndef NDEBUG |
362 DCHECK_EQ(url_request_metrics.object_count,0); | 351 DCHECK_EQ(url_request_metrics.object_count,0); |
363 #endif | 352 #endif |
364 } | 353 } |
365 | 354 |
366 TEST_F(URLRequestTest, PostEmptyTest) { | 355 TEST_F(URLRequestTest, PostEmptyTest) { |
367 scoped_refptr<HTTPTestServer> server = | 356 TestServer server(L"net/data"); |
368 HTTPTestServer::CreateServer(L"net/data"); | 357 ASSERT_TRUE(server.init_successful()); |
369 ASSERT_TRUE(NULL != server.get()); | |
370 TestDelegate d; | 358 TestDelegate d; |
371 { | 359 { |
372 TestURLRequest r(server->TestServerPage("echo"), &d); | 360 TestURLRequest r(server.TestServerPage("echo"), &d); |
373 r.set_method("POST"); | 361 r.set_method("POST"); |
374 | 362 |
375 r.Start(); | 363 r.Start(); |
376 EXPECT_TRUE(r.is_pending()); | 364 EXPECT_TRUE(r.is_pending()); |
377 | 365 |
378 MessageLoop::current()->Run(); | 366 MessageLoop::current()->Run(); |
379 | 367 |
380 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 368 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
381 (int) r.status().status() << ", os error: " << r.status().os_error(); | 369 (int) r.status().status() << ", os error: " << r.status().os_error(); |
382 | 370 |
383 EXPECT_FALSE(d.received_data_before_response()); | 371 EXPECT_FALSE(d.received_data_before_response()); |
384 EXPECT_TRUE(d.data_received().empty()); | 372 EXPECT_TRUE(d.data_received().empty()); |
385 } | 373 } |
386 #ifndef NDEBUG | 374 #ifndef NDEBUG |
387 DCHECK_EQ(url_request_metrics.object_count,0); | 375 DCHECK_EQ(url_request_metrics.object_count,0); |
388 #endif | 376 #endif |
389 } | 377 } |
390 | 378 |
391 TEST_F(URLRequestTest, PostFileTest) { | 379 TEST_F(URLRequestTest, PostFileTest) { |
392 scoped_refptr<HTTPTestServer> server = | 380 TestServer server(L"net/data"); |
393 HTTPTestServer::CreateServer(L"net/data"); | 381 ASSERT_TRUE(server.init_successful()); |
394 ASSERT_TRUE(NULL != server.get()); | |
395 TestDelegate d; | 382 TestDelegate d; |
396 { | 383 { |
397 TestURLRequest r(server->TestServerPage("echo"), &d); | 384 TestURLRequest r(server.TestServerPage("echo"), &d); |
398 r.set_method("POST"); | 385 r.set_method("POST"); |
399 | 386 |
400 std::wstring dir; | 387 std::wstring dir; |
401 PathService::Get(base::DIR_EXE, &dir); | 388 PathService::Get(base::DIR_EXE, &dir); |
402 file_util::SetCurrentDirectory(dir); | 389 file_util::SetCurrentDirectory(dir); |
403 | 390 |
404 std::wstring path; | 391 std::wstring path; |
405 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 392 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
406 file_util::AppendToPath(&path, L"net"); | 393 file_util::AppendToPath(&path, L"net"); |
407 file_util::AppendToPath(&path, L"data"); | 394 file_util::AppendToPath(&path, L"data"); |
408 file_util::AppendToPath(&path, L"url_request_unittest"); | 395 file_util::AppendToPath(&path, L"url_request_unittest"); |
409 file_util::AppendToPath(&path, L"with-headers.html"); | 396 file_util::AppendToPath(&path, L"with-headers.html"); |
410 r.AppendFileToUpload(path); | 397 r.AppendFileToUpload(path); |
411 | 398 |
412 // This file should just be ignored in the upload stream. | 399 // This file should just be ignored in the upload stream. |
413 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); | 400 r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345"); |
414 | 401 |
415 r.Start(); | 402 r.Start(); |
416 EXPECT_TRUE(r.is_pending()); | 403 EXPECT_TRUE(r.is_pending()); |
417 | 404 |
418 MessageLoop::current()->Run(); | 405 MessageLoop::current()->Run(); |
419 | 406 |
420 int64 longsize; | 407 int64 longsize; |
421 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); | 408 ASSERT_EQ(true, file_util::GetFileSize(path, &longsize)); |
422 int size = static_cast<int>(longsize); | 409 int size = static_cast<int>(longsize); |
423 scoped_array<char> buf(new char[size]); | 410 scoped_array<char> buf(new char[size]); |
424 | 411 |
425 int size_read = static_cast<int>(file_util::ReadFile(path, | 412 int size_read = static_cast<int>(file_util::ReadFile(path, buf.get(), size))
; |
426 buf.get(), size)); | |
427 ASSERT_EQ(size, size_read); | 413 ASSERT_EQ(size, size_read); |
428 | 414 |
429 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 415 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
430 (int) r.status().status() << ", os error: " << r.status().os_error(); | 416 (int) r.status().status() << ", os error: " << r.status().os_error(); |
431 | 417 |
432 EXPECT_FALSE(d.received_data_before_response()); | 418 EXPECT_FALSE(d.received_data_before_response()); |
433 | 419 |
434 ASSERT_EQ(size, d.bytes_received()); | 420 ASSERT_EQ(size, d.bytes_received()); |
435 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); | 421 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); |
436 } | 422 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 499 |
514 MessageLoop::current()->Run(); | 500 MessageLoop::current()->Run(); |
515 EXPECT_TRUE(d.request_failed()); | 501 EXPECT_TRUE(d.request_failed()); |
516 } | 502 } |
517 #ifndef NDEBUG | 503 #ifndef NDEBUG |
518 DCHECK_EQ(url_request_metrics.object_count,0); | 504 DCHECK_EQ(url_request_metrics.object_count,0); |
519 #endif | 505 #endif |
520 } | 506 } |
521 | 507 |
522 TEST_F(URLRequestTest, ResponseHeadersTest) { | 508 TEST_F(URLRequestTest, ResponseHeadersTest) { |
523 scoped_refptr<HTTPTestServer> server = | 509 TestServer server(L"net/data/url_request_unittest"); |
524 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | 510 ASSERT_TRUE(server.init_successful()); |
525 ASSERT_TRUE(NULL != server.get()); | |
526 TestDelegate d; | 511 TestDelegate d; |
527 TestURLRequest req(server->TestServerPage("files/with-headers.html"), &d); | 512 TestURLRequest req(server.TestServerPage("files/with-headers.html"), &d); |
528 req.Start(); | 513 req.Start(); |
529 MessageLoop::current()->Run(); | 514 MessageLoop::current()->Run(); |
530 | 515 |
531 const net::HttpResponseHeaders* headers = req.response_headers(); | 516 const net::HttpResponseHeaders* headers = req.response_headers(); |
532 std::string header; | 517 std::string header; |
533 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 518 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
534 EXPECT_EQ("private", header); | 519 EXPECT_EQ("private", header); |
535 | 520 |
536 header.clear(); | 521 header.clear(); |
537 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); | 522 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); |
538 EXPECT_EQ("text/html; charset=ISO-8859-1", header); | 523 EXPECT_EQ("text/html; charset=ISO-8859-1", header); |
539 | 524 |
540 // The response has two "X-Multiple-Entries" headers. | 525 // The response has two "X-Multiple-Entries" headers. |
541 // This verfies our output has them concatenated together. | 526 // This verfies our output has them concatenated together. |
542 header.clear(); | 527 header.clear(); |
543 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); | 528 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); |
544 EXPECT_EQ("a, b", header); | 529 EXPECT_EQ("a, b", header); |
545 } | 530 } |
546 | 531 |
547 TEST_F(URLRequestTest, BZip2ContentTest) { | 532 TEST_F(URLRequestTest, BZip2ContentTest) { |
548 scoped_refptr<HTTPTestServer> server = | 533 TestServer server(L"net/data/filter_unittests"); |
549 HTTPTestServer::CreateServer(L"net/data/filter_unittests"); | 534 ASSERT_TRUE(server.init_successful()); |
550 ASSERT_TRUE(NULL != server.get()); | |
551 | 535 |
552 // for localhost domain, we also should support bzip2 encoding | 536 // for localhost domain, we also should support bzip2 encoding |
553 // first, get the original file | 537 // first, get the original file |
554 TestDelegate d1; | 538 TestDelegate d1; |
555 TestURLRequest req1(server->TestServerPage("realfiles/google.txt"), &d1); | 539 TestURLRequest req1(server.TestServerPage("realfiles/google.txt"), &d1); |
556 req1.Start(); | 540 req1.Start(); |
557 MessageLoop::current()->Run(); | 541 MessageLoop::current()->Run(); |
558 | 542 |
559 const std::string& got_content = d1.data_received(); | 543 const std::string& got_content = d1.data_received(); |
560 | 544 |
561 // second, get bzip2 content | 545 // second, get bzip2 content |
562 TestDelegate d2; | 546 TestDelegate d2; |
563 TestURLRequest req2(server->TestServerPage("realbz2files/google.txt"), &d2); | 547 TestURLRequest req2(server.TestServerPage("realbz2files/google.txt"), &d2); |
564 req2.Start(); | 548 req2.Start(); |
565 MessageLoop::current()->Run(); | 549 MessageLoop::current()->Run(); |
566 | 550 |
567 const std::string& got_bz2_content = d2.data_received(); | 551 const std::string& got_bz2_content = d2.data_received(); |
568 | 552 |
569 // compare those two results | 553 // compare those two results |
570 EXPECT_EQ(got_content, got_bz2_content); | 554 EXPECT_EQ(got_content, got_bz2_content); |
571 } | 555 } |
572 | 556 |
573 TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { | 557 TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { |
574 scoped_refptr<HTTPTestServer> server = | 558 TestServer server(L"net/data/filter_unittests"); |
575 HTTPTestServer::CreateServer(L"net/data/filter_unittests"); | 559 ASSERT_TRUE(server.init_successful()); |
576 ASSERT_TRUE(NULL != server.get()); | |
577 | 560 |
578 // for localhost domain, we also should support bzip2 encoding | 561 // for localhost domain, we also should support bzip2 encoding |
579 // first, get the original file | 562 // first, get the original file |
580 TestDelegate d1; | 563 TestDelegate d1; |
581 TestURLRequest req1(server->TestServerPage("realfiles/google.txt"), &d1); | 564 TestURLRequest req1(server.TestServerPage("realfiles/google.txt"), &d1); |
582 req1.Start(); | 565 req1.Start(); |
583 MessageLoop::current()->Run(); | 566 MessageLoop::current()->Run(); |
584 | 567 |
585 const std::string& got_content = d1.data_received(); | 568 const std::string& got_content = d1.data_received(); |
586 | 569 |
587 // second, get bzip2 content. ask the testserver to send the BZ2 header in | 570 // second, get bzip2 content. ask the testserver to send the BZ2 header in |
588 // two chunks with a delay between them. this tests our fix for bug 867161. | 571 // two chunks with a delay between them. this tests our fix for bug 867161. |
589 TestDelegate d2; | 572 TestDelegate d2; |
590 TestURLRequest req2(server->TestServerPage( | 573 TestURLRequest req2(server.TestServerPage("realbz2files/google.txt?incremental
-header"), &d2); |
591 "realbz2files/google.txt?incremental-header"), &d2); | |
592 req2.Start(); | 574 req2.Start(); |
593 MessageLoop::current()->Run(); | 575 MessageLoop::current()->Run(); |
594 | 576 |
595 const std::string& got_bz2_content = d2.data_received(); | 577 const std::string& got_bz2_content = d2.data_received(); |
596 | 578 |
597 // compare those two results | 579 // compare those two results |
598 EXPECT_EQ(got_content, got_bz2_content); | 580 EXPECT_EQ(got_content, got_bz2_content); |
599 } | 581 } |
600 | 582 |
601 #if defined(OS_WIN) | 583 #if defined(OS_WIN) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 DeleteFile(lnk_path.c_str()); | 647 DeleteFile(lnk_path.c_str()); |
666 CoUninitialize(); | 648 CoUninitialize(); |
667 | 649 |
668 #ifndef NDEBUG | 650 #ifndef NDEBUG |
669 DCHECK_EQ(url_request_metrics.object_count,0); | 651 DCHECK_EQ(url_request_metrics.object_count,0); |
670 #endif | 652 #endif |
671 } | 653 } |
672 #endif // defined(OS_WIN) | 654 #endif // defined(OS_WIN) |
673 | 655 |
674 TEST_F(URLRequestTest, ContentTypeNormalizationTest) { | 656 TEST_F(URLRequestTest, ContentTypeNormalizationTest) { |
675 scoped_refptr<HTTPTestServer> server = | 657 TestServer server(L"net/data/url_request_unittest"); |
676 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | 658 ASSERT_TRUE(server.init_successful()); |
677 ASSERT_TRUE(NULL != server.get()); | |
678 | |
679 TestDelegate d; | 659 TestDelegate d; |
680 TestURLRequest req(server->TestServerPage( | 660 TestURLRequest req(server.TestServerPage( |
681 "files/content-type-normalization.html"), &d); | 661 "files/content-type-normalization.html"), &d); |
682 req.Start(); | 662 req.Start(); |
683 MessageLoop::current()->Run(); | 663 MessageLoop::current()->Run(); |
684 | 664 |
685 std::string mime_type; | 665 std::string mime_type; |
686 req.GetMimeType(&mime_type); | 666 req.GetMimeType(&mime_type); |
687 EXPECT_EQ("text/html", mime_type); | 667 EXPECT_EQ("text/html", mime_type); |
688 | 668 |
689 std::string charset; | 669 std::string charset; |
690 req.GetCharset(&charset); | 670 req.GetCharset(&charset); |
(...skipping 23 matching lines...) Expand all Loading... |
714 } | 694 } |
715 #ifndef NDEBUG | 695 #ifndef NDEBUG |
716 DCHECK_EQ(url_request_metrics.object_count,0); | 696 DCHECK_EQ(url_request_metrics.object_count,0); |
717 #endif | 697 #endif |
718 | 698 |
719 // Take out mock resource provider. | 699 // Take out mock resource provider. |
720 net::NetModule::SetResourceProvider(NULL); | 700 net::NetModule::SetResourceProvider(NULL); |
721 } | 701 } |
722 | 702 |
723 TEST_F(URLRequestTest, RestrictRedirects) { | 703 TEST_F(URLRequestTest, RestrictRedirects) { |
724 scoped_refptr<HTTPTestServer> server = | 704 TestServer server(L"net/data/url_request_unittest"); |
725 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | 705 ASSERT_TRUE(server.init_successful()); |
726 ASSERT_TRUE(NULL != server.get()); | |
727 | |
728 TestDelegate d; | 706 TestDelegate d; |
729 TestURLRequest req(server->TestServerPage( | 707 TestURLRequest req(server.TestServerPage( |
730 "files/redirect-to-file.html"), &d); | 708 "files/redirect-to-file.html"), &d); |
731 req.Start(); | 709 req.Start(); |
732 MessageLoop::current()->Run(); | 710 MessageLoop::current()->Run(); |
733 | 711 |
734 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 712 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
735 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); | 713 EXPECT_EQ(net::ERR_UNSAFE_REDIRECT, req.status().os_error()); |
736 } | 714 } |
737 | 715 |
738 TEST_F(URLRequestTest, NoUserPassInReferrer) { | 716 TEST_F(URLRequestTest, NoUserPassInReferrer) { |
739 scoped_refptr<HTTPTestServer> server = | 717 TestServer server(L"net/data/url_request_unittest"); |
740 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | 718 ASSERT_TRUE(server.init_successful()); |
741 ASSERT_TRUE(NULL != server.get()); | |
742 TestDelegate d; | 719 TestDelegate d; |
743 TestURLRequest req(server->TestServerPage( | 720 TestURLRequest req(server.TestServerPage( |
744 "echoheader?Referer"), &d); | 721 "echoheader?Referer"), &d); |
745 req.set_referrer("http://user:pass@foo.com/"); | 722 req.set_referrer("http://user:pass@foo.com/"); |
746 req.Start(); | 723 req.Start(); |
747 MessageLoop::current()->Run(); | 724 MessageLoop::current()->Run(); |
748 | 725 |
749 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 726 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
750 } | 727 } |
751 | 728 |
752 TEST_F(URLRequestTest, CancelRedirect) { | 729 TEST_F(URLRequestTest, CancelRedirect) { |
753 scoped_refptr<HTTPTestServer> server = | 730 TestServer server(L"net/data/url_request_unittest"); |
754 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | 731 ASSERT_TRUE(server.init_successful()); |
755 ASSERT_TRUE(NULL != server.get()); | |
756 TestDelegate d; | 732 TestDelegate d; |
757 { | 733 { |
758 d.set_cancel_in_received_redirect(true); | 734 d.set_cancel_in_received_redirect(true); |
759 TestURLRequest req(server->TestServerPage( | 735 TestURLRequest req(server.TestServerPage( |
760 "files/redirect-test.html"), &d); | 736 "files/redirect-test.html"), &d); |
761 req.Start(); | 737 req.Start(); |
762 MessageLoop::current()->Run(); | 738 MessageLoop::current()->Run(); |
763 | 739 |
764 EXPECT_EQ(1, d.response_started_count()); | 740 EXPECT_EQ(1, d.response_started_count()); |
765 EXPECT_EQ(0, d.bytes_received()); | 741 EXPECT_EQ(0, d.bytes_received()); |
766 EXPECT_FALSE(d.received_data_before_response()); | 742 EXPECT_FALSE(d.received_data_before_response()); |
767 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 743 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
768 } | 744 } |
769 } | 745 } |
770 | 746 |
771 TEST_F(URLRequestTest, VaryHeader) { | 747 TEST_F(URLRequestTest, VaryHeader) { |
772 scoped_refptr<HTTPTestServer> server = | 748 TestServer server(L"net/data/url_request_unittest"); |
773 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | 749 ASSERT_TRUE(server.init_successful()); |
774 ASSERT_TRUE(NULL != server.get()); | |
775 | 750 |
776 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); | 751 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); |
777 | 752 |
778 Time response_time; | 753 Time response_time; |
779 | 754 |
780 // populate the cache | 755 // populate the cache |
781 { | 756 { |
782 TestDelegate d; | 757 TestDelegate d; |
783 URLRequest req(server->TestServerPage("echoheader?foo"), &d); | 758 URLRequest req(server.TestServerPage("echoheader?foo"), &d); |
784 req.set_context(context); | 759 req.set_context(context); |
785 req.SetExtraRequestHeaders("foo:1"); | 760 req.SetExtraRequestHeaders("foo:1"); |
786 req.Start(); | 761 req.Start(); |
787 MessageLoop::current()->Run(); | 762 MessageLoop::current()->Run(); |
788 | 763 |
789 response_time = req.response_time(); | 764 response_time = req.response_time(); |
790 } | 765 } |
791 | 766 |
792 // Make sure that the response time of a future response will be in the | 767 // Make sure that the response time of a future response will be in the |
793 // future! | 768 // future! |
794 PlatformThread::Sleep(10); | 769 PlatformThread::Sleep(10); |
795 | 770 |
796 // expect a cache hit | 771 // expect a cache hit |
797 { | 772 { |
798 TestDelegate d; | 773 TestDelegate d; |
799 URLRequest req(server->TestServerPage("echoheader?foo"), &d); | 774 URLRequest req(server.TestServerPage("echoheader?foo"), &d); |
800 req.set_context(context); | 775 req.set_context(context); |
801 req.SetExtraRequestHeaders("foo:1"); | 776 req.SetExtraRequestHeaders("foo:1"); |
802 req.Start(); | 777 req.Start(); |
803 MessageLoop::current()->Run(); | 778 MessageLoop::current()->Run(); |
804 | 779 |
805 EXPECT_TRUE(req.response_time() == response_time); | 780 EXPECT_TRUE(req.response_time() == response_time); |
806 } | 781 } |
807 | 782 |
808 // expect a cache miss | 783 // expect a cache miss |
809 { | 784 { |
810 TestDelegate d; | 785 TestDelegate d; |
811 URLRequest req(server->TestServerPage("echoheader?foo"), &d); | 786 URLRequest req(server.TestServerPage("echoheader?foo"), &d); |
812 req.set_context(context); | 787 req.set_context(context); |
813 req.SetExtraRequestHeaders("foo:2"); | 788 req.SetExtraRequestHeaders("foo:2"); |
814 req.Start(); | 789 req.Start(); |
815 MessageLoop::current()->Run(); | 790 MessageLoop::current()->Run(); |
816 | 791 |
817 EXPECT_FALSE(req.response_time() == response_time); | 792 EXPECT_FALSE(req.response_time() == response_time); |
818 } | 793 } |
819 } | 794 } |
820 | 795 |
821 TEST_F(URLRequestTest, BasicAuth) { | 796 TEST_F(URLRequestTest, BasicAuth) { |
822 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); | 797 scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); |
823 scoped_refptr<HTTPTestServer> server = | 798 TestServer server(L""); |
824 HTTPTestServer::CreateServer(L""); | 799 ASSERT_TRUE(server.init_successful()); |
825 ASSERT_TRUE(NULL != server.get()); | |
826 | 800 |
827 Time response_time; | 801 Time response_time; |
828 | 802 |
829 // populate the cache | 803 // populate the cache |
830 { | 804 { |
831 TestDelegate d; | 805 TestDelegate d; |
832 d.set_username(L"user"); | 806 d.set_username(L"user"); |
833 d.set_password(L"secret"); | 807 d.set_password(L"secret"); |
834 | 808 |
835 URLRequest r(server->TestServerPage("auth-basic"), &d); | 809 URLRequest r(server.TestServerPage("auth-basic"), &d); |
836 r.set_context(context); | 810 r.set_context(context); |
837 r.Start(); | 811 r.Start(); |
838 | 812 |
839 MessageLoop::current()->Run(); | 813 MessageLoop::current()->Run(); |
840 | 814 |
841 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 815 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
842 | 816 |
843 response_time = r.response_time(); | 817 response_time = r.response_time(); |
844 } | 818 } |
845 | 819 |
846 // Let some time pass so we can ensure that a future response will have a | 820 // Let some time pass so we can ensure that a future response will have a |
847 // response time value in the future. | 821 // response time value in the future. |
848 PlatformThread::Sleep(10 /* milliseconds */); | 822 PlatformThread::Sleep(10 /* milliseconds */); |
849 | 823 |
850 // repeat request with end-to-end validation. since auth-basic results in a | 824 // repeat request with end-to-end validation. since auth-basic results in a |
851 // cachable page, we expect this test to result in a 304. in which case, the | 825 // cachable page, we expect this test to result in a 304. in which case, the |
852 // response should be fetched from the cache. | 826 // response should be fetched from the cache. |
853 { | 827 { |
854 TestDelegate d; | 828 TestDelegate d; |
855 d.set_username(L"user"); | 829 d.set_username(L"user"); |
856 d.set_password(L"secret"); | 830 d.set_password(L"secret"); |
857 | 831 |
858 URLRequest r(server->TestServerPage("auth-basic"), &d); | 832 URLRequest r(server.TestServerPage("auth-basic"), &d); |
859 r.set_context(context); | 833 r.set_context(context); |
860 r.set_load_flags(net::LOAD_VALIDATE_CACHE); | 834 r.set_load_flags(net::LOAD_VALIDATE_CACHE); |
861 r.Start(); | 835 r.Start(); |
862 | 836 |
863 MessageLoop::current()->Run(); | 837 MessageLoop::current()->Run(); |
864 | 838 |
865 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 839 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
866 | 840 |
867 // Should be the same cached document, which means that the response time | 841 // Should be the same cached document, which means that the response time |
868 // should not have changed. | 842 // should not have changed. |
869 EXPECT_TRUE(response_time == r.response_time()); | 843 EXPECT_TRUE(response_time == r.response_time()); |
870 } | 844 } |
871 } | 845 } |
872 | 846 |
873 // In this test, we do a POST which the server will 302 redirect. | 847 // In this test, we do a POST which the server will 302 redirect. |
874 // The subsequent transaction should use GET, and should not send the | 848 // The subsequent transaction should use GET, and should not send the |
875 // Content-Type header. | 849 // Content-Type header. |
876 // http://code.google.com/p/chromium/issues/detail?id=843 | 850 // http://code.google.com/p/chromium/issues/detail?id=843 |
877 TEST_F(URLRequestTest, Post302RedirectGet) { | 851 TEST_F(URLRequestTest, Post302RedirectGet) { |
878 scoped_refptr<HTTPTestServer> server = | 852 TestServer server(L"net/data/url_request_unittest"); |
879 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | |
880 ASSERT_TRUE(NULL != server.get()); | |
881 TestDelegate d; | 853 TestDelegate d; |
882 TestURLRequest req(server->TestServerPage("files/redirect-to-echoall"), &d); | 854 TestURLRequest req(server.TestServerPage("files/redirect-to-echoall"), &d); |
883 req.set_method("POST"); | 855 req.set_method("POST"); |
884 | 856 |
885 // Set headers (some of which are specific to the POST). | 857 // Set headers (some of which are specific to the POST). |
886 // ("Content-Length: 10" is just a junk value to make sure it gets stripped). | 858 // ("Content-Length: 10" is just a junk value to make sure it gets stripped). |
887 req.SetExtraRequestHeaders( | 859 req.SetExtraRequestHeaders( |
888 "Content-Type: multipart/form-data; " | 860 "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAADeAA+NA
AWMAAwZ\r\n" |
889 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 861 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text
/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
890 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | |
891 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | |
892 "Accept-Language: en-US,en\r\n" | 862 "Accept-Language: en-US,en\r\n" |
893 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" | 863 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" |
894 "Content-Length: 10\r\n" | 864 "Content-Length: 10\r\n" |
895 "Origin: http://localhost:1337/" | 865 "Origin: http://localhost:1337/" |
896 ); | 866 ); |
897 req.Start(); | 867 req.Start(); |
898 MessageLoop::current()->Run(); | 868 MessageLoop::current()->Run(); |
899 | 869 |
900 std::string mime_type; | 870 std::string mime_type; |
901 req.GetMimeType(&mime_type); | 871 req.GetMimeType(&mime_type); |
902 EXPECT_EQ("text/html", mime_type); | 872 EXPECT_EQ("text/html", mime_type); |
903 | 873 |
904 const std::string& data = d.data_received(); | 874 const std::string& data = d.data_received(); |
905 | 875 |
906 // Check that the post-specific headers were stripped: | 876 // Check that the post-specific headers were stripped: |
907 EXPECT_FALSE(ContainsString(data, "Content-Length:")); | 877 EXPECT_FALSE(ContainsString(data, "Content-Length:")); |
908 EXPECT_FALSE(ContainsString(data, "Content-Type:")); | 878 EXPECT_FALSE(ContainsString(data, "Content-Type:")); |
909 EXPECT_FALSE(ContainsString(data, "Origin:")); | 879 EXPECT_FALSE(ContainsString(data, "Origin:")); |
910 | 880 |
911 // These extra request headers should not have been stripped. | 881 // These extra request headers should not have been stripped. |
912 EXPECT_TRUE(ContainsString(data, "Accept:")); | 882 EXPECT_TRUE(ContainsString(data, "Accept:")); |
913 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); | 883 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); |
914 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); | 884 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); |
915 } | 885 } |
916 | 886 |
917 TEST_F(URLRequestTest, Post307RedirectPost) { | 887 TEST_F(URLRequestTest, Post307RedirectPost) { |
918 scoped_refptr<HTTPTestServer> server = | 888 TestServer server(L"net/data/url_request_unittest"); |
919 HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); | |
920 ASSERT_TRUE(NULL != server.get()); | |
921 TestDelegate d; | 889 TestDelegate d; |
922 TestURLRequest req(server->TestServerPage("files/redirect307-to-echoall"), | 890 TestURLRequest req(server.TestServerPage("files/redirect307-to-echoall"), &d); |
923 &d); | |
924 req.set_method("POST"); | 891 req.set_method("POST"); |
925 req.Start(); | 892 req.Start(); |
926 MessageLoop::current()->Run(); | 893 MessageLoop::current()->Run(); |
927 EXPECT_EQ(req.method(), "POST"); | 894 EXPECT_EQ(req.method(), "POST"); |
928 } | 895 } |
929 | |
930 // TODO(ibrar) It appears that these tests are hanging or not shutting down | |
931 // correctly. Disable them for now. | |
932 #if 1 // !defined(OS_WIN) | |
933 #define MAYBE_FTPGetTestAnonymous DISABLED_FTPGetTestAnonymous | |
934 #define MAYBE_FTPCheckWrongPassword DISABLED_FTPCheckWrongPassword | |
935 #define MAYBE_FTPCheckWrongUser DISABLED_FTPCheckWrongUser | |
936 #define MAYBE_FTPGetTest DISABLED_FTPGetTest | |
937 #else | |
938 #define MAYBE_FTPGetTestAnonymous FTPGetTestAnonymous | |
939 #define MAYBE_FTPCheckWrongPassword FTPCheckWrongPassword | |
940 #define MAYBE_FTPCheckWrongUser FTPCheckWrongUser | |
941 #define MAYBE_FTPGetTest FTPGetTest | |
942 #endif | |
943 | |
944 TEST_F(URLRequestTest, MAYBE_FTPGetTestAnonymous) { | |
945 scoped_refptr<FTPTestServer> server = FTPTestServer::CreateServer(L""); | |
946 ASSERT_TRUE(NULL != server.get()); | |
947 std::wstring app_path; | |
948 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
949 app_path.append(L"\\LICENSE"); | |
950 TestDelegate d; | |
951 { | |
952 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); | |
953 r.Start(); | |
954 EXPECT_TRUE(r.is_pending()); | |
955 | |
956 MessageLoop::current()->Run(); | |
957 | |
958 int64 file_size = 0; | |
959 file_util::GetFileSize(app_path, &file_size); | |
960 | |
961 EXPECT_TRUE(!r.is_pending()); | |
962 EXPECT_EQ(1, d.response_started_count()); | |
963 EXPECT_FALSE(d.received_data_before_response()); | |
964 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | |
965 } | |
966 } | |
967 | |
968 TEST_F(URLRequestTest, MAYBE_FTPGetTest) { | |
969 scoped_refptr<FTPTestServer> server = | |
970 FTPTestServer::CreateServer(L"", "chrome", "chrome"); | |
971 ASSERT_TRUE(NULL != server.get()); | |
972 std::wstring app_path; | |
973 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
974 app_path.append(L"\\LICENSE"); | |
975 TestDelegate d; | |
976 { | |
977 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); | |
978 r.Start(); | |
979 EXPECT_TRUE(r.is_pending()); | |
980 | |
981 MessageLoop::current()->Run(); | |
982 | |
983 int64 file_size = 0; | |
984 file_util::GetFileSize(app_path, &file_size); | |
985 | |
986 EXPECT_TRUE(!r.is_pending()); | |
987 EXPECT_EQ(1, d.response_started_count()); | |
988 EXPECT_FALSE(d.received_data_before_response()); | |
989 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | |
990 } | |
991 } | |
992 | |
993 TEST_F(URLRequestTest, MAYBE_FTPCheckWrongPassword) { | |
994 scoped_refptr<FTPTestServer> server = | |
995 FTPTestServer::CreateServer(L"", "chrome", "wrong_password"); | |
996 ASSERT_TRUE(NULL != server.get()); | |
997 std::wstring app_path; | |
998 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
999 app_path.append(L"\\LICENSE"); | |
1000 TestDelegate d; | |
1001 { | |
1002 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); | |
1003 r.Start(); | |
1004 EXPECT_TRUE(r.is_pending()); | |
1005 | |
1006 MessageLoop::current()->Run(); | |
1007 | |
1008 int64 file_size = 0; | |
1009 file_util::GetFileSize(app_path, &file_size); | |
1010 | |
1011 EXPECT_TRUE(!r.is_pending()); | |
1012 EXPECT_EQ(1, d.response_started_count()); | |
1013 EXPECT_FALSE(d.received_data_before_response()); | |
1014 EXPECT_EQ(d.bytes_received(), 0); | |
1015 } | |
1016 } | |
1017 | |
1018 TEST_F(URLRequestTest, MAYBE_FTPCheckWrongUser) { | |
1019 scoped_refptr<FTPTestServer> server = | |
1020 FTPTestServer::CreateServer(L"", "wrong_user", "chrome"); | |
1021 ASSERT_TRUE(NULL != server.get()); | |
1022 std::wstring app_path; | |
1023 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
1024 app_path.append(L"\\LICENSE"); | |
1025 TestDelegate d; | |
1026 { | |
1027 TestURLRequest r(server->TestServerPage("/LICENSE"), &d); | |
1028 r.Start(); | |
1029 EXPECT_TRUE(r.is_pending()); | |
1030 | |
1031 MessageLoop::current()->Run(); | |
1032 | |
1033 int64 file_size = 0; | |
1034 file_util::GetFileSize(app_path, &file_size); | |
1035 | |
1036 EXPECT_TRUE(!r.is_pending()); | |
1037 EXPECT_EQ(1, d.response_started_count()); | |
1038 EXPECT_FALSE(d.received_data_before_response()); | |
1039 EXPECT_EQ(d.bytes_received(), 0); | |
1040 } | |
1041 } | |
1042 | |
OLD | NEW |