1// Copyright 2013 The Chromium 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 SYNC_TEST_ACCOUNTS_CLIENT_TEST_ACCOUNTS_CLIENT_H_
6#define SYNC_TEST_ACCOUNTS_CLIENT_TEST_ACCOUNTS_CLIENT_H_
7
8#include <string>
9#include <vector>
10
11#include "base/message_loop/message_loop.h"
12#include "url/gurl.h"
13
14using std::string;
15using std::vector;
16
17// The data associated with an account session.
18struct AccountSession {
19  AccountSession();
20  ~AccountSession();
21
22  string username;
23  string account_space;
24  string session_id;
25  string expiration_time;
26};
27
28// A test-side client for the Test Accounts service. This service provides
29// short-term, exclusive access to test accounts for the purpose of testing
30// against real Chrome Sync servers.
31class TestAccountsClient {
32 public:
33  // Creates a client associated with the given |server| URL (e.g.,
34  // http://service-runs-here.com), |account_space| (for account segregation),
35  // and |usernames| (the collection of accounts to be chosen from).
36  TestAccountsClient(const string& server,
37                     const string& account_space,
38                     const vector<string>& usernames);
39
40  virtual ~TestAccountsClient();
41
42  // Attempts to claim an account via the Test Accounts service. If
43  // successful, true is returned and the given |session| has its data set.
44  // If an error occurred, then false is returned.
45  bool ClaimAccount(AccountSession* session);
46
47  // Attempts to release an account via the Test Accounts service. The value
48  // of |session| should be one returned from ClaimAccount(). This function
49  // is best-effort and fails silently.
50  void ReleaseAccount(const AccountSession& session);
51
52  // Sends an HTTP POST request to the Test Accounts service.
53  virtual bool SendRequest(const GURL& url, string* response);
54
55 private:
56  GURL CreateGURLWithPath(const string& path);
57  base::MessageLoopForIO io_loop_;
58  const string server_;
59  const string account_space_;
60  vector<string> usernames_;
61};
62
63#endif  // SYNC_TEST_ACCOUNTS_CLIENT_TEST_ACCOUNTS_CLIENT_H_
64