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_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
6 #define REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "testing/gtest/include/gtest/gtest.h"
17 class MessageLoopForIO
;
23 class AccessTokenFetcher
;
24 class RefreshTokenStore
;
25 class HostListFetcher
;
28 // Globally accessible to all test fixtures and cases and has its
29 // lifetime managed by the GTest framework. It is responsible for managing
30 // access tokens and retrieving the host list.
31 class ChromotingTestDriverEnvironment
: public testing::Environment
{
33 struct EnvironmentOptions
{
35 ~EnvironmentOptions();
37 std::string user_name
;
38 std::string host_name
;
39 base::FilePath refresh_token_file_path
;
42 explicit ChromotingTestDriverEnvironment(const EnvironmentOptions
& options
);
43 ~ChromotingTestDriverEnvironment() override
;
45 // Returns false if a valid access token cannot be retrieved.
46 bool Initialize(const std::string
& auth_code
);
48 // Retrieves connection information for all known hosts and displays
49 // their availability to STDOUT.
50 void DisplayHostList();
52 // Used to set fake/mock objects for ChromotingTestDriverEnvironment tests.
53 // The caller retains ownership of the supplied objects, and must ensure that
54 // they remain valid until the ChromotingTestDriverEnvironment instance has
56 void SetAccessTokenFetcherForTest(AccessTokenFetcher
* access_token_fetcher
);
57 void SetRefreshTokenStoreForTest(RefreshTokenStore
* refresh_token_store
);
58 void SetHostListFetcherForTest(HostListFetcher
* host_list_fetcher
);
60 // Accessors for fields used by tests.
61 const std::string
& access_token() const { return access_token_
; }
62 const std::string
& host_name() const { return host_name_
; }
63 const std::string
& user_name() const { return user_name_
; }
64 const std::vector
<HostInfo
>& host_list() const { return host_list_
; }
67 // testing::Environment interface.
68 void TearDown() override
;
70 // Used to retrieve an access token. If |auth_code| is empty, then the stored
71 // refresh_token will be used instead of |auth_code|.
72 // Returns true if a new, valid access token has been retrieved.
73 bool RetrieveAccessToken(const std::string
& auth_code
);
75 // Called after the access token fetcher completes.
76 // The tokens will be empty on failure.
77 void OnAccessTokenRetrieved(base::Closure done_closure
,
78 const std::string
& retrieved_access_token
,
79 const std::string
& retrieved_refresh_token
);
81 // Used to retrieve a host list from the directory service.
82 // Returns true if the request was successful and |host_list_| is valid.
83 bool RetrieveHostList();
85 // Called after the host info fetcher completes.
86 void OnHostListRetrieved(base::Closure done_closure
,
87 const std::vector
<HostInfo
>& retrieved_host_list
);
89 // Used for authenticating with the directory service.
90 std::string access_token_
;
92 // Used to retrieve an access token.
93 std::string refresh_token_
;
95 // Used to find remote host in host list.
96 std::string host_name_
;
98 // The test account for a test case.
99 std::string user_name_
;
101 // Path to a JSON file containing refresh tokens.
102 base::FilePath refresh_token_file_path_
;
104 // List of remote hosts for the specified user/test-account.
105 std::vector
<HostInfo
> host_list_
;
107 // Access token fetcher used by TestDriverEnvironment tests.
108 remoting::test::AccessTokenFetcher
* test_access_token_fetcher_
;
110 // RefreshTokenStore used by TestDriverEnvironment tests.
111 remoting::test::RefreshTokenStore
* test_refresh_token_store_
;
113 // HostListFetcher used by TestDriverEnvironment tests.
114 remoting::test::HostListFetcher
* test_host_list_fetcher_
;
116 // Used for running network request tasks.
117 scoped_ptr
<base::MessageLoopForIO
> message_loop_
;
119 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironment
);
123 } // namespace remoting
125 #endif // REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_