OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 5 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 list_head_ = this; | 258 list_head_ = this; |
259 } | 259 } |
260 | 260 |
261 static URLRequestTestDelayedStartJob* list_head_; | 261 static URLRequestTestDelayedStartJob* list_head_; |
262 URLRequestTestDelayedStartJob* next_; | 262 URLRequestTestDelayedStartJob* next_; |
263 }; | 263 }; |
264 | 264 |
265 URLRequestTestDelayedStartJob* | 265 URLRequestTestDelayedStartJob* |
266 URLRequestTestDelayedStartJob::list_head_ = NULL; | 266 URLRequestTestDelayedStartJob::list_head_ = NULL; |
267 | 267 |
268 // This class is a variation on URLRequestTestJob in that it only | |
rvargas (doing something else)
2012/05/29 18:13:36
nit: remove "only" ?
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Done.
| |
269 // returns IO_pending errors before every read, not just the first one. | |
270 class URLRequestTestDelayedCompleteJob : public net::URLRequestTestJob { | |
rvargas (doing something else)
2012/05/29 18:13:36
...DelayedCompletion... ? DelayCompletion ?
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Went with URLRequestTestDelayedCompletionJob; let
| |
271 public: | |
272 URLRequestTestDelayedCompleteJob(net::URLRequest* request) | |
rvargas (doing something else)
2012/05/29 18:13:36
explicit
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Whoops; thank you.
| |
273 : net::URLRequestTestJob(request) { } | |
rvargas (doing something else)
2012/05/29 18:13:36
nit: no space between {} (same thing below)
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Done.
| |
274 URLRequestTestDelayedCompleteJob(net::URLRequest* request, bool auto_advance) | |
275 : net::URLRequestTestJob(request, auto_advance) { } | |
276 URLRequestTestDelayedCompleteJob(net::URLRequest* request, | |
277 const std::string& response_headers, | |
rvargas (doing something else)
2012/05/29 18:13:36
nit: indent three more spaces
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Done; sorry.
| |
278 const std::string& response_data, | |
279 bool auto_advance) | |
280 : net::URLRequestTestJob( | |
281 request, response_headers, response_data, auto_advance) { } | |
rvargas (doing something else)
2012/05/29 18:13:36
nit: arguments start on the previous line
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Done.
| |
282 | |
283 private: | |
284 bool FinalRoundIOPending() { return true; } | |
rvargas (doing something else)
2012/05/29 18:32:13
I forgot about this one:
nit: virtual.
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Also added OVERRIDE, now that you got me thinking
| |
285 }; | |
286 | |
287 | |
288 | |
268 // Associated with an URLRequest to determine if the URLRequest gets deleted. | 289 // Associated with an URLRequest to determine if the URLRequest gets deleted. |
269 class TestUserData : public base::SupportsUserData::Data { | 290 class TestUserData : public base::SupportsUserData::Data { |
270 public: | 291 public: |
271 explicit TestUserData(bool* was_deleted) | 292 explicit TestUserData(bool* was_deleted) |
272 : was_deleted_(was_deleted) { | 293 : was_deleted_(was_deleted) { |
273 } | 294 } |
274 | 295 |
275 ~TestUserData() { | 296 ~TestUserData() { |
276 *was_deleted_ = true; | 297 *was_deleted_ = true; |
277 } | 298 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 // testing::Test | 372 // testing::Test |
352 virtual void SetUp() { | 373 virtual void SetUp() { |
353 DCHECK(!test_fixture_); | 374 DCHECK(!test_fixture_); |
354 test_fixture_ = this; | 375 test_fixture_ = this; |
355 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0); | 376 ChildProcessSecurityPolicyImpl::GetInstance()->Add(0); |
356 net::URLRequest::Deprecated::RegisterProtocolFactory( | 377 net::URLRequest::Deprecated::RegisterProtocolFactory( |
357 "test", | 378 "test", |
358 &ResourceDispatcherHostTest::Factory); | 379 &ResourceDispatcherHostTest::Factory); |
359 EnsureTestSchemeIsAllowed(); | 380 EnsureTestSchemeIsAllowed(); |
360 delay_start_ = false; | 381 delay_start_ = false; |
382 delay_complete_ = false; | |
361 } | 383 } |
362 | 384 |
363 virtual void TearDown() { | 385 virtual void TearDown() { |
364 net::URLRequest::Deprecated::RegisterProtocolFactory("test", NULL); | 386 net::URLRequest::Deprecated::RegisterProtocolFactory("test", NULL); |
365 if (!scheme_.empty()) | 387 if (!scheme_.empty()) |
366 net::URLRequest::Deprecated::RegisterProtocolFactory( | 388 net::URLRequest::Deprecated::RegisterProtocolFactory( |
367 scheme_, old_factory_); | 389 scheme_, old_factory_); |
368 | 390 |
369 EXPECT_TRUE(URLRequestTestDelayedStartJob::DelayedStartQueueEmpty()); | 391 EXPECT_TRUE(URLRequestTestDelayedStartJob::DelayedStartQueueEmpty()); |
370 URLRequestTestDelayedStartJob::ClearQueue(); | 392 URLRequestTestDelayedStartJob::ClearQueue(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( | 454 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( |
433 scheme_, &ResourceDispatcherHostTest::Factory); | 455 scheme_, &ResourceDispatcherHostTest::Factory); |
434 } | 456 } |
435 | 457 |
436 // Our own net::URLRequestJob factory. | 458 // Our own net::URLRequestJob factory. |
437 static net::URLRequestJob* Factory(net::URLRequest* request, | 459 static net::URLRequestJob* Factory(net::URLRequest* request, |
438 const std::string& scheme) { | 460 const std::string& scheme) { |
439 if (test_fixture_->response_headers_.empty()) { | 461 if (test_fixture_->response_headers_.empty()) { |
440 if (delay_start_) { | 462 if (delay_start_) { |
441 return new URLRequestTestDelayedStartJob(request); | 463 return new URLRequestTestDelayedStartJob(request); |
464 } else if (delay_complete_) { | |
465 return new URLRequestTestDelayedCompleteJob(request); | |
442 } else { | 466 } else { |
443 return new net::URLRequestTestJob(request); | 467 return new net::URLRequestTestJob(request); |
444 } | 468 } |
445 } else { | 469 } else { |
446 if (delay_start_) { | 470 if (delay_start_) { |
447 return new URLRequestTestDelayedStartJob( | 471 return new URLRequestTestDelayedStartJob( |
448 request, test_fixture_->response_headers_, | 472 request, test_fixture_->response_headers_, |
449 test_fixture_->response_data_, false); | 473 test_fixture_->response_data_, false); |
474 } else if (delay_complete_) { | |
475 return new URLRequestTestDelayedCompleteJob( | |
476 request, test_fixture_->response_headers_, | |
477 test_fixture_->response_data_, false); | |
450 } else { | 478 } else { |
451 return new net::URLRequestTestJob(request, | 479 return new net::URLRequestTestJob(request, |
452 test_fixture_->response_headers_, | 480 test_fixture_->response_headers_, |
453 test_fixture_->response_data_, | 481 test_fixture_->response_data_, |
454 false); | 482 false); |
455 } | 483 } |
456 } | 484 } |
457 } | 485 } |
458 | 486 |
459 void SetDelayedStartJobGeneration(bool delay_job_start) { | 487 void SetDelayedStartJobGeneration(bool delay_job_start) { |
460 delay_start_ = delay_job_start; | 488 delay_start_ = delay_job_start; |
461 } | 489 } |
462 | 490 |
491 void SetDelayedCompleteJobGeneration(bool delay_job_complete) { | |
492 delay_complete_ = delay_job_complete; | |
493 } | |
494 | |
463 MessageLoopForIO message_loop_; | 495 MessageLoopForIO message_loop_; |
464 BrowserThreadImpl ui_thread_; | 496 BrowserThreadImpl ui_thread_; |
465 BrowserThreadImpl file_thread_; | 497 BrowserThreadImpl file_thread_; |
466 BrowserThreadImpl cache_thread_; | 498 BrowserThreadImpl cache_thread_; |
467 BrowserThreadImpl io_thread_; | 499 BrowserThreadImpl io_thread_; |
468 scoped_ptr<TestBrowserContext> browser_context_; | 500 scoped_ptr<TestBrowserContext> browser_context_; |
469 scoped_refptr<ForwardingFilter> filter_; | 501 scoped_refptr<ForwardingFilter> filter_; |
470 ResourceDispatcherHostImpl host_; | 502 ResourceDispatcherHostImpl host_; |
471 ResourceIPCAccumulator accum_; | 503 ResourceIPCAccumulator accum_; |
472 std::string response_headers_; | 504 std::string response_headers_; |
473 std::string response_data_; | 505 std::string response_data_; |
474 std::string scheme_; | 506 std::string scheme_; |
475 net::URLRequest::ProtocolFactory* old_factory_; | 507 net::URLRequest::ProtocolFactory* old_factory_; |
476 ResourceType::Type resource_type_; | 508 ResourceType::Type resource_type_; |
477 static ResourceDispatcherHostTest* test_fixture_; | 509 static ResourceDispatcherHostTest* test_fixture_; |
478 static bool delay_start_; | 510 static bool delay_start_; |
511 static bool delay_complete_; | |
479 }; | 512 }; |
480 // Static. | 513 // Static. |
481 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; | 514 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; |
482 bool ResourceDispatcherHostTest::delay_start_ = false; | 515 bool ResourceDispatcherHostTest::delay_start_ = false; |
516 bool ResourceDispatcherHostTest::delay_complete_ = false; | |
483 | 517 |
484 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 518 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
485 int request_id, | 519 int request_id, |
486 const GURL& url) { | 520 const GURL& url) { |
487 MakeTestRequest(filter_.get(), render_view_id, request_id, url); | 521 MakeTestRequest(filter_.get(), render_view_id, request_id, url); |
488 } | 522 } |
489 | 523 |
490 void ResourceDispatcherHostTest::MakeTestRequest( | 524 void ResourceDispatcherHostTest::MakeTestRequest( |
491 ResourceMessageFilter* filter, | 525 ResourceMessageFilter* filter, |
492 int render_view_id, | 526 int render_view_id, |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1260 EXPECT_EQ(0, host_.pending_requests()); | 1294 EXPECT_EQ(0, host_.pending_requests()); |
1261 | 1295 |
1262 int render_view_id = 0; | 1296 int render_view_id = 0; |
1263 int request_id = 1; | 1297 int request_id = 1; |
1264 | 1298 |
1265 std::string response("HTTP\n" | 1299 std::string response("HTTP\n" |
1266 "Content-disposition: attachment; filename=foo\n\n"); | 1300 "Content-disposition: attachment; filename=foo\n\n"); |
1267 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 1301 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
1268 response.size())); | 1302 response.size())); |
1269 std::string response_data("01234567890123456789\x01foobar"); | 1303 std::string response_data("01234567890123456789\x01foobar"); |
1304 // Get past sniffing metrics. | |
1305 response_data.resize(1025, ' '); | |
rvargas (doing something else)
2012/05/29 18:13:36
It seems quite fragile. Hopefully the failure will
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Completely fair, but I'm not coming up with a good
| |
1270 | 1306 |
1271 SetResponse(raw_headers, response_data); | 1307 SetResponse(raw_headers, response_data); |
1272 SetResourceType(ResourceType::MAIN_FRAME); | 1308 SetResourceType(ResourceType::MAIN_FRAME); |
1309 SetDelayedCompleteJobGeneration(true); | |
1273 HandleScheme("http"); | 1310 HandleScheme("http"); |
1274 | 1311 |
1275 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1312 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
1276 // Return some data so that the request is identified as a download | 1313 // Return some data so that the request is identified as a download |
1277 // and the proper resource handlers are created. | 1314 // and the proper resource handlers are created. |
1278 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1315 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1279 | 1316 |
1280 // And now simulate a cancellation coming from the renderer. | 1317 // And now simulate a cancellation coming from the renderer. |
1281 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1318 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); |
1282 bool msg_was_ok; | 1319 bool msg_was_ok; |
(...skipping 12 matching lines...) Expand all Loading... | |
1295 EXPECT_EQ(0, host_.pending_requests()); | 1332 EXPECT_EQ(0, host_.pending_requests()); |
1296 | 1333 |
1297 int render_view_id = 0; | 1334 int render_view_id = 0; |
1298 int request_id = 1; | 1335 int request_id = 1; |
1299 | 1336 |
1300 std::string response("HTTP\n" | 1337 std::string response("HTTP\n" |
1301 "Content-disposition: attachment; filename=foo\n\n"); | 1338 "Content-disposition: attachment; filename=foo\n\n"); |
1302 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 1339 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
1303 response.size())); | 1340 response.size())); |
1304 std::string response_data("01234567890123456789\x01foobar"); | 1341 std::string response_data("01234567890123456789\x01foobar"); |
1342 // Get past sniffing metrics. | |
1343 response_data.resize(1025, ' '); | |
1305 | 1344 |
1306 SetResponse(raw_headers, response_data); | 1345 SetResponse(raw_headers, response_data); |
1307 SetResourceType(ResourceType::MAIN_FRAME); | 1346 SetResourceType(ResourceType::MAIN_FRAME); |
1347 SetDelayedCompleteJobGeneration(true); | |
1308 HandleScheme("http"); | 1348 HandleScheme("http"); |
1309 | 1349 |
1310 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1350 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
1311 // Return some data so that the request is identified as a download | 1351 // Return some data so that the request is identified as a download |
1312 // and the proper resource handlers are created. | 1352 // and the proper resource handlers are created. |
1313 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1353 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1314 | 1354 |
1315 // And now simulate a cancellation coming from the renderer. | 1355 // And now simulate a cancellation coming from the renderer. |
1316 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1356 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); |
1317 bool msg_was_ok; | 1357 bool msg_was_ok; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1400 PickleIterator iter(msgs[0][0]); | 1440 PickleIterator iter(msgs[0][0]); |
1401 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | 1441 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); |
1402 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); | 1442 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); |
1403 | 1443 |
1404 EXPECT_EQ(1, request_id); | 1444 EXPECT_EQ(1, request_id); |
1405 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); | 1445 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); |
1406 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); | 1446 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); |
1407 } | 1447 } |
1408 | 1448 |
1409 } // namespace content | 1449 } // namespace content |
OLD | NEW |