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

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: 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 <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/at_exit.h"
joedow 2015/07/15 03:04:53 Not used, remove
tonychun 2015/07/15 17:24:49 Done.
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
joedow 2015/07/15 03:04:53 You can forward declare this, you don't need to in
tonychun 2015/07/15 17:24:49 I used include because of what the C++ style guide
16 #include "remoting/test/access_token_fetcher.h"
joedow 2015/07/15 03:04:53 Forward declare, you only use pointers to AccessTo
tonychun 2015/07/15 17:24:49 Done.
17 #include "remoting/test/host_info.h"
18 #include "remoting/test/host_list_fetcher.h"
joedow 2015/07/15 03:04:53 forward declare then remove
tonychun 2015/07/15 17:24:48 Done.
19 #include "remoting/test/refresh_token_store.h"
joedow 2015/07/15 03:04:53 Forward declare then remove
tonychun 2015/07/15 17:24:49 Done.
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace remoting {
23 namespace test {
24
25 // Globally accessible to all test fixtures and cases and has its
26 // lifetime managed by the GTest framework. It is responsible for managing
27 // access tokens and retrieving the host list.
28 class ChromotingTestDriverEnvironment : public testing::Environment {
29 public:
30 struct EnvironmentOptions {
31 EnvironmentOptions();
32 ~EnvironmentOptions();
33
34 std::string user_name;
35 std::string host_name;
36 base::FilePath refresh_token_file_path;
37 };
38
39 explicit ChromotingTestDriverEnvironment(const EnvironmentOptions& options);
40 ~ChromotingTestDriverEnvironment() override;
41
42 // Returns false if a valid access token cannot be retrieved.
43 bool Initialize(const std::string& auth_code);
44
45 // Retrieves connection information for all known hosts and displays
46 // their availability to STDOUT.
47 void DisplayHostList();
48
49 // Used to set fake/mock objects for ChromotingTestDriverEnvironment tests.
50 // The caller retains ownership of the supplied objects, and must ensure that
51 // they remain valid until the ChromotingTestDriverEnvironment instance has
52 // been destroyed.
53 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
54 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
55 void SetHostListFetcherForTest(HostListFetcher* host_list_fetcher);
56
57 // Accessors for fields used by tests.
58 const std::string& access_token() const { return access_token_; }
59 const std::string& host_name() const { return host_name_; }
60 const std::string& user_name() const { return user_name_; }
61 const std::vector<HostInfo>& host_list() const { return host_list_; }
62
63 private:
64 // testing::Environment interface.
65 void TearDown() override;
66
67 // Used to retrieve an access token. If |auth_code| is empty, then the stored
68 // refresh_token will be used instead of |auth_code|.
69 // Returns true if a new, valid access token has been retrieved.
70 bool RetrieveAccessToken(const std::string& auth_code);
71
72 // Called after the access token fetcher completes.
73 // The tokens will be empty on failure.
74 void OnAccessTokenRetrieved(base::Closure done_closure,
75 const std::string& retrieved_access_token,
76 const std::string& retrieved_refresh_token);
77
78 // Used to retrieve a host list from the directory service.
79 // Returns true if the request was successful and |host_list_| is valid.
80 bool RetrieveHostList();
81
82 // Called after the host info fetcher completes.
83 // |host_list_| is modified on failure.
joedow 2015/07/15 03:04:53 I think you can remove the second comment line, si
tonychun 2015/07/15 17:24:49 Done.
84 void OnHostListRetrieved(base::Closure done_closure,
85 const std::vector<HostInfo>& retrieved_host_list);
86
87 // Used for authenticating with the directory service.
88 std::string access_token_;
89
90 // Used to retrieve an access token.
91 std::string refresh_token_;
92
93 // Used to find remote host in host lost.
94 std::string host_name_;
95
96 // Used for authentication.
97 std::string user_name_;
98
99 // Path to a JSON file containing refresh tokens.
100 base::FilePath refresh_token_file_path_;
101
102 // Host info in host list used to connect to remote host.
103 std::vector<HostInfo> host_list_;
104
105 // Access token fetcher used by TestDriverEnvironment tests.
106 remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
107
108 // RefreshTokenStore used by TestDriverEnvironment tests.
109 remoting::test::RefreshTokenStore* test_refresh_token_store_;
110
111 // HostListFetcher used by TestDriverEnvironment tests.
112 remoting::test::HostListFetcher* test_host_list_fetcher_;
113
114 // Used for running network request tasks.
115 scoped_ptr<base::MessageLoopForIO> message_loop_;
116
117 DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironment);
118 };
119
120 // Unfortunately a global var is how the GTEST framework handles sharing data
121 // between tests and keeping long-lived objects around. Used to share auth
joedow 2015/07/15 03:04:53 s/auth/access
tonychun 2015/07/15 17:24:49 Done.
122 // tokens and a host list across tests.
123 extern ChromotingTestDriverEnvironment* ChromotingSharedData;
124
125 } // namespace test
126 } // namespace remoting
127
128 #endif // REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698