blob: 26ca307cea3707b1258d92434b38d03d3a5e4ac2 [file] [log] [blame]
Alex Vakulenko9cd5e272014-04-25 17:26:11 -07001// 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 BUFFET_HTTP_CONNECTION_FAKE_H_
6#define BUFFET_HTTP_CONNECTION_FAKE_H_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include <base/basictypes.h>
13
14#include "buffet/http_connection.h"
15#include "buffet/http_transport_fake.h"
16
17namespace chromeos {
18namespace http {
19namespace fake {
20
21// This is a fake implementation of http::Connection for unit testing.
22class Connection : public chromeos::http::Connection {
23 public:
24 Connection(const std::string& url, const std::string& method,
25 std::shared_ptr<http::Transport> transport);
26 virtual ~Connection();
27
28 // Overrides from http::Connection.
29 // See http_connection.h for description of these methods.
30 virtual bool SendHeaders(const HeaderList& headers) override;
31 virtual bool WriteRequestData(const void* data, size_t size) override;
32 virtual bool FinishRequest() override;
33
34 virtual int GetResponseStatusCode() const override;
35 virtual std::string GetResponseStatusText() const override;
36 virtual std::string GetProtocolVersion() const override;
37 virtual std::string GetResponseHeader(
38 const std::string& header_name) const override;
39 virtual uint64_t GetResponseDataSize() const override;
40 virtual bool ReadResponseData(void* data, size_t buffer_size,
41 size_t* size_read) override;
42 virtual std::string GetErrorMessage() const override;
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(Connection);
46
47 // Request and response objects passed to the user-provided request handler
48 // callback. The request object contains all the request information.
49 // The response object is the server response that is created by
50 // the handler in response to the request.
51 ServerRequest request_;
52 ServerResponse response_;
53
54 // Internal read data pointer needed for ReadResponseData() implementation.
55 size_t response_data_ptr_ = 0;
56};
57
58} // namespace fake
59} // namespace http
60} // namespace chromeos
61
62#endif // BUFFET_HTTP_CONNECTION_FAKE_H_