OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stack> | 5 #include <stack> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/base/request_priority.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_error_job.h" | 21 #include "net/url_request/url_request_error_job.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "webkit/browser/appcache/appcache_response.h" | 23 #include "webkit/browser/appcache/appcache_response.h" |
23 #include "webkit/browser/appcache/appcache_url_request_job.h" | 24 #include "webkit/browser/appcache/appcache_url_request_job.h" |
24 #include "webkit/browser/appcache/mock_appcache_service.h" | 25 #include "webkit/browser/appcache/mock_appcache_service.h" |
25 | 26 |
26 using net::IOBuffer; | 27 using net::IOBuffer; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return true; | 370 return true; |
370 } | 371 } |
371 | 372 |
372 // Individual Tests --------------------------------------------------------- | 373 // Individual Tests --------------------------------------------------------- |
373 // Some of the individual tests involve multiple async steps. Each test | 374 // Some of the individual tests involve multiple async steps. Each test |
374 // is delineated with a section header. | 375 // is delineated with a section header. |
375 | 376 |
376 // Basic ------------------------------------------------------------------- | 377 // Basic ------------------------------------------------------------------- |
377 void Basic() { | 378 void Basic() { |
378 AppCacheStorage* storage = service_->storage(); | 379 AppCacheStorage* storage = service_->storage(); |
379 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); | 380 net::URLRequest request( |
| 381 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, &empty_context_); |
380 scoped_refptr<AppCacheURLRequestJob> job; | 382 scoped_refptr<AppCacheURLRequestJob> job; |
381 | 383 |
382 // Create an instance and see that it looks as expected. | 384 // Create an instance and see that it looks as expected. |
383 | 385 |
384 job = new AppCacheURLRequestJob( | 386 job = new AppCacheURLRequestJob( |
385 &request, NULL, storage, NULL); | 387 &request, NULL, storage, NULL); |
386 EXPECT_TRUE(job->is_waiting()); | 388 EXPECT_TRUE(job->is_waiting()); |
387 EXPECT_FALSE(job->is_delivering_appcache_response()); | 389 EXPECT_FALSE(job->is_delivering_appcache_response()); |
388 EXPECT_FALSE(job->is_delivering_network_response()); | 390 EXPECT_FALSE(job->is_delivering_network_response()); |
389 EXPECT_FALSE(job->is_delivering_error_response()); | 391 EXPECT_FALSE(job->is_delivering_error_response()); |
390 EXPECT_FALSE(job->has_been_started()); | 392 EXPECT_FALSE(job->has_been_started()); |
391 EXPECT_FALSE(job->has_been_killed()); | 393 EXPECT_FALSE(job->has_been_killed()); |
392 EXPECT_EQ(GURL(), job->manifest_url()); | 394 EXPECT_EQ(GURL(), job->manifest_url()); |
393 EXPECT_EQ(kNoCacheId, job->cache_id()); | 395 EXPECT_EQ(kNoCacheId, job->cache_id()); |
394 EXPECT_FALSE(job->entry().has_response_id()); | 396 EXPECT_FALSE(job->entry().has_response_id()); |
395 | 397 |
396 TestFinished(); | 398 TestFinished(); |
397 } | 399 } |
398 | 400 |
399 // DeliveryOrders ----------------------------------------------------- | 401 // DeliveryOrders ----------------------------------------------------- |
400 void DeliveryOrders() { | 402 void DeliveryOrders() { |
401 AppCacheStorage* storage = service_->storage(); | 403 AppCacheStorage* storage = service_->storage(); |
402 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); | 404 net::URLRequest request( |
| 405 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, &empty_context_); |
403 scoped_refptr<AppCacheURLRequestJob> job; | 406 scoped_refptr<AppCacheURLRequestJob> job; |
404 | 407 |
405 // Create an instance, give it a delivery order and see that | 408 // Create an instance, give it a delivery order and see that |
406 // it looks as expected. | 409 // it looks as expected. |
407 | 410 |
408 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL); | 411 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL); |
409 job->DeliverErrorResponse(); | 412 job->DeliverErrorResponse(); |
410 EXPECT_TRUE(job->is_delivering_error_response()); | 413 EXPECT_TRUE(job->is_delivering_error_response()); |
411 EXPECT_FALSE(job->has_been_started()); | 414 EXPECT_FALSE(job->has_been_started()); |
412 | 415 |
(...skipping 23 matching lines...) Expand all Loading... |
436 | 439 |
437 // DeliverNetworkResponse -------------------------------------------------- | 440 // DeliverNetworkResponse -------------------------------------------------- |
438 | 441 |
439 void DeliverNetworkResponse() { | 442 void DeliverNetworkResponse() { |
440 // This test has async steps. | 443 // This test has async steps. |
441 PushNextTask( | 444 PushNextTask( |
442 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, | 445 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, |
443 base::Unretained(this))); | 446 base::Unretained(this))); |
444 | 447 |
445 AppCacheStorage* storage = service_->storage(); | 448 AppCacheStorage* storage = service_->storage(); |
446 request_.reset(empty_context_.CreateRequest( | 449 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
447 GURL("http://blah/"), url_request_delegate_.get())); | 450 net::DEFAULT_PRIORITY, |
| 451 url_request_delegate_.get()); |
448 | 452 |
449 // Setup to create an AppCacheURLRequestJob with orders to deliver | 453 // Setup to create an AppCacheURLRequestJob with orders to deliver |
450 // a network response. | 454 // a network response. |
451 mock_factory_job_ = new AppCacheURLRequestJob( | 455 mock_factory_job_ = new AppCacheURLRequestJob( |
452 request_.get(), NULL, storage, NULL); | 456 request_.get(), NULL, storage, NULL); |
453 mock_factory_job_->DeliverNetworkResponse(); | 457 mock_factory_job_->DeliverNetworkResponse(); |
454 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); | 458 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); |
455 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 459 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
456 | 460 |
457 // Start the request. | 461 // Start the request. |
(...skipping 12 matching lines...) Expand all Loading... |
470 | 474 |
471 // DeliverErrorResponse -------------------------------------------------- | 475 // DeliverErrorResponse -------------------------------------------------- |
472 | 476 |
473 void DeliverErrorResponse() { | 477 void DeliverErrorResponse() { |
474 // This test has async steps. | 478 // This test has async steps. |
475 PushNextTask( | 479 PushNextTask( |
476 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, | 480 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, |
477 base::Unretained(this))); | 481 base::Unretained(this))); |
478 | 482 |
479 AppCacheStorage* storage = service_->storage(); | 483 AppCacheStorage* storage = service_->storage(); |
480 request_.reset(empty_context_.CreateRequest(GURL( | 484 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
481 "http://blah/"), url_request_delegate_.get())); | 485 net::DEFAULT_PRIORITY, |
| 486 url_request_delegate_.get()); |
482 | 487 |
483 // Setup to create an AppCacheURLRequestJob with orders to deliver | 488 // Setup to create an AppCacheURLRequestJob with orders to deliver |
484 // a network response. | 489 // a network response. |
485 mock_factory_job_ = new AppCacheURLRequestJob( | 490 mock_factory_job_ = new AppCacheURLRequestJob( |
486 request_.get(), NULL, storage, NULL); | 491 request_.get(), NULL, storage, NULL); |
487 mock_factory_job_->DeliverErrorResponse(); | 492 mock_factory_job_->DeliverErrorResponse(); |
488 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); | 493 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); |
489 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 494 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
490 | 495 |
491 // Start the request. | 496 // Start the request. |
(...skipping 27 matching lines...) Expand all Loading... |
519 base::Unretained(this), false)); | 524 base::Unretained(this), false)); |
520 | 525 |
521 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 526 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
522 written_response_id_ = writer_->response_id(); | 527 written_response_id_ = writer_->response_id(); |
523 WriteBasicResponse(); | 528 WriteBasicResponse(); |
524 // Continues async | 529 // Continues async |
525 } | 530 } |
526 | 531 |
527 void RequestAppCachedResource(bool start_after_delivery_orders) { | 532 void RequestAppCachedResource(bool start_after_delivery_orders) { |
528 AppCacheStorage* storage = service_->storage(); | 533 AppCacheStorage* storage = service_->storage(); |
529 request_.reset(empty_context_.CreateRequest( | 534 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
530 GURL("http://blah/"), url_request_delegate_.get())); | 535 net::DEFAULT_PRIORITY, |
| 536 url_request_delegate_.get()); |
531 | 537 |
532 // Setup to create an AppCacheURLRequestJob with orders to deliver | 538 // Setup to create an AppCacheURLRequestJob with orders to deliver |
533 // a network response. | 539 // a network response. |
534 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 540 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
535 request_.get(), NULL, storage, NULL)); | 541 request_.get(), NULL, storage, NULL)); |
536 | 542 |
537 if (start_after_delivery_orders) { | 543 if (start_after_delivery_orders) { |
538 job->DeliverAppCachedResponse( | 544 job->DeliverAppCachedResponse( |
539 GURL(), 0, 111, | 545 GURL(), 0, 111, |
540 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 546 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 PushNextTask(base::Bind( | 638 PushNextTask(base::Bind( |
633 &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this))); | 639 &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this))); |
634 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 640 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
635 written_response_id_ = writer_->response_id(); | 641 written_response_id_ = writer_->response_id(); |
636 WriteBasicResponse(); | 642 WriteBasicResponse(); |
637 // Continues async | 643 // Continues async |
638 } | 644 } |
639 | 645 |
640 void MakeRangeRequest() { | 646 void MakeRangeRequest() { |
641 AppCacheStorage* storage = service_->storage(); | 647 AppCacheStorage* storage = service_->storage(); |
642 request_.reset(empty_context_.CreateRequest( | 648 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
643 GURL("http://blah/"), url_request_delegate_.get())); | 649 net::DEFAULT_PRIORITY, |
| 650 url_request_delegate_.get()); |
644 | 651 |
645 // Request a range, the 3 middle chars out of 'Hello' | 652 // Request a range, the 3 middle chars out of 'Hello' |
646 net::HttpRequestHeaders extra_headers; | 653 net::HttpRequestHeaders extra_headers; |
647 extra_headers.SetHeader("Range", "bytes= 1-3"); | 654 extra_headers.SetHeader("Range", "bytes= 1-3"); |
648 request_->SetExtraRequestHeaders(extra_headers); | 655 request_->SetExtraRequestHeaders(extra_headers); |
649 | 656 |
650 // Create job with orders to deliver an appcached entry. | 657 // Create job with orders to deliver an appcached entry. |
651 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 658 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
652 request_.get(), NULL, storage, NULL)); | 659 request_.get(), NULL, storage, NULL)); |
653 job->DeliverAppCachedResponse( | 660 job->DeliverAppCachedResponse( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 | 807 |
801 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 808 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
802 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 809 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
803 } | 810 } |
804 | 811 |
805 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 812 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
806 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
807 } | 814 } |
808 | 815 |
809 } // namespace appcache | 816 } // namespace appcache |
OLD | NEW |