http_connection_fake.h revision f2418e562d358917b02b53290d5f4b3690d6f5d3
1// Copyright 2014 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef LIBCHROMEOS_CHROMEOS_HTTP_HTTP_CONNECTION_FAKE_H_ 6#define LIBCHROMEOS_CHROMEOS_HTTP_HTTP_CONNECTION_FAKE_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include <base/macros.h> 13#include <chromeos/http/http_connection.h> 14#include <chromeos/http/http_transport_fake.h> 15 16namespace chromeos { 17namespace http { 18namespace fake { 19 20// This is a fake implementation of http::Connection for unit testing. 21class Connection : public http::Connection { 22 public: 23 Connection(const std::string& url, const std::string& method, 24 std::shared_ptr<http::Transport> transport); 25 virtual ~Connection(); 26 27 // Overrides from http::Connection. 28 // See http_connection.h for description of these methods. 29 bool SendHeaders(const HeaderList& headers, 30 chromeos::ErrorPtr* error) override; 31 bool WriteRequestData(const void* data, size_t size, 32 chromeos::ErrorPtr* error) override; 33 bool FinishRequest(chromeos::ErrorPtr* error) override; 34 35 int GetResponseStatusCode() const override; 36 std::string GetResponseStatusText() const override; 37 std::string GetProtocolVersion() const override; 38 std::string GetResponseHeader(const std::string& header_name) const override; 39 uint64_t GetResponseDataSize() const override; 40 bool ReadResponseData(void* data, size_t buffer_size, 41 size_t* size_read, chromeos::ErrorPtr* error) override; 42 43 private: 44 // Request and response objects passed to the user-provided request handler 45 // callback. The request object contains all the request information. 46 // The response object is the server response that is created by 47 // the handler in response to the request. 48 ServerRequest request_; 49 ServerResponse response_; 50 51 // Internal read data pointer needed for ReadResponseData() implementation. 52 size_t response_data_ptr_ = 0; 53 54 DISALLOW_COPY_AND_ASSIGN(Connection); 55}; 56 57} // namespace fake 58} // namespace http 59} // namespace chromeos 60 61#endif // LIBCHROMEOS_CHROMEOS_HTTP_HTTP_CONNECTION_FAKE_H_ 62