| OLD | NEW |
| 1 // Copyright (c) 2010 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 <stack> | 5 #include <stack> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 loaded_info_ = info; | 49 loaded_info_ = info; |
| 50 loaded_info_id_ = response_id; | 50 loaded_info_id_ = response_id; |
| 51 test_->ScheduleNextTask(); | 51 test_->ScheduleNextTask(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 scoped_refptr<AppCacheResponseInfo> loaded_info_; | 54 scoped_refptr<AppCacheResponseInfo> loaded_info_; |
| 55 int64 loaded_info_id_; | 55 int64 loaded_info_id_; |
| 56 AppCacheURLRequestJobTest* test_; | 56 AppCacheURLRequestJobTest* test_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class MockURLRequestDelegate : public URLRequest::Delegate { | 59 class MockURLRequestDelegate : public net::URLRequest::Delegate { |
| 60 public: | 60 public: |
| 61 explicit MockURLRequestDelegate(AppCacheURLRequestJobTest* test) | 61 explicit MockURLRequestDelegate(AppCacheURLRequestJobTest* test) |
| 62 : test_(test), | 62 : test_(test), |
| 63 received_data_(new net::IOBuffer(kNumBlocks * kBlockSize)), | 63 received_data_(new net::IOBuffer(kNumBlocks * kBlockSize)), |
| 64 did_receive_headers_(false), amount_received_(0), | 64 did_receive_headers_(false), amount_received_(0), |
| 65 kill_after_amount_received_(0), kill_with_io_pending_(false) { | 65 kill_after_amount_received_(0), kill_with_io_pending_(false) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual void OnResponseStarted(URLRequest* request) { | 68 virtual void OnResponseStarted(net::URLRequest* request) { |
| 69 amount_received_ = 0; | 69 amount_received_ = 0; |
| 70 did_receive_headers_ = false; | 70 did_receive_headers_ = false; |
| 71 if (request->status().is_success()) { | 71 if (request->status().is_success()) { |
| 72 EXPECT_TRUE(request->response_headers()); | 72 EXPECT_TRUE(request->response_headers()); |
| 73 did_receive_headers_ = true; | 73 did_receive_headers_ = true; |
| 74 received_info_ = request->response_info(); | 74 received_info_ = request->response_info(); |
| 75 ReadSome(request); | 75 ReadSome(request); |
| 76 } else { | 76 } else { |
| 77 RequestComplete(); | 77 RequestComplete(); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 virtual void OnReadCompleted(URLRequest* request, int bytes_read) { | 81 virtual void OnReadCompleted(net::URLRequest* request, int bytes_read) { |
| 82 if (bytes_read > 0) { | 82 if (bytes_read > 0) { |
| 83 amount_received_ += bytes_read; | 83 amount_received_ += bytes_read; |
| 84 | 84 |
| 85 if (kill_after_amount_received_ && !kill_with_io_pending_) { | 85 if (kill_after_amount_received_ && !kill_with_io_pending_) { |
| 86 if (amount_received_ >= kill_after_amount_received_) { | 86 if (amount_received_ >= kill_after_amount_received_) { |
| 87 request->Cancel(); | 87 request->Cancel(); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 ReadSome(request); | 92 ReadSome(request); |
| 93 | 93 |
| 94 if (kill_after_amount_received_ && kill_with_io_pending_) { | 94 if (kill_after_amount_received_ && kill_with_io_pending_) { |
| 95 if (amount_received_ >= kill_after_amount_received_) { | 95 if (amount_received_ >= kill_after_amount_received_) { |
| 96 request->Cancel(); | 96 request->Cancel(); |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } else { | 100 } else { |
| 101 RequestComplete(); | 101 RequestComplete(); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ReadSome(URLRequest* request) { | 105 void ReadSome(net::URLRequest* request) { |
| 106 DCHECK(amount_received_ + kBlockSize <= kNumBlocks * kBlockSize); | 106 DCHECK(amount_received_ + kBlockSize <= kNumBlocks * kBlockSize); |
| 107 scoped_refptr<IOBuffer> wrapped_buffer( | 107 scoped_refptr<IOBuffer> wrapped_buffer( |
| 108 new net::WrappedIOBuffer(received_data_->data() + amount_received_)); | 108 new net::WrappedIOBuffer(received_data_->data() + amount_received_)); |
| 109 int bytes_read = 0; | 109 int bytes_read = 0; |
| 110 EXPECT_FALSE(request->Read(wrapped_buffer, kBlockSize, &bytes_read)); | 110 EXPECT_FALSE(request->Read(wrapped_buffer, kBlockSize, &bytes_read)); |
| 111 EXPECT_EQ(0, bytes_read); | 111 EXPECT_EQ(0, bytes_read); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void RequestComplete() { | 114 void RequestComplete() { |
| 115 test_->ScheduleNextTask(); | 115 test_->ScheduleNextTask(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 AppCacheURLRequestJobTest* test_; | 118 AppCacheURLRequestJobTest* test_; |
| 119 net::HttpResponseInfo received_info_; | 119 net::HttpResponseInfo received_info_; |
| 120 scoped_refptr<net::IOBuffer> received_data_; | 120 scoped_refptr<net::IOBuffer> received_data_; |
| 121 bool did_receive_headers_; | 121 bool did_receive_headers_; |
| 122 int amount_received_; | 122 int amount_received_; |
| 123 int kill_after_amount_received_; | 123 int kill_after_amount_received_; |
| 124 bool kill_with_io_pending_; | 124 bool kill_with_io_pending_; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 static URLRequestJob* MockHttpJobFactory(URLRequest* request, | 127 static URLRequestJob* MockHttpJobFactory(net::URLRequest* request, |
| 128 const std::string& scheme) { | 128 const std::string& scheme) { |
| 129 if (mock_factory_job_) { | 129 if (mock_factory_job_) { |
| 130 URLRequestJob* temp = mock_factory_job_; | 130 URLRequestJob* temp = mock_factory_job_; |
| 131 mock_factory_job_ = NULL; | 131 mock_factory_job_ = NULL; |
| 132 return temp; | 132 return temp; |
| 133 } else { | 133 } else { |
| 134 return new URLRequestErrorJob(request, net::ERR_INTERNET_DISCONNECTED); | 134 return new URLRequestErrorJob(request, net::ERR_INTERNET_DISCONNECTED); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 void RunTestOnIOThread(Method method) { | 179 void RunTestOnIOThread(Method method) { |
| 180 test_finished_event_ .reset(new base::WaitableEvent(false, false)); | 180 test_finished_event_ .reset(new base::WaitableEvent(false, false)); |
| 181 io_thread_->message_loop()->PostTask( | 181 io_thread_->message_loop()->PostTask( |
| 182 FROM_HERE, new WrapperTask<Method>(this, method)); | 182 FROM_HERE, new WrapperTask<Method>(this, method)); |
| 183 test_finished_event_->Wait(); | 183 test_finished_event_->Wait(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void SetUpTest() { | 186 void SetUpTest() { |
| 187 DCHECK(MessageLoop::current() == io_thread_->message_loop()); | 187 DCHECK(MessageLoop::current() == io_thread_->message_loop()); |
| 188 DCHECK(task_stack_.empty()); | 188 DCHECK(task_stack_.empty()); |
| 189 orig_http_factory_ = URLRequest::RegisterProtocolFactory( | 189 orig_http_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 190 "http", MockHttpJobFactory); | 190 "http", MockHttpJobFactory); |
| 191 url_request_delegate_.reset(new MockURLRequestDelegate(this)); | 191 url_request_delegate_.reset(new MockURLRequestDelegate(this)); |
| 192 storage_delegate_.reset(new MockStorageDelegate(this)); | 192 storage_delegate_.reset(new MockStorageDelegate(this)); |
| 193 service_.reset(new MockAppCacheService()); | 193 service_.reset(new MockAppCacheService()); |
| 194 expected_read_result_ = 0; | 194 expected_read_result_ = 0; |
| 195 expected_write_result_ = 0; | 195 expected_write_result_ = 0; |
| 196 written_response_id_ = 0; | 196 written_response_id_ = 0; |
| 197 should_delete_reader_in_completion_callback_ = false; | 197 should_delete_reader_in_completion_callback_ = false; |
| 198 should_delete_writer_in_completion_callback_ = false; | 198 should_delete_writer_in_completion_callback_ = false; |
| 199 reader_deletion_count_down_ = 0; | 199 reader_deletion_count_down_ = 0; |
| 200 writer_deletion_count_down_ = 0; | 200 writer_deletion_count_down_ = 0; |
| 201 read_callback_was_called_ = false; | 201 read_callback_was_called_ = false; |
| 202 write_callback_was_called_ = false; | 202 write_callback_was_called_ = false; |
| 203 } | 203 } |
| 204 | 204 |
| 205 void TearDownTest() { | 205 void TearDownTest() { |
| 206 DCHECK(MessageLoop::current() == io_thread_->message_loop()); | 206 DCHECK(MessageLoop::current() == io_thread_->message_loop()); |
| 207 URLRequest::RegisterProtocolFactory("http", orig_http_factory_); | 207 net::URLRequest::RegisterProtocolFactory("http", orig_http_factory_); |
| 208 orig_http_factory_ = NULL; | 208 orig_http_factory_ = NULL; |
| 209 request_.reset(); | 209 request_.reset(); |
| 210 url_request_delegate_.reset(); | 210 url_request_delegate_.reset(); |
| 211 DCHECK(!mock_factory_job_); | 211 DCHECK(!mock_factory_job_); |
| 212 | 212 |
| 213 while (!task_stack_.empty()) { | 213 while (!task_stack_.empty()) { |
| 214 delete task_stack_.top().first; | 214 delete task_stack_.top().first; |
| 215 task_stack_.pop(); | 215 task_stack_.pop(); |
| 216 } | 216 } |
| 217 reader_.reset(); | 217 reader_.reset(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 return true; | 386 return true; |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Individual Tests --------------------------------------------------------- | 389 // Individual Tests --------------------------------------------------------- |
| 390 // Some of the individual tests involve multiple async steps. Each test | 390 // Some of the individual tests involve multiple async steps. Each test |
| 391 // is delineated with a section header. | 391 // is delineated with a section header. |
| 392 | 392 |
| 393 // Basic ------------------------------------------------------------------- | 393 // Basic ------------------------------------------------------------------- |
| 394 void Basic() { | 394 void Basic() { |
| 395 AppCacheStorage* storage = service_->storage(); | 395 AppCacheStorage* storage = service_->storage(); |
| 396 URLRequest request(GURL("http://blah/"), NULL); | 396 net::URLRequest request(GURL("http://blah/"), NULL); |
| 397 scoped_refptr<AppCacheURLRequestJob> job; | 397 scoped_refptr<AppCacheURLRequestJob> job; |
| 398 | 398 |
| 399 // Create an instance and see that it looks as expected. | 399 // Create an instance and see that it looks as expected. |
| 400 | 400 |
| 401 job = new AppCacheURLRequestJob(&request, storage); | 401 job = new AppCacheURLRequestJob(&request, storage); |
| 402 EXPECT_TRUE(job->is_waiting()); | 402 EXPECT_TRUE(job->is_waiting()); |
| 403 EXPECT_FALSE(job->is_delivering_appcache_response()); | 403 EXPECT_FALSE(job->is_delivering_appcache_response()); |
| 404 EXPECT_FALSE(job->is_delivering_network_response()); | 404 EXPECT_FALSE(job->is_delivering_network_response()); |
| 405 EXPECT_FALSE(job->is_delivering_error_response()); | 405 EXPECT_FALSE(job->is_delivering_error_response()); |
| 406 EXPECT_FALSE(job->has_been_started()); | 406 EXPECT_FALSE(job->has_been_started()); |
| 407 EXPECT_FALSE(job->has_been_killed()); | 407 EXPECT_FALSE(job->has_been_killed()); |
| 408 EXPECT_EQ(GURL(), job->manifest_url()); | 408 EXPECT_EQ(GURL(), job->manifest_url()); |
| 409 EXPECT_EQ(kNoCacheId, job->cache_id()); | 409 EXPECT_EQ(kNoCacheId, job->cache_id()); |
| 410 EXPECT_FALSE(job->entry().has_response_id()); | 410 EXPECT_FALSE(job->entry().has_response_id()); |
| 411 | 411 |
| 412 TestFinished(); | 412 TestFinished(); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // DeliveryOrders ----------------------------------------------------- | 415 // DeliveryOrders ----------------------------------------------------- |
| 416 void DeliveryOrders() { | 416 void DeliveryOrders() { |
| 417 AppCacheStorage* storage = service_->storage(); | 417 AppCacheStorage* storage = service_->storage(); |
| 418 URLRequest request(GURL("http://blah/"), NULL); | 418 net::URLRequest request(GURL("http://blah/"), NULL); |
| 419 scoped_refptr<AppCacheURLRequestJob> job; | 419 scoped_refptr<AppCacheURLRequestJob> job; |
| 420 | 420 |
| 421 // Create an instance, give it a delivery order and see that | 421 // Create an instance, give it a delivery order and see that |
| 422 // it looks as expected. | 422 // it looks as expected. |
| 423 | 423 |
| 424 job = new AppCacheURLRequestJob(&request, storage); | 424 job = new AppCacheURLRequestJob(&request, storage); |
| 425 job->DeliverErrorResponse(); | 425 job->DeliverErrorResponse(); |
| 426 EXPECT_TRUE(job->is_delivering_error_response()); | 426 EXPECT_TRUE(job->is_delivering_error_response()); |
| 427 EXPECT_FALSE(job->has_been_started()); | 427 EXPECT_FALSE(job->has_been_started()); |
| 428 | 428 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 449 | 449 |
| 450 // DeliverNetworkResponse -------------------------------------------------- | 450 // DeliverNetworkResponse -------------------------------------------------- |
| 451 | 451 |
| 452 void DeliverNetworkResponse() { | 452 void DeliverNetworkResponse() { |
| 453 // This test has async steps. | 453 // This test has async steps. |
| 454 PushNextTask(NewRunnableMethod( | 454 PushNextTask(NewRunnableMethod( |
| 455 this, &AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse)); | 455 this, &AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse)); |
| 456 | 456 |
| 457 AppCacheStorage* storage = service_->storage(); | 457 AppCacheStorage* storage = service_->storage(); |
| 458 request_.reset( | 458 request_.reset( |
| 459 new URLRequest(GURL("http://blah/"), url_request_delegate_.get())); | 459 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get())); |
| 460 | 460 |
| 461 // Setup to create an AppCacheURLRequestJob with orders to deliver | 461 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 462 // a network response. | 462 // a network response. |
| 463 mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); | 463 mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); |
| 464 mock_factory_job_->DeliverNetworkResponse(); | 464 mock_factory_job_->DeliverNetworkResponse(); |
| 465 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); | 465 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); |
| 466 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 466 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
| 467 | 467 |
| 468 // Start the request. | 468 // Start the request. |
| 469 request_->Start(); | 469 request_->Start(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 481 | 481 |
| 482 // DeliverErrorResponse -------------------------------------------------- | 482 // DeliverErrorResponse -------------------------------------------------- |
| 483 | 483 |
| 484 void DeliverErrorResponse() { | 484 void DeliverErrorResponse() { |
| 485 // This test has async steps. | 485 // This test has async steps. |
| 486 PushNextTask(NewRunnableMethod( | 486 PushNextTask(NewRunnableMethod( |
| 487 this, &AppCacheURLRequestJobTest::VerifyDeliverErrorResponse)); | 487 this, &AppCacheURLRequestJobTest::VerifyDeliverErrorResponse)); |
| 488 | 488 |
| 489 AppCacheStorage* storage = service_->storage(); | 489 AppCacheStorage* storage = service_->storage(); |
| 490 request_.reset( | 490 request_.reset( |
| 491 new URLRequest(GURL("http://blah/"), url_request_delegate_.get())); | 491 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get())); |
| 492 | 492 |
| 493 // Setup to create an AppCacheURLRequestJob with orders to deliver | 493 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 494 // a network response. | 494 // a network response. |
| 495 mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); | 495 mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); |
| 496 mock_factory_job_->DeliverErrorResponse(); | 496 mock_factory_job_->DeliverErrorResponse(); |
| 497 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); | 497 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); |
| 498 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 498 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
| 499 | 499 |
| 500 // Start the request. | 500 // Start the request. |
| 501 request_->Start(); | 501 request_->Start(); |
| 502 | 502 |
| 503 // The job should have been picked up. | 503 // The job should have been picked up. |
| 504 EXPECT_FALSE(mock_factory_job_); | 504 EXPECT_FALSE(mock_factory_job_); |
| 505 // Completion is async. | 505 // Completion is async. |
| 506 } | 506 } |
| 507 | 507 |
| 508 void VerifyDeliverErrorResponse() { | 508 void VerifyDeliverErrorResponse() { |
| 509 EXPECT_EQ(request_->status().os_error(), net::ERR_FAILED); | 509 EXPECT_EQ(request_->status().os_error(), net::ERR_FAILED); |
| 510 TestFinished(); | 510 TestFinished(); |
| 511 } | 511 } |
| 512 | 512 |
| 513 // DeliverSmallAppCachedResponse -------------------------------------- | 513 // DeliverSmallAppCachedResponse -------------------------------------- |
| 514 // "Small" being small enough to read completely in a single | 514 // "Small" being small enough to read completely in a single |
| 515 // request->Read call. | 515 // request->Read call. |
| 516 | 516 |
| 517 void DeliverSmallAppCachedResponse() { | 517 void DeliverSmallAppCachedResponse() { |
| 518 // This test has several async steps. | 518 // This test has several async steps. |
| 519 // 1. Write a small response to response storage. | 519 // 1. Write a small response to response storage. |
| 520 // 2. Use URLRequest to retrieve it. | 520 // 2. Use net::URLRequest to retrieve it. |
| 521 // 3. Verify we received what we expected to receive. | 521 // 3. Verify we received what we expected to receive. |
| 522 | 522 |
| 523 PushNextTask(NewRunnableMethod( | 523 PushNextTask(NewRunnableMethod( |
| 524 this, &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse)); | 524 this, &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse)); |
| 525 PushNextTask(NewRunnableMethod( | 525 PushNextTask(NewRunnableMethod( |
| 526 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, false)); | 526 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, false)); |
| 527 | 527 |
| 528 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 528 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
| 529 written_response_id_ = writer_->response_id(); | 529 written_response_id_ = writer_->response_id(); |
| 530 WriteBasicResponse(); | 530 WriteBasicResponse(); |
| 531 // Continues async | 531 // Continues async |
| 532 } | 532 } |
| 533 | 533 |
| 534 void RequestAppCachedResource(bool start_after_delivery_orders) { | 534 void RequestAppCachedResource(bool start_after_delivery_orders) { |
| 535 AppCacheStorage* storage = service_->storage(); | 535 AppCacheStorage* storage = service_->storage(); |
| 536 request_.reset( | 536 request_.reset( |
| 537 new URLRequest(GURL("http://blah/"), url_request_delegate_.get())); | 537 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get())); |
| 538 | 538 |
| 539 // Setup to create an AppCacheURLRequestJob with orders to deliver | 539 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 540 // a network response. | 540 // a network response. |
| 541 scoped_refptr<AppCacheURLRequestJob> job( | 541 scoped_refptr<AppCacheURLRequestJob> job( |
| 542 new AppCacheURLRequestJob(request_.get(), storage)); | 542 new AppCacheURLRequestJob(request_.get(), storage)); |
| 543 | 543 |
| 544 if (start_after_delivery_orders) { | 544 if (start_after_delivery_orders) { |
| 545 job->DeliverAppCachedResponse( | 545 job->DeliverAppCachedResponse( |
| 546 GURL(), 111, | 546 GURL(), 111, |
| 547 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 547 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 578 strlen(kHttpBasicBody))); | 578 strlen(kHttpBasicBody))); |
| 579 TestFinished(); | 579 TestFinished(); |
| 580 } | 580 } |
| 581 | 581 |
| 582 // DeliverLargeAppCachedResponse -------------------------------------- | 582 // DeliverLargeAppCachedResponse -------------------------------------- |
| 583 // "Large" enough to require multiple calls to request->Read to complete. | 583 // "Large" enough to require multiple calls to request->Read to complete. |
| 584 | 584 |
| 585 void DeliverLargeAppCachedResponse() { | 585 void DeliverLargeAppCachedResponse() { |
| 586 // This test has several async steps. | 586 // This test has several async steps. |
| 587 // 1. Write a large response to response storage. | 587 // 1. Write a large response to response storage. |
| 588 // 2. Use URLRequest to retrieve it. | 588 // 2. Use net::URLRequest to retrieve it. |
| 589 // 3. Verify we received what we expected to receive. | 589 // 3. Verify we received what we expected to receive. |
| 590 | 590 |
| 591 PushNextTask(NewRunnableMethod( | 591 PushNextTask(NewRunnableMethod( |
| 592 this, &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse)); | 592 this, &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse)); |
| 593 PushNextTask(NewRunnableMethod( | 593 PushNextTask(NewRunnableMethod( |
| 594 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); | 594 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); |
| 595 | 595 |
| 596 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 596 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
| 597 written_response_id_ = writer_->response_id(); | 597 written_response_id_ = writer_->response_id(); |
| 598 WriteLargeResponse(); | 598 WriteLargeResponse(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 621 for (int i = 0; i < 3; ++i, p += kBlockSize) | 621 for (int i = 0; i < 3; ++i, p += kBlockSize) |
| 622 EXPECT_TRUE(CheckData(i + 1, p, kBlockSize)); | 622 EXPECT_TRUE(CheckData(i + 1, p, kBlockSize)); |
| 623 TestFinished(); | 623 TestFinished(); |
| 624 } | 624 } |
| 625 | 625 |
| 626 // DeliverPartialResponse -------------------------------------- | 626 // DeliverPartialResponse -------------------------------------- |
| 627 | 627 |
| 628 void DeliverPartialResponse() { | 628 void DeliverPartialResponse() { |
| 629 // This test has several async steps. | 629 // This test has several async steps. |
| 630 // 1. Write a small response to response storage. | 630 // 1. Write a small response to response storage. |
| 631 // 2. Use URLRequest to retrieve it a subset using a range request | 631 // 2. Use net::URLRequest to retrieve it a subset using a range request |
| 632 // 3. Verify we received what we expected to receive. | 632 // 3. Verify we received what we expected to receive. |
| 633 PushNextTask(NewRunnableMethod( | 633 PushNextTask(NewRunnableMethod( |
| 634 this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse)); | 634 this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse)); |
| 635 PushNextTask(NewRunnableMethod( | 635 PushNextTask(NewRunnableMethod( |
| 636 this, &AppCacheURLRequestJobTest::MakeRangeRequest)); | 636 this, &AppCacheURLRequestJobTest::MakeRangeRequest)); |
| 637 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 637 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
| 638 written_response_id_ = writer_->response_id(); | 638 written_response_id_ = writer_->response_id(); |
| 639 WriteBasicResponse(); | 639 WriteBasicResponse(); |
| 640 // Continues async | 640 // Continues async |
| 641 } | 641 } |
| 642 | 642 |
| 643 void MakeRangeRequest() { | 643 void MakeRangeRequest() { |
| 644 AppCacheStorage* storage = service_->storage(); | 644 AppCacheStorage* storage = service_->storage(); |
| 645 request_.reset( | 645 request_.reset( |
| 646 new URLRequest(GURL("http://blah/"), url_request_delegate_.get())); | 646 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get())); |
| 647 | 647 |
| 648 // Request a range, the 3 middle chars out of 'Hello' | 648 // Request a range, the 3 middle chars out of 'Hello' |
| 649 net::HttpRequestHeaders extra_headers; | 649 net::HttpRequestHeaders extra_headers; |
| 650 extra_headers.SetHeader("Range", "bytes= 1-3"); | 650 extra_headers.SetHeader("Range", "bytes= 1-3"); |
| 651 request_->SetExtraRequestHeaders(extra_headers); | 651 request_->SetExtraRequestHeaders(extra_headers); |
| 652 | 652 |
| 653 // Create job with orders to deliver an appcached entry. | 653 // Create job with orders to deliver an appcached entry. |
| 654 scoped_refptr<AppCacheURLRequestJob> job( | 654 scoped_refptr<AppCacheURLRequestJob> job( |
| 655 new AppCacheURLRequestJob(request_.get(), storage)); | 655 new AppCacheURLRequestJob(request_.get(), storage)); |
| 656 job->DeliverAppCachedResponse( | 656 job->DeliverAppCachedResponse( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 685 EXPECT_EQ(3, range_end); | 685 EXPECT_EQ(3, range_end); |
| 686 EXPECT_EQ(5, object_size); | 686 EXPECT_EQ(5, object_size); |
| 687 TestFinished(); | 687 TestFinished(); |
| 688 } | 688 } |
| 689 | 689 |
| 690 // CancelRequest -------------------------------------- | 690 // CancelRequest -------------------------------------- |
| 691 | 691 |
| 692 void CancelRequest() { | 692 void CancelRequest() { |
| 693 // This test has several async steps. | 693 // This test has several async steps. |
| 694 // 1. Write a large response to response storage. | 694 // 1. Write a large response to response storage. |
| 695 // 2. Use URLRequest to retrieve it. | 695 // 2. Use net::URLRequest to retrieve it. |
| 696 // 3. Cancel the request after data starts coming in. | 696 // 3. Cancel the request after data starts coming in. |
| 697 | 697 |
| 698 PushNextTask(NewRunnableMethod( | 698 PushNextTask(NewRunnableMethod( |
| 699 this, &AppCacheURLRequestJobTest::VerifyCancel)); | 699 this, &AppCacheURLRequestJobTest::VerifyCancel)); |
| 700 PushNextTask(NewRunnableMethod( | 700 PushNextTask(NewRunnableMethod( |
| 701 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); | 701 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); |
| 702 | 702 |
| 703 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 703 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
| 704 written_response_id_ = writer_->response_id(); | 704 written_response_id_ = writer_->response_id(); |
| 705 WriteLargeResponse(); | 705 WriteLargeResponse(); |
| 706 | 706 |
| 707 url_request_delegate_->kill_after_amount_received_ = kBlockSize; | 707 url_request_delegate_->kill_after_amount_received_ = kBlockSize; |
| 708 url_request_delegate_->kill_with_io_pending_ = false; | 708 url_request_delegate_->kill_with_io_pending_ = false; |
| 709 // Continues async | 709 // Continues async |
| 710 } | 710 } |
| 711 | 711 |
| 712 void VerifyCancel() { | 712 void VerifyCancel() { |
| 713 EXPECT_EQ(URLRequestStatus::CANCELED, | 713 EXPECT_EQ(URLRequestStatus::CANCELED, |
| 714 request_->status().status()); | 714 request_->status().status()); |
| 715 TestFinished(); | 715 TestFinished(); |
| 716 } | 716 } |
| 717 | 717 |
| 718 // CancelRequestWithIOPending -------------------------------------- | 718 // CancelRequestWithIOPending -------------------------------------- |
| 719 | 719 |
| 720 void CancelRequestWithIOPending() { | 720 void CancelRequestWithIOPending() { |
| 721 // This test has several async steps. | 721 // This test has several async steps. |
| 722 // 1. Write a large response to response storage. | 722 // 1. Write a large response to response storage. |
| 723 // 2. Use URLRequest to retrieve it. | 723 // 2. Use net::URLRequest to retrieve it. |
| 724 // 3. Cancel the request after data starts coming in. | 724 // 3. Cancel the request after data starts coming in. |
| 725 | 725 |
| 726 PushNextTask(NewRunnableMethod( | 726 PushNextTask(NewRunnableMethod( |
| 727 this, &AppCacheURLRequestJobTest::VerifyCancel)); | 727 this, &AppCacheURLRequestJobTest::VerifyCancel)); |
| 728 PushNextTask(NewRunnableMethod( | 728 PushNextTask(NewRunnableMethod( |
| 729 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); | 729 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); |
| 730 | 730 |
| 731 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 731 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
| 732 written_response_id_ = writer_->response_id(); | 732 written_response_id_ = writer_->response_id(); |
| 733 WriteLargeResponse(); | 733 WriteLargeResponse(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 759 scoped_ptr<AppCacheResponseWriter> writer_; | 759 scoped_ptr<AppCacheResponseWriter> writer_; |
| 760 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; | 760 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; |
| 761 scoped_refptr<IOBuffer> write_buffer_; | 761 scoped_refptr<IOBuffer> write_buffer_; |
| 762 int expected_write_result_; | 762 int expected_write_result_; |
| 763 net::CompletionCallbackImpl<AppCacheURLRequestJobTest> write_callback_; | 763 net::CompletionCallbackImpl<AppCacheURLRequestJobTest> write_callback_; |
| 764 net::CompletionCallbackImpl<AppCacheURLRequestJobTest> write_info_callback_; | 764 net::CompletionCallbackImpl<AppCacheURLRequestJobTest> write_info_callback_; |
| 765 bool should_delete_writer_in_completion_callback_; | 765 bool should_delete_writer_in_completion_callback_; |
| 766 int writer_deletion_count_down_; | 766 int writer_deletion_count_down_; |
| 767 bool write_callback_was_called_; | 767 bool write_callback_was_called_; |
| 768 | 768 |
| 769 URLRequest::ProtocolFactory* orig_http_factory_; | 769 net::URLRequest::ProtocolFactory* orig_http_factory_; |
| 770 scoped_ptr<URLRequest> request_; | 770 scoped_ptr<net::URLRequest> request_; |
| 771 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; | 771 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; |
| 772 | 772 |
| 773 static scoped_ptr<base::Thread> io_thread_; | 773 static scoped_ptr<base::Thread> io_thread_; |
| 774 static AppCacheURLRequestJob* mock_factory_job_; | 774 static AppCacheURLRequestJob* mock_factory_job_; |
| 775 }; | 775 }; |
| 776 | 776 |
| 777 // static | 777 // static |
| 778 scoped_ptr<base::Thread> AppCacheURLRequestJobTest::io_thread_; | 778 scoped_ptr<base::Thread> AppCacheURLRequestJobTest::io_thread_; |
| 779 AppCacheURLRequestJob* AppCacheURLRequestJobTest::mock_factory_job_ = NULL; | 779 AppCacheURLRequestJob* AppCacheURLRequestJobTest::mock_factory_job_ = NULL; |
| 780 | 780 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 | 812 |
| 813 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 813 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
| 814 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 814 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
| 815 } | 815 } |
| 816 | 816 |
| 817 } // namespace appcache | 817 } // namespace appcache |
| 818 | 818 |
| 819 // AppCacheURLRequestJobTest is expected to always live longer than the | 819 // AppCacheURLRequestJobTest is expected to always live longer than the |
| 820 // runnable methods. This lets us call NewRunnableMethod on its instances. | 820 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 821 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); | 821 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); |
| OLD | NEW |