Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: remoting/test/chromoting_test_driver_environment.h

Issue 1237883002: Added chromoting test environment for the tests to share data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittest, display connection stats ability, and error check for transition delay. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
6 #define REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
7
8 #include <string>
9 #include <vector>
10
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"
15
16 namespace base {
17 class MessageLoopForIO;
18 }
19
20 namespace remoting {
21 namespace test {
22
23 class AccessTokenFetcher;
24 class RefreshTokenStore;
25 class HostListFetcher;
26 struct HostInfo;
27
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 {
32 public:
33 struct EnvironmentOptions {
34 EnvironmentOptions();
35 ~EnvironmentOptions();
36
37 std::string user_name;
38 std::string host_name;
39 base::FilePath refresh_token_file_path;
40 };
41
42 explicit ChromotingTestDriverEnvironment(const EnvironmentOptions& options);
43 ~ChromotingTestDriverEnvironment() override;
44
45 // Returns false if a valid access token cannot be retrieved.
46 bool Initialize(const std::string& auth_code);
47
48 // Retrieves connection information for all known hosts and displays
49 // their availability to STDOUT.
50 void DisplayHostList();
51
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
55 // been destroyed.
56 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
57 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
58 void SetHostListFetcherForTest(HostListFetcher* host_list_fetcher);
59
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_; }
65
66 private:
67 // testing::Environment interface.
68 void TearDown() override;
69
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);
74
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);
80
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();
84
85 // Called after the host info fetcher completes.
86 void OnHostListRetrieved(base::Closure done_closure,
87 const std::vector<HostInfo>& retrieved_host_list);
88
89 // Used for authenticating with the directory service.
90 std::string access_token_;
91
92 // Used to retrieve an access token.
93 std::string refresh_token_;
94
95 // Used to find remote host in host list.
96 std::string host_name_;
97
98 // The test account for a test case.
99 std::string user_name_;
100
101 // Path to a JSON file containing refresh tokens.
102 base::FilePath refresh_token_file_path_;
103
104 // List of remote hosts for the specified user/test-account.
105 std::vector<HostInfo> host_list_;
106
107 // Access token fetcher used by TestDriverEnvironment tests.
108 remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
109
110 // RefreshTokenStore used by TestDriverEnvironment tests.
111 remoting::test::RefreshTokenStore* test_refresh_token_store_;
112
113 // HostListFetcher used by TestDriverEnvironment tests.
114 remoting::test::HostListFetcher* test_host_list_fetcher_;
115
116 // Used for running network request tasks.
117 scoped_ptr<base::MessageLoopForIO> message_loop_;
118
119 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironment);
120 };
121
122 } // namespace test
123 } // namespace remoting
124
125 #endif // REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
OLDNEW
« no previous file with comments | « remoting/test/app_remoting_test_driver_environment_unittest.cc ('k') | remoting/test/chromoting_test_driver_environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698