| 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" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 io_thread_.reset(new base::Thread("AppCacheURLRequestJobTest Thread")); | 162 io_thread_.reset(new base::Thread("AppCacheURLRequestJobTest Thread")); |
| 163 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 163 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
| 164 io_thread_->StartWithOptions(options); | 164 io_thread_->StartWithOptions(options); |
| 165 } | 165 } |
| 166 | 166 |
| 167 static void TearDownTestCase() { | 167 static void TearDownTestCase() { |
| 168 io_thread_.reset(NULL); | 168 io_thread_.reset(NULL); |
| 169 } | 169 } |
| 170 | 170 |
| 171 AppCacheURLRequestJobTest() | 171 AppCacheURLRequestJobTest() |
| 172 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 172 : ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_( |
| 173 this, &AppCacheURLRequestJobTest::OnReadComplete)), | 173 this, &AppCacheURLRequestJobTest::OnReadInfoComplete)) { |
| 174 ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_( | |
| 175 this, &AppCacheURLRequestJobTest::OnReadInfoComplete)), | |
| 176 ALLOW_THIS_IN_INITIALIZER_LIST(write_callback_( | |
| 177 this, &AppCacheURLRequestJobTest::OnWriteComplete)), | |
| 178 ALLOW_THIS_IN_INITIALIZER_LIST(write_info_callback_( | |
| 179 this, &AppCacheURLRequestJobTest::OnWriteInfoComplete)) { | |
| 180 } | 174 } |
| 181 | 175 |
| 182 template <class Method> | 176 template <class Method> |
| 183 void RunTestOnIOThread(Method method) { | 177 void RunTestOnIOThread(Method method) { |
| 184 test_finished_event_ .reset(new base::WaitableEvent(false, false)); | 178 test_finished_event_ .reset(new base::WaitableEvent(false, false)); |
| 185 io_thread_->message_loop()->PostTask( | 179 io_thread_->message_loop()->PostTask( |
| 186 FROM_HERE, new WrapperTask<Method>(this, method)); | 180 FROM_HERE, new WrapperTask<Method>(this, method)); |
| 187 test_finished_event_->Wait(); | 181 test_finished_event_->Wait(); |
| 188 } | 182 } |
| 189 | 183 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 scoped_refptr<IOBuffer> body_ref(body); | 274 scoped_refptr<IOBuffer> body_ref(body); |
| 281 PushNextTask(base::Bind(&AppCacheURLRequestJobTest::WriteResponseBody, | 275 PushNextTask(base::Bind(&AppCacheURLRequestJobTest::WriteResponseBody, |
| 282 base::Unretained(this), body_ref, body_len)); | 276 base::Unretained(this), body_ref, body_len)); |
| 283 WriteResponseHead(head); | 277 WriteResponseHead(head); |
| 284 } | 278 } |
| 285 | 279 |
| 286 void WriteResponseHead(net::HttpResponseInfo* head) { | 280 void WriteResponseHead(net::HttpResponseInfo* head) { |
| 287 EXPECT_FALSE(writer_->IsWritePending()); | 281 EXPECT_FALSE(writer_->IsWritePending()); |
| 288 expected_write_result_ = GetHttpResponseInfoSize(head); | 282 expected_write_result_ = GetHttpResponseInfoSize(head); |
| 289 write_info_buffer_ = new HttpResponseInfoIOBuffer(head); | 283 write_info_buffer_ = new HttpResponseInfoIOBuffer(head); |
| 290 writer_->WriteInfo(write_info_buffer_, &write_info_callback_); | 284 writer_->WriteInfo( |
| 285 write_info_buffer_, |
| 286 base::Bind(&AppCacheURLRequestJobTest::OnWriteInfoComplete, |
| 287 base::Unretained(this))); |
| 291 } | 288 } |
| 292 | 289 |
| 293 void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { | 290 void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { |
| 294 EXPECT_FALSE(writer_->IsWritePending()); | 291 EXPECT_FALSE(writer_->IsWritePending()); |
| 295 write_buffer_ = io_buffer; | 292 write_buffer_ = io_buffer; |
| 296 expected_write_result_ = buf_len; | 293 expected_write_result_ = buf_len; |
| 297 writer_->WriteData( | 294 writer_->WriteData( |
| 298 write_buffer_, buf_len, &write_callback_); | 295 write_buffer_, buf_len, |
| 296 base::Bind(&AppCacheURLRequestJobTest::OnWriteComplete, |
| 297 base::Unretained(this))); |
| 299 } | 298 } |
| 300 | 299 |
| 301 void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { | 300 void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { |
| 302 EXPECT_FALSE(reader_->IsReadPending()); | 301 EXPECT_FALSE(reader_->IsReadPending()); |
| 303 read_buffer_ = io_buffer; | 302 read_buffer_ = io_buffer; |
| 304 expected_read_result_ = buf_len; | 303 expected_read_result_ = buf_len; |
| 305 reader_->ReadData( | 304 reader_->ReadData( |
| 306 read_buffer_, buf_len, &read_callback_); | 305 read_buffer_, buf_len, |
| 306 base::Bind(&AppCacheURLRequestJobTest::OnReadComplete, |
| 307 base::Unretained(this))); |
| 307 } | 308 } |
| 308 | 309 |
| 309 // AppCacheResponseReader / Writer completion callbacks | 310 // AppCacheResponseReader / Writer completion callbacks |
| 310 | 311 |
| 311 void OnWriteInfoComplete(int result) { | 312 void OnWriteInfoComplete(int result) { |
| 312 EXPECT_FALSE(writer_->IsWritePending()); | 313 EXPECT_FALSE(writer_->IsWritePending()); |
| 313 EXPECT_EQ(expected_write_result_, result); | 314 EXPECT_EQ(expected_write_result_, result); |
| 314 ScheduleNextTask(); | 315 ScheduleNextTask(); |
| 315 } | 316 } |
| 316 | 317 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 | 758 |
| 758 scoped_ptr<base::WaitableEvent> test_finished_event_; | 759 scoped_ptr<base::WaitableEvent> test_finished_event_; |
| 759 scoped_ptr<MockStorageDelegate> storage_delegate_; | 760 scoped_ptr<MockStorageDelegate> storage_delegate_; |
| 760 scoped_ptr<MockAppCacheService> service_; | 761 scoped_ptr<MockAppCacheService> service_; |
| 761 std::stack<std::pair<base::Closure, bool> > task_stack_; | 762 std::stack<std::pair<base::Closure, bool> > task_stack_; |
| 762 | 763 |
| 763 scoped_ptr<AppCacheResponseReader> reader_; | 764 scoped_ptr<AppCacheResponseReader> reader_; |
| 764 scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_; | 765 scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_; |
| 765 scoped_refptr<IOBuffer> read_buffer_; | 766 scoped_refptr<IOBuffer> read_buffer_; |
| 766 int expected_read_result_; | 767 int expected_read_result_; |
| 767 net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> read_callback_; | |
| 768 net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> read_info_callback_; | 768 net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> read_info_callback_; |
| 769 bool should_delete_reader_in_completion_callback_; | 769 bool should_delete_reader_in_completion_callback_; |
| 770 int reader_deletion_count_down_; | 770 int reader_deletion_count_down_; |
| 771 bool read_callback_was_called_; | 771 bool read_callback_was_called_; |
| 772 | 772 |
| 773 int64 written_response_id_; | 773 int64 written_response_id_; |
| 774 scoped_ptr<AppCacheResponseWriter> writer_; | 774 scoped_ptr<AppCacheResponseWriter> writer_; |
| 775 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; | 775 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; |
| 776 scoped_refptr<IOBuffer> write_buffer_; | 776 scoped_refptr<IOBuffer> write_buffer_; |
| 777 int expected_write_result_; | 777 int expected_write_result_; |
| 778 net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> write_callback_; | |
| 779 net::OldCompletionCallbackImpl<AppCacheURLRequestJobTest> write_info_callback_
; | |
| 780 bool should_delete_writer_in_completion_callback_; | 778 bool should_delete_writer_in_completion_callback_; |
| 781 int writer_deletion_count_down_; | 779 int writer_deletion_count_down_; |
| 782 bool write_callback_was_called_; | 780 bool write_callback_was_called_; |
| 783 | 781 |
| 784 net::URLRequest::ProtocolFactory* orig_http_factory_; | 782 net::URLRequest::ProtocolFactory* orig_http_factory_; |
| 785 scoped_ptr<net::URLRequest> request_; | 783 scoped_ptr<net::URLRequest> request_; |
| 786 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; | 784 scoped_ptr<MockURLRequestDelegate> url_request_delegate_; |
| 787 | 785 |
| 788 static scoped_ptr<base::Thread> io_thread_; | 786 static scoped_ptr<base::Thread> io_thread_; |
| 789 static AppCacheURLRequestJob* mock_factory_job_; | 787 static AppCacheURLRequestJob* mock_factory_job_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 821 |
| 824 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 822 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
| 825 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 823 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
| 826 } | 824 } |
| 827 | 825 |
| 828 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 826 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
| 829 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 827 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
| 830 } | 828 } |
| 831 | 829 |
| 832 } // namespace appcache | 830 } // namespace appcache |
| OLD | NEW |