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_
10 #include "base/memory/scoped_ptr.h"
11 #include "remoting/test/remote_host_info_fetcher.h"
12 #include "testing/gtest/include/gtest/gtest.h"
17 class AccessTokenFetcher
;
18 class RefreshTokenStore
;
19 struct RemoteHostInfo
;
21 // Globally accessible to all test fixtures and cases and has its
22 // lifetime managed by the GTest framework. It is responsible for managing
23 // access tokens and retrieving remote host connection information.
24 class AppRemotingTestDriverEnvironment
: public testing::Environment
{
26 AppRemotingTestDriverEnvironment(
27 const std::string
& user_name
,
28 ServiceEnvironment service_environment
);
29 ~AppRemotingTestDriverEnvironment() override
;
31 // Returns false if a valid access token cannot be retrieved.
32 bool Initialize(const std::string
& auth_code
);
34 // Synchronously request a new access token using |refresh_token_|.
35 // Returns true if a valid access token has been retrieved.
36 bool RefreshAccessToken();
38 // Synchronously request remote host information for |application_id|.
39 // Returns true if the request was successful and |remote_host_info| is valid.
40 bool GetRemoteHostInfoForApplicationId(
41 const std::string
& application_id
,
42 RemoteHostInfo
* remote_host_info
);
44 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests.
45 void SetAccessTokenFetcherForTest(AccessTokenFetcher
* access_token_fetcher
);
46 void SetRefreshTokenStoreForTest(RefreshTokenStore
* refresh_token_store
);
47 void SetRemoteHostInfoFetcherForTest(
48 RemoteHostInfoFetcher
* remote_host_info_fetcher
);
50 // Accessors for fields used by tests.
51 const std::string
& access_token() const { return access_token_
; }
52 const std::string
& user_name() const { return user_name_
; }
55 // Used to retrieve an access token. If |auth_code| is empty, then the stored
56 // refresh_token will be used instead of |auth_code|.
57 // Returns true if a new, valid access token has been retrieved.
58 bool RetrieveAccessToken(const std::string
& auth_code
);
60 // Called after the access token fetcher completes.
61 // The tokens will be empty on failure.
62 void OnAccessTokenRetrieved(
63 base::Closure done_closure
,
64 const std::string
& access_token
,
65 const std::string
& refresh_token
);
67 // Called after the remote host info fetcher completes.
68 // |remote_host_info| is not modified on failure.
69 void OnRemoteHostInfoRetrieved(
70 base::Closure done_closure
,
71 RemoteHostInfo
* remote_host_info
,
72 const RemoteHostInfo
& retrieved_remote_host_info
);
74 // Used for authenticating with the app remoting service API.
75 std::string access_token_
;
77 // Used to retrieve an access token.
78 std::string refresh_token_
;
80 // Used for authentication.
81 std::string user_name_
;
83 // Service API to target when retrieving remote host connection information.
84 ServiceEnvironment service_environment_
;
86 // Access token fetcher used by TestDriverEnvironment tests.
87 remoting::test::AccessTokenFetcher
* test_access_token_fetcher_
;
89 // RefreshTokenStore used by TestDriverEnvironment tests.
90 remoting::test::RefreshTokenStore
* test_refresh_token_store_
;
92 // RemoteHostInfoFetcher used by TestDriverEnvironment tests.
93 remoting::test::RemoteHostInfoFetcher
* test_remote_host_info_fetcher_
;
95 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment
);
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
100 // tokens and remote host connection information across tests.
101 extern AppRemotingTestDriverEnvironment
* AppRemotingSharedData
;
104 } // namespace remoting
106 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_