| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 DidRead(result); | 211 DidRead(result); |
| 212 break; | 212 break; |
| 213 default: | 213 default: |
| 214 NOTREACHED(); | 214 NOTREACHED(); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 MockNetworkTransaction::MockNetworkTransaction(MockNetworkLayer* factory) | 218 MockNetworkTransaction::MockNetworkTransaction(MockNetworkLayer* factory) |
| 219 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 219 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 220 data_cursor_(0), | 220 data_cursor_(0), |
| 221 priority_(net::IDLE), |
| 221 transaction_factory_(factory->AsWeakPtr()) { | 222 transaction_factory_(factory->AsWeakPtr()) { |
| 222 } | 223 } |
| 223 | 224 |
| 224 MockNetworkTransaction::~MockNetworkTransaction() {} | 225 MockNetworkTransaction::~MockNetworkTransaction() {} |
| 225 | 226 |
| 226 int MockNetworkTransaction::Start(const net::HttpRequestInfo* request, | 227 int MockNetworkTransaction::Start(const net::HttpRequestInfo* request, |
| 227 const net::CompletionCallback& callback, | 228 const net::CompletionCallback& callback, |
| 228 const net::BoundNetLog& net_log) { | 229 const net::BoundNetLog& net_log) { |
| 230 priority_ = request->priority; |
| 231 |
| 229 const MockTransaction* t = FindMockTransaction(request->url); | 232 const MockTransaction* t = FindMockTransaction(request->url); |
| 230 if (!t) | 233 if (!t) |
| 231 return net::ERR_FAILED; | 234 return net::ERR_FAILED; |
| 232 | 235 |
| 233 std::string resp_status = t->status; | 236 std::string resp_status = t->status; |
| 234 std::string resp_headers = t->response_headers; | 237 std::string resp_headers = t->response_headers; |
| 235 std::string resp_data = t->data; | 238 std::string resp_data = t->data; |
| 236 if (t->handler) | 239 if (t->handler) |
| 237 (t->handler)(request, &resp_status, &resp_headers, &resp_data); | 240 (t->handler)(request, &resp_status, &resp_headers, &resp_data); |
| 238 | 241 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 321 |
| 319 net::UploadProgress MockNetworkTransaction::GetUploadProgress() const { | 322 net::UploadProgress MockNetworkTransaction::GetUploadProgress() const { |
| 320 return net::UploadProgress(); | 323 return net::UploadProgress(); |
| 321 } | 324 } |
| 322 | 325 |
| 323 bool MockNetworkTransaction::GetLoadTimingInfo( | 326 bool MockNetworkTransaction::GetLoadTimingInfo( |
| 324 net::LoadTimingInfo* load_timing_info) const { | 327 net::LoadTimingInfo* load_timing_info) const { |
| 325 return false; | 328 return false; |
| 326 } | 329 } |
| 327 | 330 |
| 331 void MockNetworkTransaction::SetPriority(net::RequestPriority priority) { |
| 332 priority_ = priority; |
| 333 } |
| 334 |
| 328 void MockNetworkTransaction::CallbackLater( | 335 void MockNetworkTransaction::CallbackLater( |
| 329 const net::CompletionCallback& callback, int result) { | 336 const net::CompletionCallback& callback, int result) { |
| 330 MessageLoop::current()->PostTask( | 337 MessageLoop::current()->PostTask( |
| 331 FROM_HERE, base::Bind(&MockNetworkTransaction::RunCallback, | 338 FROM_HERE, base::Bind(&MockNetworkTransaction::RunCallback, |
| 332 weak_factory_.GetWeakPtr(), callback, result)); | 339 weak_factory_.GetWeakPtr(), callback, result)); |
| 333 } | 340 } |
| 334 | 341 |
| 335 void MockNetworkTransaction::RunCallback( | 342 void MockNetworkTransaction::RunCallback( |
| 336 const net::CompletionCallback& callback, int result) { | 343 const net::CompletionCallback& callback, int result) { |
| 337 callback.Run(result); | 344 callback.Run(result); |
| 338 } | 345 } |
| 339 | 346 |
| 340 MockNetworkLayer::MockNetworkLayer() | 347 MockNetworkLayer::MockNetworkLayer() |
| 341 : transaction_count_(0), done_reading_called_(false) {} | 348 : transaction_count_(0), |
| 349 done_reading_called_(false), |
| 350 last_transaction_(NULL) {} |
| 342 | 351 |
| 343 MockNetworkLayer::~MockNetworkLayer() {} | 352 MockNetworkLayer::~MockNetworkLayer() {} |
| 344 | 353 |
| 345 void MockNetworkLayer::TransactionDoneReading() { | 354 void MockNetworkLayer::TransactionDoneReading() { |
| 346 done_reading_called_ = true; | 355 done_reading_called_ = true; |
| 347 } | 356 } |
| 348 | 357 |
| 349 int MockNetworkLayer::CreateTransaction( | 358 int MockNetworkLayer::CreateTransaction( |
| 350 scoped_ptr<net::HttpTransaction>* trans, | 359 scoped_ptr<net::HttpTransaction>* trans, |
| 351 net::HttpTransactionDelegate* delegate) { | 360 net::HttpTransactionDelegate* delegate) { |
| 352 transaction_count_++; | 361 transaction_count_++; |
| 353 trans->reset(new MockNetworkTransaction(this)); | 362 last_transaction_ = new MockNetworkTransaction(this); |
| 363 trans->reset(last_transaction_); |
| 354 return net::OK; | 364 return net::OK; |
| 355 } | 365 } |
| 356 | 366 |
| 357 net::HttpCache* MockNetworkLayer::GetCache() { | 367 net::HttpCache* MockNetworkLayer::GetCache() { |
| 358 return NULL; | 368 return NULL; |
| 359 } | 369 } |
| 360 | 370 |
| 361 net::HttpNetworkSession* MockNetworkLayer::GetSession() { | 371 net::HttpNetworkSession* MockNetworkLayer::GetSession() { |
| 362 return NULL; | 372 return NULL; |
| 363 } | 373 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 379 | 389 |
| 380 if (rv > 0) | 390 if (rv > 0) |
| 381 content.append(buf->data(), rv); | 391 content.append(buf->data(), rv); |
| 382 else if (rv < 0) | 392 else if (rv < 0) |
| 383 return rv; | 393 return rv; |
| 384 } while (rv > 0); | 394 } while (rv > 0); |
| 385 | 395 |
| 386 result->swap(content); | 396 result->swap(content); |
| 387 return net::OK; | 397 return net::OK; |
| 388 } | 398 } |
| OLD | NEW |