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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "remoting/test/remote_host_info_fetcher.h" | 11 #include "remoting/test/remote_host_info_fetcher.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 namespace test { | 15 namespace test { |
16 | 16 |
17 class AccessTokenFetcher; | 17 class AccessTokenFetcher; |
18 class RefreshTokenStore; | 18 class RefreshTokenStore; |
19 struct RemoteHostInfo; | 19 struct RemoteHostInfo; |
20 | 20 |
21 // Globally accessible to all test fixtures and cases and has its | 21 // Globally accessible to all test fixtures and cases and has its |
22 // lifetime managed by the GTest framework. It is responsible for managing | 22 // lifetime managed by the GTest framework. It is responsible for managing |
23 // access tokens and retrieving remote host connection information. | 23 // access tokens and retrieving remote host connection information. |
24 class AppRemotingTestDriverEnvironment : public testing::Environment { | 24 class AppRemotingTestDriverEnvironment : public testing::Environment { |
25 public: | 25 public: |
26 AppRemotingTestDriverEnvironment( | 26 AppRemotingTestDriverEnvironment(const std::string& user_name, |
27 const std::string& user_name, | 27 ServiceEnvironment service_environment); |
28 ServiceEnvironment service_environment); | |
29 ~AppRemotingTestDriverEnvironment() override; | 28 ~AppRemotingTestDriverEnvironment() override; |
30 | 29 |
31 // Returns false if a valid access token cannot be retrieved. | 30 // Returns false if a valid access token cannot be retrieved. |
32 bool Initialize(const std::string& auth_code); | 31 bool Initialize(const std::string& auth_code); |
33 | 32 |
34 // Synchronously request a new access token using |refresh_token_|. | 33 // Synchronously request a new access token using |refresh_token_|. |
35 // Returns true if a valid access token has been retrieved. | 34 // Returns true if a valid access token has been retrieved. |
36 bool RefreshAccessToken(); | 35 bool RefreshAccessToken(); |
37 | 36 |
38 // Synchronously request remote host information for |application_id|. | 37 // Synchronously request remote host information for |application_id|. |
39 // Returns true if the request was successful and |remote_host_info| is valid. | 38 // Returns true if the request was successful and |remote_host_info| is valid. |
40 bool GetRemoteHostInfoForApplicationId( | 39 bool GetRemoteHostInfoForApplicationId(const std::string& application_id, |
41 const std::string& application_id, | 40 RemoteHostInfo* remote_host_info); |
42 RemoteHostInfo* remote_host_info); | 41 |
42 // Retrieves connection information for all known applications and displays | |
43 // their availability. | |
Wez
2015/03/16 22:19:10
Displays it where?
joedow
2015/03/18 20:13:09
Done.
| |
44 void ShowHostAvailability(); | |
43 | 45 |
44 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests. | 46 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests. |
45 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher); | 47 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher); |
46 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store); | 48 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store); |
47 void SetRemoteHostInfoFetcherForTest( | 49 void SetRemoteHostInfoFetcherForTest( |
48 RemoteHostInfoFetcher* remote_host_info_fetcher); | 50 RemoteHostInfoFetcher* remote_host_info_fetcher); |
49 | 51 |
50 // Accessors for fields used by tests. | 52 // Accessors for fields used by tests. |
51 const std::string& access_token() const { return access_token_; } | 53 const std::string& access_token() const { return access_token_; } |
52 const std::string& user_name() const { return user_name_; } | 54 const std::string& user_name() const { return user_name_; } |
53 | 55 |
54 private: | 56 private: |
55 // Used to retrieve an access token. If |auth_code| is empty, then the stored | 57 // Used to retrieve an access token. If |auth_code| is empty, then the stored |
56 // refresh_token will be used instead of |auth_code|. | 58 // refresh_token will be used instead of |auth_code|. |
57 // Returns true if a new, valid access token has been retrieved. | 59 // Returns true if a new, valid access token has been retrieved. |
58 bool RetrieveAccessToken(const std::string& auth_code); | 60 bool RetrieveAccessToken(const std::string& auth_code); |
59 | 61 |
60 // Called after the access token fetcher completes. | 62 // Called after the access token fetcher completes. |
61 // The tokens will be empty on failure. | 63 // The tokens will be empty on failure. |
62 void OnAccessTokenRetrieved( | 64 void OnAccessTokenRetrieved(base::Closure done_closure, |
63 base::Closure done_closure, | 65 const std::string& access_token, |
64 const std::string& access_token, | 66 const std::string& refresh_token); |
65 const std::string& refresh_token); | |
66 | 67 |
67 // Called after the remote host info fetcher completes. | 68 // Called after the remote host info fetcher completes. |
68 // |remote_host_info| is not modified on failure. | |
Wez
2015/03/16 22:19:10
RemoteHostInfo _is_ now modified on failure, then?
joedow
2015/03/18 20:13:09
It is, I was treating 'pending' as a failure howev
| |
69 void OnRemoteHostInfoRetrieved( | 69 void OnRemoteHostInfoRetrieved( |
70 base::Closure done_closure, | 70 base::Closure done_closure, |
71 RemoteHostInfo* remote_host_info, | 71 RemoteHostInfo* remote_host_info, |
72 const RemoteHostInfo& retrieved_remote_host_info); | 72 const RemoteHostInfo& retrieved_remote_host_info); |
73 | 73 |
74 // Used for authenticating with the app remoting service API. | 74 // Used for authenticating with the app remoting service API. |
75 std::string access_token_; | 75 std::string access_token_; |
76 | 76 |
77 // Used to retrieve an access token. | 77 // Used to retrieve an access token. |
78 std::string refresh_token_; | 78 std::string refresh_token_; |
(...skipping 18 matching lines...) Expand all Loading... | |
97 | 97 |
98 // Unfortunately a global var is how the GTEST framework handles sharing data | 98 // 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 | 99 // between tests and keeping long-lived objects around. Used to share auth |
100 // tokens and remote host connection information across tests. | 100 // tokens and remote host connection information across tests. |
101 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData; | 101 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData; |
102 | 102 |
103 } // namespace test | 103 } // namespace test |
104 } // namespace remoting | 104 } // namespace remoting |
105 | 105 |
106 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | 106 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ |
OLD | NEW |