OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | 5 #ifndef REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ |
6 #define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | 6 #define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "remoting/test/remote_application_details.h" |
11 #include "remoting/test/remote_host_info_fetcher.h" | 14 #include "remoting/test/remote_host_info_fetcher.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
13 | 16 |
14 namespace remoting { | 17 namespace remoting { |
15 namespace test { | 18 namespace test { |
16 | 19 |
17 class AccessTokenFetcher; | 20 class AccessTokenFetcher; |
18 class RefreshTokenStore; | 21 class RefreshTokenStore; |
19 struct RemoteHostInfo; | 22 struct RemoteHostInfo; |
20 | 23 |
21 // Globally accessible to all test fixtures and cases and has its | 24 // Globally accessible to all test fixtures and cases and has its |
22 // lifetime managed by the GTest framework. It is responsible for managing | 25 // lifetime managed by the GTest framework. It is responsible for managing |
23 // access tokens and retrieving remote host connection information. | 26 // access tokens and retrieving remote host connection information. |
24 class AppRemotingTestDriverEnvironment : public testing::Environment { | 27 class AppRemotingTestDriverEnvironment : public testing::Environment { |
25 public: | 28 public: |
26 AppRemotingTestDriverEnvironment( | 29 AppRemotingTestDriverEnvironment(const std::string& user_name, |
27 const std::string& user_name, | 30 ServiceEnvironment service_environment); |
28 ServiceEnvironment service_environment); | |
29 ~AppRemotingTestDriverEnvironment() override; | 31 ~AppRemotingTestDriverEnvironment() override; |
30 | 32 |
31 // Returns false if a valid access token cannot be retrieved. | 33 // Returns false if a valid access token cannot be retrieved. |
32 bool Initialize(const std::string& auth_code); | 34 bool Initialize(const std::string& auth_code); |
33 | 35 |
34 // Synchronously request a new access token using |refresh_token_|. | 36 // Synchronously request a new access token using |refresh_token_|. |
35 // Returns true if a valid access token has been retrieved. | 37 // Returns true if a valid access token has been retrieved. |
36 bool RefreshAccessToken(); | 38 bool RefreshAccessToken(); |
37 | 39 |
38 // Synchronously request remote host information for |application_id|. | 40 // Synchronously request remote host information for |application_id|. |
39 // Returns true if the request was successful and |remote_host_info| is valid. | 41 // Returns true if the request was successful and |remote_host_info| is valid. |
40 bool GetRemoteHostInfoForApplicationId( | 42 bool GetRemoteHostInfoForApplicationId(const std::string& application_id, |
41 const std::string& application_id, | 43 RemoteHostInfo* remote_host_info); |
42 RemoteHostInfo* remote_host_info); | 44 |
| 45 // Retrieves connection information for all known applications and displays |
| 46 // their availability to STDOUT. |
| 47 void ShowHostAvailability(); |
| 48 |
| 49 // Provides the RemoteApplicationDetails for the specified |application_name|. |
| 50 const RemoteApplicationDetails& GetDetailsFromAppName( |
| 51 const std::string& application_name); |
43 | 52 |
44 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests. | 53 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests. |
45 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher); | 54 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher); |
46 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store); | 55 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store); |
47 void SetRemoteHostInfoFetcherForTest( | 56 void SetRemoteHostInfoFetcherForTest( |
48 RemoteHostInfoFetcher* remote_host_info_fetcher); | 57 RemoteHostInfoFetcher* remote_host_info_fetcher); |
49 | 58 |
50 // Accessors for fields used by tests. | 59 // Accessors for fields used by tests. |
51 const std::string& access_token() const { return access_token_; } | 60 const std::string& access_token() const { return access_token_; } |
52 const std::string& user_name() const { return user_name_; } | 61 const std::string& user_name() const { return user_name_; } |
53 | 62 |
54 private: | 63 private: |
55 // Used to retrieve an access token. If |auth_code| is empty, then the stored | 64 // Used to retrieve an access token. If |auth_code| is empty, then the stored |
56 // refresh_token will be used instead of |auth_code|. | 65 // refresh_token will be used instead of |auth_code|. |
57 // Returns true if a new, valid access token has been retrieved. | 66 // Returns true if a new, valid access token has been retrieved. |
58 bool RetrieveAccessToken(const std::string& auth_code); | 67 bool RetrieveAccessToken(const std::string& auth_code); |
59 | 68 |
60 // Called after the access token fetcher completes. | 69 // Called after the access token fetcher completes. |
61 // The tokens will be empty on failure. | 70 // The tokens will be empty on failure. |
62 void OnAccessTokenRetrieved( | 71 void OnAccessTokenRetrieved(base::Closure done_closure, |
63 base::Closure done_closure, | 72 const std::string& access_token, |
64 const std::string& access_token, | 73 const std::string& refresh_token); |
65 const std::string& refresh_token); | |
66 | 74 |
67 // Called after the remote host info fetcher completes. | 75 // Called after the remote host info fetcher completes. |
68 // |remote_host_info| is not modified on failure. | 76 // |remote_host_info| is modified on failure. |
69 void OnRemoteHostInfoRetrieved( | 77 void OnRemoteHostInfoRetrieved( |
70 base::Closure done_closure, | 78 base::Closure done_closure, |
71 RemoteHostInfo* remote_host_info, | 79 RemoteHostInfo* remote_host_info, |
72 const RemoteHostInfo& retrieved_remote_host_info); | 80 const RemoteHostInfo& retrieved_remote_host_info); |
73 | 81 |
| 82 // Populates |application_names_| with the names of the supported remote |
| 83 // applications. |
| 84 void PopulateApplicationNames(); |
| 85 |
| 86 // Populates |application_details_map_| with the RemoteApplicationDetails for |
| 87 // all supported remote applications. |
| 88 void PopulateApplicationDetailsMap(); |
| 89 |
74 // Used for authenticating with the app remoting service API. | 90 // Used for authenticating with the app remoting service API. |
75 std::string access_token_; | 91 std::string access_token_; |
76 | 92 |
77 // Used to retrieve an access token. | 93 // Used to retrieve an access token. |
78 std::string refresh_token_; | 94 std::string refresh_token_; |
79 | 95 |
80 // Used for authentication. | 96 // Used for authentication. |
81 std::string user_name_; | 97 std::string user_name_; |
82 | 98 |
83 // Service API to target when retrieving remote host connection information. | 99 // Service API to target when retrieving remote host connection information. |
84 ServiceEnvironment service_environment_; | 100 ServiceEnvironment service_environment_; |
85 | 101 |
86 // Access token fetcher used by TestDriverEnvironment tests. | 102 // Access token fetcher used by TestDriverEnvironment tests. |
87 remoting::test::AccessTokenFetcher* test_access_token_fetcher_; | 103 remoting::test::AccessTokenFetcher* test_access_token_fetcher_; |
88 | 104 |
89 // RefreshTokenStore used by TestDriverEnvironment tests. | 105 // RefreshTokenStore used by TestDriverEnvironment tests. |
90 remoting::test::RefreshTokenStore* test_refresh_token_store_; | 106 remoting::test::RefreshTokenStore* test_refresh_token_store_; |
91 | 107 |
92 // RemoteHostInfoFetcher used by TestDriverEnvironment tests. | 108 // RemoteHostInfoFetcher used by TestDriverEnvironment tests. |
93 remoting::test::RemoteHostInfoFetcher* test_remote_host_info_fetcher_; | 109 remoting::test::RemoteHostInfoFetcher* test_remote_host_info_fetcher_; |
94 | 110 |
| 111 // Contains the names of all supported remote applications. |
| 112 std::vector<std::string> application_names_; |
| 113 |
| 114 // Contains RemoteApplicationDetails for all supported remote applications. |
| 115 std::map<std::string, RemoteApplicationDetails> application_details_map_; |
| 116 |
95 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment); | 117 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment); |
96 }; | 118 }; |
97 | 119 |
98 // Unfortunately a global var is how the GTEST framework handles sharing data | 120 // Unfortunately a global var is how the GTEST framework handles sharing data |
99 // between tests and keeping long-lived objects around. Used to share auth | 121 // between tests and keeping long-lived objects around. Used to share auth |
100 // tokens and remote host connection information across tests. | 122 // tokens and remote host connection information across tests. |
101 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData; | 123 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData; |
102 | 124 |
103 } // namespace test | 125 } // namespace test |
104 } // namespace remoting | 126 } // namespace remoting |
105 | 127 |
106 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | 128 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ |
OLD | NEW |