#ifndef GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_RESPONSE_H_
#define GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_RESPONSE_H_
#include <optional>
#include <string>
#include <variant>
#include "base/time/time.h"
#include "google_apis/gaia/oauth2_response.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
#include "services/network/test/test_url_loader_factory.h"
#include "url/gurl.h"
namespace gaia {
class FakeOAuth2TokenResponse {
public:
enum ApiEndpoint {
kGetToken,
kIssueToken,
};
static FakeOAuth2TokenResponse Success(
std::string_view access_token,
base::TimeDelta expires_in = base::Hours(1));
static FakeOAuth2TokenResponse OAuth2Error(
OAuth2Response error,
std::optional<net::HttpStatusCode> http_status_code_override =
std::nullopt);
static FakeOAuth2TokenResponse NetError(net::Error net_error);
FakeOAuth2TokenResponse(const FakeOAuth2TokenResponse&);
FakeOAuth2TokenResponse& operator=(const FakeOAuth2TokenResponse&);
~FakeOAuth2TokenResponse();
void AddToTestURLLoaderFactory(
network::TestURLLoaderFactory& test_url_loader_factory,
std::optional<ApiEndpoint> exclusive_endpoint = std::nullopt) const;
std::string GetBody(ApiEndpoint endpoint) const;
net::HttpStatusCode GetHttpStatusCode(ApiEndpoint endpoint) const;
net::Error GetNetError(ApiEndpoint endpoint) const;
GURL GetUrl(ApiEndpoint endpoint) const;
private:
struct SuccessData {
std::string access_token;
base::TimeDelta expires_in;
};
struct ErrorData {
OAuth2Response error;
std::optional<net::HttpStatusCode> http_status_code_override;
};
using ResponseData = std::variant<SuccessData, ErrorData, net::Error>;
explicit FakeOAuth2TokenResponse(ResponseData data);
ResponseData data_;
};
}
#endif