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

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

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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) 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 <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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods 153 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods
154 154
155 void WriteBasicResponse() { 155 void WriteBasicResponse() {
156 static const char kHttpHeaders[] = 156 static const char kHttpHeaders[] =
157 "HTTP/1.0 200 OK\0Content-Length: 5\0\0"; 157 "HTTP/1.0 200 OK\0Content-Length: 5\0\0";
158 static const char* kHttpBody = "Hello"; 158 static const char* kHttpBody = "Hello";
159 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBody)); 159 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBody));
160 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders)); 160 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders));
161 WriteResponse(MakeHttpResponseInfo(raw_headers), body, strlen(kHttpBody)); 161 WriteResponse(
162 MakeHttpResponseInfo(raw_headers), body.get(), strlen(kHttpBody));
162 } 163 }
163 164
164 int basic_response_size() { return 5; } // should match kHttpBody above 165 int basic_response_size() { return 5; } // should match kHttpBody above
165 166
166 void WriteResponse(net::HttpResponseInfo* head, 167 void WriteResponse(net::HttpResponseInfo* head,
167 IOBuffer* body, int body_len) { 168 IOBuffer* body, int body_len) {
168 DCHECK(body); 169 DCHECK(body);
169 scoped_refptr<IOBuffer> body_ref(body); 170 scoped_refptr<IOBuffer> body_ref(body);
170 PushNextTask(base::Bind(&AppCacheResponseTest::WriteResponseBody, 171 PushNextTask(base::Bind(&AppCacheResponseTest::WriteResponseBody,
171 base::Unretained(this), body_ref, body_len)); 172 base::Unretained(this), body_ref, body_len));
172 WriteResponseHead(head); 173 WriteResponseHead(head);
173 } 174 }
174 175
175 void WriteResponseHead(net::HttpResponseInfo* head) { 176 void WriteResponseHead(net::HttpResponseInfo* head) {
176 EXPECT_FALSE(writer_->IsWritePending()); 177 EXPECT_FALSE(writer_->IsWritePending());
177 expected_write_result_ = GetHttpResponseInfoSize(head); 178 expected_write_result_ = GetHttpResponseInfoSize(head);
178 write_info_buffer_ = new HttpResponseInfoIOBuffer(head); 179 write_info_buffer_ = new HttpResponseInfoIOBuffer(head);
179 writer_->WriteInfo( 180 writer_->WriteInfo(write_info_buffer_.get(),
180 write_info_buffer_, 181 base::Bind(&AppCacheResponseTest::OnWriteInfoComplete,
181 base::Bind(&AppCacheResponseTest::OnWriteInfoComplete, 182 base::Unretained(this)));
182 base::Unretained(this)));
183 } 183 }
184 184
185 void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { 185 void WriteResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
186 EXPECT_FALSE(writer_->IsWritePending()); 186 EXPECT_FALSE(writer_->IsWritePending());
187 write_buffer_ = io_buffer; 187 write_buffer_ = io_buffer;
188 expected_write_result_ = buf_len; 188 expected_write_result_ = buf_len;
189 writer_->WriteData( 189 writer_->WriteData(write_buffer_.get(),
190 write_buffer_, buf_len, 190 buf_len,
191 base::Bind(&AppCacheResponseTest::OnWriteComplete, 191 base::Bind(&AppCacheResponseTest::OnWriteComplete,
192 base::Unretained(this))); 192 base::Unretained(this)));
193 } 193 }
194 194
195 void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) { 195 void ReadResponseBody(scoped_refptr<IOBuffer> io_buffer, int buf_len) {
196 EXPECT_FALSE(reader_->IsReadPending()); 196 EXPECT_FALSE(reader_->IsReadPending());
197 read_buffer_ = io_buffer; 197 read_buffer_ = io_buffer;
198 expected_read_result_ = buf_len; 198 expected_read_result_ = buf_len;
199 reader_->ReadData( 199 reader_->ReadData(read_buffer_.get(),
200 read_buffer_, buf_len, 200 buf_len,
201 base::Bind(&AppCacheResponseTest::OnReadComplete, 201 base::Bind(&AppCacheResponseTest::OnReadComplete,
202 base::Unretained(this))); 202 base::Unretained(this)));
203 } 203 }
204 204
205 // AppCacheResponseReader / Writer completion callbacks 205 // AppCacheResponseReader / Writer completion callbacks
206 206
207 void OnWriteInfoComplete(int result) { 207 void OnWriteInfoComplete(int result) {
208 EXPECT_FALSE(writer_->IsWritePending()); 208 EXPECT_FALSE(writer_->IsWritePending());
209 EXPECT_EQ(expected_write_result_, result); 209 EXPECT_EQ(expected_write_result_, result);
210 ScheduleNextTask(); 210 ScheduleNextTask();
211 } 211 }
212 212
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentData, 302 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentData,
303 base::Unretained(this))); 303 base::Unretained(this)));
304 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentInfo, 304 PushNextTask(base::Bind(&AppCacheResponseTest::ReadNonExistentInfo,
305 base::Unretained(this))); 305 base::Unretained(this)));
306 ScheduleNextTask(); 306 ScheduleNextTask();
307 } 307 }
308 308
309 void ReadNonExistentInfo() { 309 void ReadNonExistentInfo() {
310 EXPECT_FALSE(reader_->IsReadPending()); 310 EXPECT_FALSE(reader_->IsReadPending());
311 read_info_buffer_ = new HttpResponseInfoIOBuffer(); 311 read_info_buffer_ = new HttpResponseInfoIOBuffer();
312 reader_->ReadInfo( 312 reader_->ReadInfo(read_info_buffer_.get(),
313 read_info_buffer_, 313 base::Bind(&AppCacheResponseTest::OnReadInfoComplete,
314 base::Bind(&AppCacheResponseTest::OnReadInfoComplete, 314 base::Unretained(this)));
315 base::Unretained(this)));
316 EXPECT_TRUE(reader_->IsReadPending()); 315 EXPECT_TRUE(reader_->IsReadPending());
317 expected_read_result_ = net::ERR_CACHE_MISS; 316 expected_read_result_ = net::ERR_CACHE_MISS;
318 } 317 }
319 318
320 void ReadNonExistentData() { 319 void ReadNonExistentData() {
321 EXPECT_FALSE(reader_->IsReadPending()); 320 EXPECT_FALSE(reader_->IsReadPending());
322 read_buffer_ = new IOBuffer(kBlockSize); 321 read_buffer_ = new IOBuffer(kBlockSize);
323 reader_->ReadData( 322 reader_->ReadData(read_buffer_.get(),
324 read_buffer_, kBlockSize, 323 kBlockSize,
325 base::Bind(&AppCacheResponseTest::OnReadComplete, 324 base::Bind(&AppCacheResponseTest::OnReadComplete,
326 base::Unretained(this))); 325 base::Unretained(this)));
327 EXPECT_TRUE(reader_->IsReadPending()); 326 EXPECT_TRUE(reader_->IsReadPending());
328 expected_read_result_ = net::ERR_CACHE_MISS; 327 expected_read_result_ = net::ERR_CACHE_MISS;
329 } 328 }
330 329
331 // LoadResponseInfo_Miss ---------------------------------------------------- 330 // LoadResponseInfo_Miss ----------------------------------------------------
332 void LoadResponseInfo_Miss() { 331 void LoadResponseInfo_Miss() {
333 PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Miss_Verify, 332 PushNextTask(base::Bind(&AppCacheResponseTest::LoadResponseInfo_Miss_Verify,
334 base::Unretained(this))); 333 base::Unretained(this)));
335 service_->storage()->LoadResponseInfo(GURL(), 0, kNoSuchResponseId, 334 service_->storage()->LoadResponseInfo(GURL(), 0, kNoSuchResponseId,
336 storage_delegate_.get()); 335 storage_delegate_.get());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 char* p = read_buffer_->data(); 491 char* p = read_buffer_->data();
493 for (int i = 0; i < kNumBlocks; ++i, p += kBlockSize) 492 for (int i = 0; i < kNumBlocks; ++i, p += kBlockSize)
494 EXPECT_TRUE(CheckData(i + 1, p, kBlockSize)); 493 EXPECT_TRUE(CheckData(i + 1, p, kBlockSize));
495 ScheduleNextTask(); 494 ScheduleNextTask();
496 } 495 }
497 496
498 void ReadPastEOF() { 497 void ReadPastEOF() {
499 EXPECT_FALSE(reader_->IsReadPending()); 498 EXPECT_FALSE(reader_->IsReadPending());
500 read_buffer_ = new IOBuffer(kBlockSize); 499 read_buffer_ = new IOBuffer(kBlockSize);
501 expected_read_result_ = 0; 500 expected_read_result_ = 0;
502 reader_->ReadData( 501 reader_->ReadData(read_buffer_.get(),
503 read_buffer_, kBlockSize, 502 kBlockSize,
504 base::Bind(&AppCacheResponseTest::OnReadComplete, 503 base::Bind(&AppCacheResponseTest::OnReadComplete,
505 base::Unretained(this))); 504 base::Unretained(this)));
506 } 505 }
507 506
508 void ReadRange() { 507 void ReadRange() {
509 PushNextTask(base::Bind(&AppCacheResponseTest::VerifyRange, 508 PushNextTask(base::Bind(&AppCacheResponseTest::VerifyRange,
510 base::Unretained(this))); 509 base::Unretained(this)));
511 reader_.reset(service_->storage()->CreateResponseReader( 510 reader_.reset(service_->storage()->CreateResponseReader(
512 GURL(), 0, written_response_id_)); 511 GURL(), 0, written_response_id_));
513 reader_->SetReadRange(kBlockSize, kBlockSize); 512 reader_->SetReadRange(kBlockSize, kBlockSize);
514 ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize); 513 ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
515 } 514 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 708
710 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) { 709 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) {
711 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks); 710 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks);
712 } 711 }
713 712
714 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { 713 TEST_F(AppCacheResponseTest, DeleteWithIOPending) {
715 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); 714 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending);
716 } 715 }
717 716
718 } // namespace appcache 717 } // 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