OLD | NEW |
---|---|
(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_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | |
6 #define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "remoting/test/access_token_fetcher.h" | |
10 #include "remoting/test/refresh_token_storage.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace base { | |
14 class RunLoop; | |
15 } | |
16 | |
17 namespace remoting { | |
18 namespace test { | |
19 | |
20 // This class is globally accessible to all test fixtures and cases and has its | |
21 // lifetime managed by the GTest framework. It is responsible for managing | |
22 // access tokens and caching remote host connection information. | |
Wez
2015/02/13 03:01:54
As with other class comments, start with what the
joedow
2015/02/14 02:31:27
Fixed the comment. The remote host connection inf
| |
23 // TODO(joedow) Add remote host connection functionality. | |
24 class AppRemotingTestDriverEnvironment : public testing::Environment { | |
25 public: | |
26 AppRemotingTestDriverEnvironment( | |
27 const std::string& user_name, | |
28 const std::string& service_environment); | |
29 ~AppRemotingTestDriverEnvironment() override; | |
30 | |
31 // Sets up the underlying objects and state for this class. Returns false if | |
32 // a valid access token cannot be retrieved. | |
Wez
2015/02/13 03:01:54
The first part of the comment is pretty redundant;
joedow
2015/02/14 02:31:28
Done.
| |
33 bool Initialize(const std::string& auth_code); | |
34 | |
35 // Uses the existing |refresh_token_| to request a new access token. | |
36 // This call blocks until either the token is retrieved or the call fails. | |
Wez
2015/02/13 03:01:54
You can shorten this to e.g. "Synchronously reques
joedow
2015/02/14 02:31:28
Done.
| |
37 // Returns true if a valid access token has been retrieved, otherwise false. | |
Wez
2015/02/13 03:01:54
As per style guide, if a method has a bool return
joedow
2015/02/14 02:31:28
Done.
| |
38 bool RefreshAccessToken(); | |
39 | |
40 // Used for service call authentication. | |
Wez
2015/02/13 03:01:53
If this and the following accessor are used by tes
joedow
2015/02/14 02:31:28
Done.
| |
41 const std::string& access_token() const { return access_token_; } | |
42 | |
43 // The user name to use for authentication. | |
44 const std::string& user_name() const { return user_name_; } | |
45 | |
46 // Used to set a mock version of the fetcher for testing. Calling this method | |
47 // transfers ownership of the fetcher's lifetime to this object. | |
48 void SetAccessTokenFetcherForTesting( | |
Wez
2015/02/13 03:01:53
Why is this and the function below "ForTesting"? T
joedow
2015/02/14 02:31:28
It is true that the class is used in a test tool,
Wez
2015/02/19 22:00:22
Acknowledged.
| |
49 remoting::test::AccessTokenFetcher* mock_fetcher); | |
50 | |
51 // Used to set a mock version of the refresh token storage object for testing. | |
52 // Calling this method transfers ownership to this object. | |
53 void SetRefreshTokenStorageForTesting( | |
54 remoting::test::RefreshTokenStorageInterface* mock_refresh_token_storage); | |
Wez
2015/02/13 03:01:53
I'd recommend not mixing accessor methods and ones
joedow
2015/02/14 02:31:28
Done.
| |
55 | |
56 private: | |
57 // Environment interface methods. | |
Wez
2015/02/13 03:01:54
nit: drop "methods"; that's implicit, since they a
joedow
2015/02/14 02:31:28
Done.
| |
58 void SetUp() override; | |
59 void TearDown() override; | |
60 | |
61 // Used to retrieve an access token via either an auth code or refresh token. | |
Wez
2015/02/13 03:01:53
The parameter is called |auth_token|.. so presumab
joedow
2015/02/14 02:31:27
Done.
| |
62 // Returns true if a new, valid access token has been retrieved, otherwise | |
63 // false. | |
Wez
2015/02/13 03:01:53
See above re true/false in comments.
joedow
2015/02/14 02:31:28
Done.
| |
64 bool RetrieveAccessToken(const std::string& auth_code); | |
65 | |
66 // Called back after the access token fetcher completes its network requests. | |
Wez
2015/02/13 03:01:54
nit: No need for "back" nor for "its network reque
joedow
2015/02/14 02:31:28
Done.
| |
67 // On success the tokens will be valid strings, if a failure occurs the | |
68 // access token will be empty, the refresh token may be valid | |
Wez
2015/02/13 03:01:53
See elsewhere re it being weird that refresh token
joedow
2015/02/14 02:31:28
Done.
| |
69 void OnAccessTokenRetrieved( | |
70 const std::string& access_token, | |
71 const std::string& refresh_token); | |
72 | |
73 // Used for service call authentication. | |
Wez
2015/02/13 03:01:54
What is "service call authentication"? Do you mea
joedow
2015/02/14 02:31:28
Done.
| |
74 std::string access_token_; | |
75 | |
76 // This token is used to retrieve a short lived access token. | |
Wez
2015/02/13 03:01:53
No need for "This token is" nor "short lived"; the
joedow
2015/02/14 02:31:28
Done.
| |
77 std::string refresh_token_; | |
78 | |
79 // The user name to use for authentication. | |
Wez
2015/02/13 03:01:54
nit: Drop "the"
joedow
2015/02/14 02:31:28
Done.
| |
80 std::string user_name_; | |
81 | |
82 // This string indicates which service API to target when retrieving remote | |
83 // host connection information. | |
Wez
2015/02/13 03:01:53
Drop "This string indicates which"
In general par
joedow
2015/02/14 02:31:28
I'll update this to an enum in my next CL, this wa
| |
84 std::string service_environment_; | |
85 | |
86 // Indicates that Initialize() has been called and the underlying objects are | |
87 // in a valid state. | |
88 bool initialized_; | |
Wez
2015/02/13 03:01:53
It looks like the only "underlying objects" that m
joedow
2015/02/14 02:31:28
Done.
| |
89 | |
90 // Runs a nested MessageLoop while a network request is being made and | |
91 // blocks until it completes. This member must be reset for every new network | |
Wez
2015/02/13 03:01:53
RunLoops don't run a nested MessageLoop, and they
joedow
2015/02/14 02:31:28
Done.
| |
92 // request that is made. | |
93 scoped_ptr<base::RunLoop> network_request_run_loop_; | |
Wez
2015/02/13 03:01:54
Why does this need to be a class member, rather th
joedow
2015/02/14 02:31:28
Done.
| |
94 | |
95 // Stores the access token fetcher to use for network requests. | |
Wez
2015/02/13 03:01:53
nit: Drop "stores the"
joedow
2015/02/14 02:31:28
Done.
| |
96 scoped_ptr<remoting::test::AccessTokenFetcher> access_token_fetcher_; | |
97 | |
98 // Stores a token storage object to be used to read/write the refresh token | |
Wez
2015/02/13 03:01:53
Drop everything before "Used to"
joedow
2015/02/14 02:31:28
Done.
| |
99 // from the disk. | |
100 scoped_ptr<remoting::test::RefreshTokenStorageInterface> | |
101 refresh_token_storage_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment); | |
104 }; | |
105 | |
106 // Unfortunately a global var is how this framework handles sharing data | |
Wez
2015/02/13 03:01:53
Which framework?
joedow
2015/02/14 02:31:27
Done.
| |
107 // between tests and keeping long-lived objects around. We'll use this to | |
108 // start up our environment and then share the data with the test fixtures/cases | |
109 // as needed. | |
Wez
2015/02/13 03:01:53
Suggest reducing this to "Used to share auth token
joedow
2015/02/14 02:31:28
Done.
| |
110 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData; | |
Wez
2015/02/13 03:01:53
Suggest putting this at the top of the file, since
joedow
2015/02/14 02:31:28
This line references the class declared just above
Wez
2015/02/19 22:00:22
Oh, fair point.
| |
111 | |
112 } // namespace test | |
113 } // namespace remoting | |
114 | |
115 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ | |
OLD | NEW |