| 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); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 386 |
| 380 if (rv > 0) | 387 if (rv > 0) |
| 381 content.append(buf->data(), rv); | 388 content.append(buf->data(), rv); |
| 382 else if (rv < 0) | 389 else if (rv < 0) |
| 383 return rv; | 390 return rv; |
| 384 } while (rv > 0); | 391 } while (rv > 0); |
| 385 | 392 |
| 386 result->swap(content); | 393 result->swap(content); |
| 387 return net::OK; | 394 return net::OK; |
| 388 } | 395 } |
| OLD | NEW |