OLD | NEW |
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 "net/http/http_transaction_unittest.h" | 5 #include "net/http/http_transaction_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void TestTransactionConsumer::DidFinish(int result) { | 188 void TestTransactionConsumer::DidFinish(int result) { |
189 state_ = DONE; | 189 state_ = DONE; |
190 error_ = result; | 190 error_ = result; |
191 if (--quit_counter_ == 0) | 191 if (--quit_counter_ == 0) |
192 MessageLoop::current()->Quit(); | 192 MessageLoop::current()->Quit(); |
193 } | 193 } |
194 | 194 |
195 void TestTransactionConsumer::Read() { | 195 void TestTransactionConsumer::Read() { |
196 state_ = READING; | 196 state_ = READING; |
197 read_buf_ = new net::IOBuffer(1024); | 197 read_buf_ = new net::IOBuffer(1024); |
198 int result = trans_->Read(read_buf_, 1024, | 198 int result = trans_->Read(read_buf_.get(), 1024, |
199 base::Bind(&TestTransactionConsumer::OnIOComplete, | 199 base::Bind(&TestTransactionConsumer::OnIOComplete, |
200 base::Unretained(this))); | 200 base::Unretained(this))); |
201 if (result != net::ERR_IO_PENDING) | 201 if (result != net::ERR_IO_PENDING) |
202 DidRead(result); | 202 DidRead(result); |
203 } | 203 } |
204 | 204 |
205 void TestTransactionConsumer::OnIOComplete(int result) { | 205 void TestTransactionConsumer::OnIOComplete(int result) { |
206 switch (state_) { | 206 switch (state_) { |
207 case STARTING: | 207 case STARTING: |
208 DidStart(result); | 208 DidStart(result); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // helpers | 360 // helpers |
361 | 361 |
362 int ReadTransaction(net::HttpTransaction* trans, std::string* result) { | 362 int ReadTransaction(net::HttpTransaction* trans, std::string* result) { |
363 int rv; | 363 int rv; |
364 | 364 |
365 net::TestCompletionCallback callback; | 365 net::TestCompletionCallback callback; |
366 | 366 |
367 std::string content; | 367 std::string content; |
368 do { | 368 do { |
369 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); | 369 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
370 rv = trans->Read(buf, 256, callback.callback()); | 370 rv = trans->Read(buf.get(), 256, callback.callback()); |
371 if (rv == net::ERR_IO_PENDING) | 371 if (rv == net::ERR_IO_PENDING) |
372 rv = callback.WaitForResult(); | 372 rv = callback.WaitForResult(); |
373 | 373 |
374 if (rv > 0) | 374 if (rv > 0) |
375 content.append(buf->data(), rv); | 375 content.append(buf->data(), rv); |
376 else if (rv < 0) | 376 else if (rv < 0) |
377 return rv; | 377 return rv; |
378 } while (rv > 0); | 378 } while (rv > 0); |
379 | 379 |
380 result->swap(content); | 380 result->swap(content); |
381 return net::OK; | 381 return net::OK; |
382 } | 382 } |
OLD | NEW |