Update V8 to version 4.6.55.
[chromium-blink-merge.git] / remoting / test / chromoting_test_driver_environment.h
blob8981de2d0b398466c0dcbc48dec340a5c1889ce4
1 // Copyright 2015 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.
5 #ifndef REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
6 #define REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/test/host_info.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace base {
18 class MessageLoopForIO;
21 namespace remoting {
22 namespace test {
24 class AccessTokenFetcher;
25 class RefreshTokenStore;
26 class HostListFetcher;
28 // Globally accessible to all test fixtures and cases and has its
29 // lifetime managed by the GTest framework. It is responsible for managing
30 // access tokens and retrieving the host list.
31 class ChromotingTestDriverEnvironment : public testing::Environment {
32 public:
33 struct EnvironmentOptions {
34 EnvironmentOptions();
35 ~EnvironmentOptions();
37 std::string user_name;
38 std::string host_name;
39 std::string pin;
40 base::FilePath refresh_token_file_path;
43 explicit ChromotingTestDriverEnvironment(const EnvironmentOptions& options);
44 ~ChromotingTestDriverEnvironment() override;
46 // Returns false if a valid access token cannot be retrieved.
47 bool Initialize(const std::string& auth_code);
49 // Retrieves connection information for all known hosts and displays
50 // their availability to STDOUT.
51 void DisplayHostList();
53 // Used to set fake/mock objects for ChromotingTestDriverEnvironment tests.
54 // The caller retains ownership of the supplied objects, and must ensure that
55 // they remain valid until the ChromotingTestDriverEnvironment instance has
56 // been destroyed.
57 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
58 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
59 void SetHostListFetcherForTest(HostListFetcher* host_list_fetcher);
61 // Accessors for fields used by tests.
62 const std::string& access_token() const { return access_token_; }
63 const std::string& host_name() const { return host_name_; }
64 const std::string& pin() const { return pin_; }
65 const std::string& user_name() const { return user_name_; }
66 const std::vector<HostInfo>& host_list() const { return host_list_; }
67 const HostInfo& host_info() const { return host_info_; }
69 private:
70 // testing::Environment interface.
71 void TearDown() override;
73 // Used to retrieve an access token. If |auth_code| is empty, then the stored
74 // refresh_token will be used instead of |auth_code|.
75 // Returns true if a new, valid access token has been retrieved.
76 bool RetrieveAccessToken(const std::string& auth_code);
78 // Called after the access token fetcher completes.
79 // The tokens will be empty on failure.
80 void OnAccessTokenRetrieved(base::Closure done_closure,
81 const std::string& retrieved_access_token,
82 const std::string& retrieved_refresh_token);
84 // Used to retrieve a host list from the directory service.
85 // Returns true if the request was successful and |host_list_| is valid.
86 bool RetrieveHostList();
88 // Called after the host info fetcher completes.
89 void OnHostListRetrieved(base::Closure done_closure,
90 const std::vector<HostInfo>& retrieved_host_list);
92 // Used for authenticating with the directory service.
93 std::string access_token_;
95 // Used to retrieve an access token.
96 std::string refresh_token_;
98 // Used to find remote host in host list.
99 std::string host_name_;
101 // The test account for a test case.
102 std::string user_name_;
104 // Used to authenticate a connection with |host_name_|.
105 std::string pin_;
107 // Path to a JSON file containing refresh tokens.
108 base::FilePath refresh_token_file_path_;
110 // List of remote hosts for the specified user/test-account.
111 std::vector<HostInfo> host_list_;
113 // Used to generate connection setup information to connect to |host_name_|.
114 HostInfo host_info_;
116 // Access token fetcher used by TestDriverEnvironment tests.
117 remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
119 // RefreshTokenStore used by TestDriverEnvironment tests.
120 remoting::test::RefreshTokenStore* test_refresh_token_store_;
122 // HostListFetcher used by TestDriverEnvironment tests.
123 remoting::test::HostListFetcher* test_host_list_fetcher_;
125 // Used for running network request tasks.
126 scoped_ptr<base::MessageLoopForIO> message_loop_;
128 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironment);
131 // Unfortunately a global var is how the GTEST framework handles sharing data
132 // between tests and keeping long-lived objects around. Used to share access
133 // tokens and a host list across tests.
134 extern ChromotingTestDriverEnvironment* g_chromoting_shared_data;
136 } // namespace test
137 } // namespace remoting
139 #endif // REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_