Give names to all utility processes.
[chromium-blink-merge.git] / remoting / test / app_remoting_test_driver_environment.h
blobeb18a8682333227e86822e1a17e9990bd014c5a6
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/memory/scoped_ptr.h"
13 #include "remoting/test/remote_application_details.h"
14 #include "remoting/test/remote_host_info_fetcher.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace remoting {
18 namespace test {
20 class AccessTokenFetcher;
21 class RefreshTokenStore;
22 struct RemoteHostInfo;
24 // Globally accessible to all test fixtures and cases and has its
25 // lifetime managed by the GTest framework. It is responsible for managing
26 // access tokens and retrieving remote host connection information.
27 class AppRemotingTestDriverEnvironment : public testing::Environment {
28 public:
29 AppRemotingTestDriverEnvironment(const std::string& user_name,
30 ServiceEnvironment service_environment);
31 ~AppRemotingTestDriverEnvironment() override;
33 // Returns false if a valid access token cannot be retrieved.
34 bool Initialize(const std::string& auth_code);
36 // Synchronously request a new access token using |refresh_token_|.
37 // Returns true if a valid access token has been retrieved.
38 bool RefreshAccessToken();
40 // Synchronously request remote host information for |application_id|.
41 // Returns true if the request was successful and |remote_host_info| is valid.
42 bool GetRemoteHostInfoForApplicationId(const std::string& application_id,
43 RemoteHostInfo* remote_host_info);
45 // Retrieves connection information for all known applications and displays
46 // their availability to STDOUT.
47 void ShowHostAvailability();
49 // Provides the RemoteApplicationDetails for the specified |application_name|.
50 const RemoteApplicationDetails& GetDetailsFromAppName(
51 const std::string& application_name);
53 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests.
54 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
55 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
56 void SetRemoteHostInfoFetcherForTest(
57 RemoteHostInfoFetcher* remote_host_info_fetcher);
59 // Accessors for fields used by tests.
60 const std::string& access_token() const { return access_token_; }
61 const std::string& user_name() const { return user_name_; }
63 private:
64 // Used to retrieve an access token. If |auth_code| is empty, then the stored
65 // refresh_token will be used instead of |auth_code|.
66 // Returns true if a new, valid access token has been retrieved.
67 bool RetrieveAccessToken(const std::string& auth_code);
69 // Called after the access token fetcher completes.
70 // The tokens will be empty on failure.
71 void OnAccessTokenRetrieved(base::Closure done_closure,
72 const std::string& access_token,
73 const std::string& refresh_token);
75 // Called after the remote host info fetcher completes.
76 // |remote_host_info| is modified on failure.
77 void OnRemoteHostInfoRetrieved(
78 base::Closure done_closure,
79 RemoteHostInfo* remote_host_info,
80 const RemoteHostInfo& retrieved_remote_host_info);
82 // Populates |application_names_| with the names of the supported remote
83 // applications.
84 void PopulateApplicationNames();
86 // Populates |application_details_map_| with the RemoteApplicationDetails for
87 // all supported remote applications.
88 void PopulateApplicationDetailsMap();
90 // Used for authenticating with the app remoting service API.
91 std::string access_token_;
93 // Used to retrieve an access token.
94 std::string refresh_token_;
96 // Used for authentication.
97 std::string user_name_;
99 // Service API to target when retrieving remote host connection information.
100 ServiceEnvironment service_environment_;
102 // Access token fetcher used by TestDriverEnvironment tests.
103 remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
105 // RefreshTokenStore used by TestDriverEnvironment tests.
106 remoting::test::RefreshTokenStore* test_refresh_token_store_;
108 // RemoteHostInfoFetcher used by TestDriverEnvironment tests.
109 remoting::test::RemoteHostInfoFetcher* test_remote_host_info_fetcher_;
111 // Contains the names of all supported remote applications.
112 std::vector<std::string> application_names_;
114 // Contains RemoteApplicationDetails for all supported remote applications.
115 std::map<std::string, RemoteApplicationDetails> application_details_map_;
117 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment);
120 // Unfortunately a global var is how the GTEST framework handles sharing data
121 // between tests and keeping long-lived objects around. Used to share auth
122 // tokens and remote host connection information across tests.
123 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData;
125 } // namespace test
126 } // namespace remoting
128 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_