ExtensionInstallDialogView: fix scrolling behavior on Views (Win,Linux)
[chromium-blink-merge.git] / remoting / test / app_remoting_test_driver_environment.h
blob8f3ca8f90d01068683f972cf6414399015c28f9e
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_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
6 #define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/test/remote_application_details.h"
15 #include "remoting/test/remote_host_info_fetcher.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace base {
19 class MessageLoopForIO;
22 namespace remoting {
23 namespace test {
25 class AccessTokenFetcher;
26 class AppRemotingReportIssueRequest;
27 class RefreshTokenStore;
28 struct RemoteHostInfo;
30 // Globally accessible to all test fixtures and cases and has its
31 // lifetime managed by the GTest framework. It is responsible for managing
32 // access tokens and retrieving remote host connection information.
33 class AppRemotingTestDriverEnvironment : public testing::Environment {
34 public:
35 struct EnvironmentOptions {
36 EnvironmentOptions();
37 ~EnvironmentOptions();
39 std::string user_name;
40 base::FilePath refresh_token_file_path;
41 ServiceEnvironment service_environment;
42 bool release_hosts_when_done;
45 explicit AppRemotingTestDriverEnvironment(const EnvironmentOptions& options);
46 ~AppRemotingTestDriverEnvironment() override;
48 // Returns false if a valid access token cannot be retrieved.
49 bool Initialize(const std::string& auth_code);
51 // Synchronously request a new access token using |refresh_token_|.
52 // Returns true if a valid access token has been retrieved.
53 bool RefreshAccessToken();
55 // Synchronously request remote host information for |application_id|.
56 // Returns true if the request was successful and |remote_host_info| is valid.
57 bool GetRemoteHostInfoForApplicationId(const std::string& application_id,
58 RemoteHostInfo* remote_host_info);
60 // Adds the host_id to the list of hosts that will be released after the tests
61 // have all been run.
62 void AddHostToReleaseList(const std::string& application_id,
63 const std::string& host_id);
65 // Retrieves connection information for all known applications and displays
66 // their availability to STDOUT.
67 void ShowHostAvailability();
69 // Provides the RemoteApplicationDetails for the specified |application_name|.
70 const RemoteApplicationDetails& GetDetailsFromAppName(
71 const std::string& application_name);
73 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests.
74 // The caller retains ownership of the supplied objects, and must ensure that
75 // they remain valid until the AppRemotingTestDriverEnvironment instance has
76 // been destroyed.
77 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
78 void SetAppRemotingReportIssueRequestForTest(
79 AppRemotingReportIssueRequest* app_remoting_report_issue_request);
80 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
81 void SetRemoteHostInfoFetcherForTest(
82 RemoteHostInfoFetcher* remote_host_info_fetcher);
84 // Accessors for fields used by tests.
85 const std::string& access_token() const { return access_token_; }
86 const std::string& user_name() const { return user_name_; }
88 private:
89 // testing::Environment interface.
90 void TearDown() override;
92 // Used to retrieve an access token. If |auth_code| is empty, then the stored
93 // refresh_token will be used instead of |auth_code|.
94 // Returns true if a new, valid access token has been retrieved.
95 bool RetrieveAccessToken(const std::string& auth_code);
97 // Called after the access token fetcher completes.
98 // The tokens will be empty on failure.
99 void OnAccessTokenRetrieved(base::Closure done_closure,
100 const std::string& access_token,
101 const std::string& refresh_token);
103 // Called after the remote host info fetcher completes.
104 // |remote_host_info| is modified on failure.
105 void OnRemoteHostInfoRetrieved(
106 base::Closure done_closure,
107 RemoteHostInfo* remote_host_info,
108 const RemoteHostInfo& retrieved_remote_host_info);
110 // Populates |application_names_| with the names of the supported remote
111 // applications.
112 void PopulateApplicationNames();
114 // Populates |application_details_map_| with the RemoteApplicationDetails for
115 // all supported remote applications.
116 void PopulateApplicationDetailsMap();
118 // Used for authenticating with the app remoting service API.
119 std::string access_token_;
121 // Used to retrieve an access token.
122 std::string refresh_token_;
124 // Used for authentication.
125 std::string user_name_;
127 // Service API to target when retrieving remote host connection information.
128 ServiceEnvironment service_environment_;
130 // Specifies whether to tell the service to release the remote hosts we
131 // requested after the tests have completed.
132 bool release_hosts_when_done_;
134 // Path to a JSON file containing refresh tokens.
135 base::FilePath refresh_token_file_path_;
137 // Access token fetcher used by TestDriverEnvironment tests.
138 remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
140 // AppRemotingReportIssueRequest used by TestDriverEnvironment tests.
141 remoting::test::AppRemotingReportIssueRequest*
142 test_app_remoting_report_issue_request_;
144 // RefreshTokenStore used by TestDriverEnvironment tests.
145 remoting::test::RefreshTokenStore* test_refresh_token_store_;
147 // RemoteHostInfoFetcher used by TestDriverEnvironment tests.
148 remoting::test::RemoteHostInfoFetcher* test_remote_host_info_fetcher_;
150 // Used for running network request tasks.
151 scoped_ptr<base::MessageLoopForIO> message_loop_;
153 // Contains the host ids to release when the environment is torn down.
154 // The key is the application id and the value is a list of hosts.
155 std::map<std::string, std::vector<std::string>> host_ids_to_release_;
157 // Contains the names of all supported remote applications.
158 // Once initialized, this vector is not modified.
159 std::vector<std::string> application_names_;
161 // Contains RemoteApplicationDetails for all supported remote applications.
162 // Once initialized, this map is not modified.
163 std::map<std::string, RemoteApplicationDetails> application_details_map_;
165 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment);
168 // Unfortunately a global var is how the GTEST framework handles sharing data
169 // between tests and keeping long-lived objects around. Used to share auth
170 // tokens and remote host connection information across tests.
171 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData;
173 } // namespace test
174 } // namespace remoting
176 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_