Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: webkit/appcache/appcache_response_unittest.cc

Issue 8991001: base::Bind: Convert most of webkit/appcache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix 2. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_response.cc ('k') | webkit/appcache/appcache_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 static void SetUpTestCase() { 75 static void SetUpTestCase() {
76 io_thread_.reset(new base::Thread("AppCacheResponseTest Thread")); 76 io_thread_.reset(new base::Thread("AppCacheResponseTest Thread"));
77 base::Thread::Options options(MessageLoop::TYPE_IO, 0); 77 base::Thread::Options options(MessageLoop::TYPE_IO, 0);
78 io_thread_->StartWithOptions(options); 78 io_thread_->StartWithOptions(options);
79 } 79 }
80 80
81 static void TearDownTestCase() { 81 static void TearDownTestCase() {
82 io_thread_.reset(NULL); 82 io_thread_.reset(NULL);
83 } 83 }
84 84
85 AppCacheResponseTest() 85 AppCacheResponseTest() {}
86 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
87 this, &AppCacheResponseTest::OnReadComplete)),
88 ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
89 this, &AppCacheResponseTest::OnReadInfoComplete)),
90 ALLOW_THIS_IN_INITIALIZER_LIST(write_callback_(
91 this, &AppCacheResponseTest::OnWriteComplete)),
92 ALLOW_THIS_IN_INITIALIZER_LIST(write_info_callback_(
93 this, &AppCacheResponseTest::OnWriteInfoComplete)) {
94 }
95 86
96 template <class Method> 87 template <class Method>
97 void RunTestOnIOThread(Method method) { 88 void RunTestOnIOThread(Method method) {
98 test_finished_event_ .reset(new base::WaitableEvent(false, false)); 89 test_finished_event_ .reset(new base::WaitableEvent(false, false));
99 io_thread_->message_loop()->PostTask( 90 io_thread_->message_loop()->PostTask(
100 FROM_HERE, new WrapperTask<Method>(this, method)); 91 FROM_HERE, new WrapperTask<Method>(this, method));
101 test_finished_event_->Wait(); 92 test_finished_event_->Wait();
102 } 93 }
103 94
104 void SetUpTest() { 95 void SetUpTest() {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 scoped_refptr<IOBuffer> body_ref(body); 179 scoped_refptr<IOBuffer> body_ref(body);
189 PushNextTask(base::Bind(&AppCacheResponseTest::WriteResponseBody, 180 PushNextTask(base::Bind(&AppCacheResponseTest::WriteResponseBody,
190 base::Unretained(this), body_ref, body_len)); 181 base::Unretained(this), body_ref, body_len));
191 WriteResponseHead(head); 182 WriteResponseHead(head);
192 } 183 }
193 184
194 void WriteResponseHead(net::HttpResponseInfo* head) { 185 void WriteResponseHead(net::HttpResponseInfo* head) {
195 EXPECT_FALSE(writer_->IsWritePending()); 186 EXPECT_FALSE(writer_->IsWritePending());
196 expected_write_result_ = GetHttpResponseInfoSize(head); 187 expected_write_result_ = GetHttpResponseInfoSize(head);
197 write_info_buffer_ = new HttpResponseInfoIOBuffer(head); 188 write_info_buffer_ = new HttpResponseInfoIOBuffer(head);
198 writer_->WriteInfo(write_info_buffer_, &write_info_callback_); 189 writer_->WriteInfo(
190 write_info_buffer_,
191 base::Bind(&AppCacheResponseTest::OnWriteInfoComplete,
192 base::Unretained(this)));
199 } 193 }
200 194
201 void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { 195 void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
202 EXPECT_FALSE(writer_->IsWritePending()); 196 EXPECT_FALSE(writer_->IsWritePending());
203 write_buffer_ = io_buffer; 197 write_buffer_ = io_buffer;
204 expected_write_result_ = buf_len; 198 expected_write_result_ = buf_len;
205 writer_->WriteData( 199 writer_->WriteData(
206 write_buffer_, buf_len, &write_callback_); 200 write_buffer_, buf_len,
201 base::Bind(&AppCacheResponseTest::OnWriteComplete,
202 base::Unretained(this)));
207 } 203 }
208 204
209 void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { 205 void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
210 EXPECT_FALSE(reader_->IsReadPending()); 206 EXPECT_FALSE(reader_->IsReadPending());
211 read_buffer_ = io_buffer; 207 read_buffer_ = io_buffer;
212 expected_read_result_ = buf_len; 208 expected_read_result_ = buf_len;
213 reader_->ReadData( 209 reader_->ReadData(
214 read_buffer_, buf_len, &read_callback_); 210 read_buffer_, buf_len,
211 base::Bind(&AppCacheResponseTest::OnReadComplete,
212 base::Unretained(this)));
215 } 213 }
216 214
217 // AppCacheResponseReader / Writer completion callbacks 215 // AppCacheResponseReader / Writer completion callbacks
218 216
219 void OnWriteInfoComplete(int result) { 217 void OnWriteInfoComplete(int result) {
220 EXPECT_FALSE(writer_->IsWritePending()); 218 EXPECT_FALSE(writer_->IsWritePending());
221 EXPECT_EQ(expected_write_result_, result); 219 EXPECT_EQ(expected_write_result_, result);
222 ScheduleNextTask(); 220 ScheduleNextTask();
223 } 221 }
224 222
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentData, 312 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentData,
315 base::Unretained(this))); 313 base::Unretained(this)));
316 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentInfo, 314 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentInfo,
317 base::Unretained(this))); 315 base::Unretained(this)));
318 ScheduleNextTask(); 316 ScheduleNextTask();
319 } 317 }
320 318
321 void ReadNonExistentInfo() { 319 void ReadNonExistentInfo() {
322 EXPECT_FALSE(reader_->IsReadPending()); 320 EXPECT_FALSE(reader_->IsReadPending());
323 read_info_buffer_ = new HttpResponseInfoIOBuffer(); 321 read_info_buffer_ = new HttpResponseInfoIOBuffer();
324 reader_->ReadInfo(read_info_buffer_, &read_info_callback_); 322 reader_->ReadInfo(
323 read_info_buffer_,
324 base::Bind(&AppCacheResponseTest::OnReadInfoComplete,
325 base::Unretained(this)));
325 EXPECT_TRUE(reader_->IsReadPending()); 326 EXPECT_TRUE(reader_->IsReadPending());
326 expected_read_result_ = net::ERR_CACHE_MISS; 327 expected_read_result_ = net::ERR_CACHE_MISS;
327 } 328 }
328 329
329 void ReadNonExistentData() { 330 void ReadNonExistentData() {
330 EXPECT_FALSE(reader_->IsReadPending()); 331 EXPECT_FALSE(reader_->IsReadPending());
331 read_buffer_ = new IOBuffer(kBlockSize); 332 read_buffer_ = new IOBuffer(kBlockSize);
332 reader_->ReadData(read_buffer_, kBlockSize, &read_callback_); 333 reader_->ReadData(
334 read_buffer_, kBlockSize,
335 base::Bind(&AppCacheResponseTest::OnReadComplete,
336 base::Unretained(this)));
333 EXPECT_TRUE(reader_->IsReadPending()); 337 EXPECT_TRUE(reader_->IsReadPending());
334 expected_read_result_ = net::ERR_CACHE_MISS; 338 expected_read_result_ = net::ERR_CACHE_MISS;
335 } 339 }
336 340
337 // LoadResponseInfo_Miss ---------------------------------------------------- 341 // LoadResponseInfo_Miss ----------------------------------------------------
338 void LoadResponseInfo_Miss() { 342 void LoadResponseInfo_Miss() {
339 PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Miss_Verify, 343 PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Miss_Verify,
340 base::Unretained(this))); 344 base::Unretained(this)));
341 service_->storage()->LoadResponseInfo(GURL(), 0, kNoSuchResponseId, 345 service_->storage()->LoadResponseInfo(GURL(), 0, kNoSuchResponseId,
342 storage_delegate_.get()); 346 storage_delegate_.get());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 for (int i = 0; i < kNumBlocks; ++i, p += kBlockSize) 503 for (int i = 0; i < kNumBlocks; ++i, p += kBlockSize)
500 EXPECT_TRUE(CheckData(i + 1, p, kBlockSize)); 504 EXPECT_TRUE(CheckData(i + 1, p, kBlockSize));
501 ScheduleNextTask(); 505 ScheduleNextTask();
502 } 506 }
503 507
504 void ReadPastEOF() { 508 void ReadPastEOF() {
505 EXPECT_FALSE(reader_->IsReadPending()); 509 EXPECT_FALSE(reader_->IsReadPending());
506 read_buffer_ = new IOBuffer(kBlockSize); 510 read_buffer_ = new IOBuffer(kBlockSize);
507 expected_read_result_ = 0; 511 expected_read_result_ = 0;
508 reader_->ReadData( 512 reader_->ReadData(
509 read_buffer_, kBlockSize, &read_callback_); 513 read_buffer_, kBlockSize,
514 base::Bind(&AppCacheResponseTest::OnReadComplete,
515 base::Unretained(this)));
510 } 516 }
511 517
512 void ReadRange() { 518 void ReadRange() {
513 PushNextTask(base::Bind(&AppCacheResponseTest::VerifyRange, 519 PushNextTask(base::Bind(&AppCacheResponseTest::VerifyRange,
514 base::Unretained(this))); 520 base::Unretained(this)));
515 reader_.reset(service_->storage()->CreateResponseReader( 521 reader_.reset(service_->storage()->CreateResponseReader(
516 GURL(), 0, written_response_id_)); 522 GURL(), 0, written_response_id_));
517 reader_->SetReadRange(kBlockSize, kBlockSize); 523 reader_->SetReadRange(kBlockSize, kBlockSize);
518 ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize); 524 ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
519 } 525 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 667
662 scoped_ptr<base::WaitableEvent> test_finished_event_; 668 scoped_ptr<base::WaitableEvent> test_finished_event_;
663 scoped_ptr<MockStorageDelegate> storage_delegate_; 669 scoped_ptr<MockStorageDelegate> storage_delegate_;
664 scoped_ptr<MockAppCacheService> service_; 670 scoped_ptr<MockAppCacheService> service_;
665 std::stack<std::pair<base::Closure, bool> > task_stack_; 671 std::stack<std::pair<base::Closure, bool> > task_stack_;
666 672
667 scoped_ptr<AppCacheResponseReader> reader_; 673 scoped_ptr<AppCacheResponseReader> reader_;
668 scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_; 674 scoped_refptr<HttpResponseInfoIOBuffer> read_info_buffer_;
669 scoped_refptr<IOBuffer> read_buffer_; 675 scoped_refptr<IOBuffer> read_buffer_;
670 int expected_read_result_; 676 int expected_read_result_;
671 net::OldCompletionCallbackImpl<AppCacheResponseTest> read_callback_;
672 net::OldCompletionCallbackImpl<AppCacheResponseTest> read_info_callback_;
673 bool should_delete_reader_in_completion_callback_; 677 bool should_delete_reader_in_completion_callback_;
674 int reader_deletion_count_down_; 678 int reader_deletion_count_down_;
675 bool read_callback_was_called_; 679 bool read_callback_was_called_;
676 680
677 int64 written_response_id_; 681 int64 written_response_id_;
678 scoped_ptr<AppCacheResponseWriter> writer_; 682 scoped_ptr<AppCacheResponseWriter> writer_;
679 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; 683 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_;
680 scoped_refptr<IOBuffer> write_buffer_; 684 scoped_refptr<IOBuffer> write_buffer_;
681 int expected_write_result_; 685 int expected_write_result_;
682 net::OldCompletionCallbackImpl<AppCacheResponseTest> write_callback_;
683 net::OldCompletionCallbackImpl<AppCacheResponseTest> write_info_callback_;
684 bool should_delete_writer_in_completion_callback_; 686 bool should_delete_writer_in_completion_callback_;
685 int writer_deletion_count_down_; 687 int writer_deletion_count_down_;
686 bool write_callback_was_called_; 688 bool write_callback_was_called_;
687 689
688 static scoped_ptr<base::Thread> io_thread_; 690 static scoped_ptr<base::Thread> io_thread_;
689 }; 691 };
690 692
691 // static 693 // static
692 scoped_ptr<base::Thread> AppCacheResponseTest::io_thread_; 694 scoped_ptr<base::Thread> AppCacheResponseTest::io_thread_;
693 695
(...skipping 23 matching lines...) Expand all
717 719
718 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) { 720 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) {
719 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks); 721 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks);
720 } 722 }
721 723
722 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { 724 TEST_F(AppCacheResponseTest, DeleteWithIOPending) {
723 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); 725 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending);
724 } 726 }
725 727
726 } // namespace appcache 728 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_response.cc ('k') | webkit/appcache/appcache_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698