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

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

Issue 880273006: Adding the AccessTokenFetcher and Environment class to the app remoting test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating AccessTokenFetcher Unittests to use the FakeURLFetcherFactory Created 5 years, 10 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_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_store.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace remoting {
14 namespace test {
15
16 // Globally accessible to all test fixtures and cases and has its
17 // lifetime managed by the GTest framework. It is responsible for managing
18 // access tokens and caching remote host connection information.
19 // TODO(joedow) Add remote host connection functionality.
20 class AppRemotingTestDriverEnvironment : public testing::Environment {
21 public:
22 AppRemotingTestDriverEnvironment(
23 const std::string& user_name,
24 const std::string& service_environment);
25 ~AppRemotingTestDriverEnvironment() override;
26
27 // Returns false if a valid access token cannot be retrieved.
28 bool Initialize(const std::string& auth_code);
29
30 // Synchronously request a new access token using |refresh_token_|.
31 // Returns true if a valid access token has been retrieved.
32 bool RefreshAccessToken();
33
34 // Used to set a mock version of the fetcher for testing.
Wez 2015/02/19 22:00:24 nit: Clarify "for testing the driver environment i
joedow 2015/02/20 02:58:36 Done.
35 void SetAccessTokenFetcherForTest(
36 scoped_ptr<remoting::test::AccessTokenFetcher> mock_fetcher);
Wez 2015/02/19 22:00:24 nit: mock_fetcher->fetcher - it'd be valid for a c
joedow 2015/02/20 02:58:36 I've updated this code to use a friend class. Tha
Wez 2015/02/23 20:17:14 Acknowledged.
37
38 // Used to set a mock version of the refresh token store object for testing.
Wez 2015/02/19 22:00:23 nit: If you make the comment on the fetcher setter
joedow 2015/02/20 02:58:36 Done.
39 void SetRefreshTokenStoreForTest(
40 scoped_ptr<remoting::test::RefreshTokenStoreInterface> mock_token_store);
41
42 // Accessors for fields used by tests.
43 const std::string& access_token() const { return access_token_; }
44 const std::string& user_name() const { return user_name_; }
45
46 private:
47 // Environment interface.
48 void SetUp() override;
49 void TearDown() override;
50
51 // Used to retrieve an access token. If |auth_code| is empty, then the stored
52 // refresh_token will be used instead of |auth_code|.
53 // Returns true if a new, valid access token has been retrieved.
54 bool RetrieveAccessToken(const std::string& auth_code);
55
56 // Called after the access token fetcher completes.
57 // The tokens will be empty on failure.
58 void OnAccessTokenRetrieved(
59 base::Closure run_loop_quit_closure,
60 const std::string& access_token,
61 const std::string& refresh_token);
62
63 // Used for authenticating with the app remoting service API.
64 std::string access_token_;
65
66 // Used to retrieve an access token.
67 std::string refresh_token_;
68
69 // Used for authentication.
70 std::string user_name_;
71
72 // Service API to target when retrieving remote host connection information.
73 // TODO(joedow): Turn this into an enum when remote_host code is added.
74 std::string service_environment_;
75
76 // Access token fetcher to use for testing.
77 scoped_ptr<remoting::test::AccessTokenFetcher> mock_access_token_fetcher_;
78
79 // Used to read/write the refresh token from the disk.
80 scoped_ptr<remoting::test::RefreshTokenStoreInterface>
81 refresh_token_store_;
82
83 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment);
84 };
85
86 // Unfortunately a global var is how the GTEST framework handles sharing data
87 // between tests and keeping long-lived objects around. Used to share auth
88 // tokens and remote host connection information across tests.
89 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData;
90
91 } // namespace test
92 } // namespace remoting
93
94 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698