1f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko// Copyright 2014 The Chromium OS Authors. All rights reserved.
2f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko// Use of this source code is governed by a BSD-style license that can be
3f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko// found in the LICENSE file.
4f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
5fed60b0c640828b320f56293c8bebc43fd2b1da8Alex Vakulenko#ifndef LIBBRILLO_BRILLO_HTTP_HTTP_CONNECTION_FAKE_H_
6fed60b0c640828b320f56293c8bebc43fd2b1da8Alex Vakulenko#define LIBBRILLO_BRILLO_HTTP_HTTP_CONNECTION_FAKE_H_
7f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
8f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko#include <map>
9f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko#include <string>
10f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko#include <vector>
11f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
12f2418e562d358917b02b53290d5f4b3690d6f5d3Alex Vakulenko#include <base/macros.h>
139ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko#include <brillo/http/http_connection.h>
149ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko#include <brillo/http/http_transport_fake.h>
15f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
169ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenkonamespace brillo {
17f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenkonamespace http {
18f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenkonamespace fake {
19f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
20f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko// This is a fake implementation of http::Connection for unit testing.
21f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenkoclass Connection : public http::Connection {
22f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko public:
2305d29044d14a60775ed6c51c75a414eb0cb50347Alex Vakulenko  Connection(const std::string& url,
2405d29044d14a60775ed6c51c75a414eb0cb50347Alex Vakulenko             const std::string& method,
25f5effe9e46e479e6fdc4f6928da545d48dcd3997Alex Vakulenko             const std::shared_ptr<http::Transport>& transport);
268757d061cd87578b5b158e8efcc8a6cf4715c7a1Alex Vakulenko  ~Connection() override;
27f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
28f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  // Overrides from http::Connection.
29f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  // See http_connection.h for description of these methods.
309ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko  bool SendHeaders(const HeaderList& headers, brillo::ErrorPtr* error) override;
319ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko  bool SetRequestData(StreamPtr stream, brillo::ErrorPtr* error) override;
322fd46ba1458275cd16b0949675bff70cc8abcdadChristopher Wiley  void SetResponseData(StreamPtr /* stream */) override {}
339ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko  bool FinishRequest(brillo::ErrorPtr* error) override;
348757d061cd87578b5b158e8efcc8a6cf4715c7a1Alex Vakulenko  RequestID FinishRequestAsync(const SuccessCallback& success_callback,
358757d061cd87578b5b158e8efcc8a6cf4715c7a1Alex Vakulenko                               const ErrorCallback& error_callback) override;
36f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
37f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  int GetResponseStatusCode() const override;
38f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  std::string GetResponseStatusText() const override;
39f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  std::string GetProtocolVersion() const override;
40f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  std::string GetResponseHeader(const std::string& header_name) const override;
419ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko  StreamPtr ExtractDataStream(brillo::ErrorPtr* error) override;
42f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
43f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko private:
44f95a2b9e277726d8793a5849ec6e81c038c22be3Alex Vakulenko  // A helper method for FinishRequestAsync() implementation.
45f95a2b9e277726d8793a5849ec6e81c038c22be3Alex Vakulenko  void FinishRequestAsyncHelper(const SuccessCallback& success_callback,
46f95a2b9e277726d8793a5849ec6e81c038c22be3Alex Vakulenko                                const ErrorCallback& error_callback);
47f95a2b9e277726d8793a5849ec6e81c038c22be3Alex Vakulenko
48f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  // Request and response objects passed to the user-provided request handler
49f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  // callback. The request object contains all the request information.
50f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  // The response object is the server response that is created by
51f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  // the handler in response to the request.
52f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  ServerRequest request_;
53f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  ServerResponse response_;
54f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
55f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko  DISALLOW_COPY_AND_ASSIGN(Connection);
56f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko};
57f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
58f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko}  // namespace fake
59f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko}  // namespace http
609ed0cab99f18acb3570a35e9408f24355f6b8324Alex Vakulenko}  // namespace brillo
61f788c95c111d0dccff735b8e02939e4e95ee2f5dAlex Vakulenko
62fed60b0c640828b320f56293c8bebc43fd2b1da8Alex Vakulenko#endif  // LIBBRILLO_BRILLO_HTTP_HTTP_CONNECTION_FAKE_H_
63