[CleanUp] Move PowerApiManager to power_api and Rename
[chromium-blink-merge.git] / remoting / test / app_remoting_test_driver_environment.h
blob579e209d028eedd40f9318c9a86d68cd2abfc183
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_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
6 #define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
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"
13 namespace remoting {
14 namespace test {
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;
27 // Returns false if a valid access token cannot be retrieved.
28 bool Initialize(const std::string& auth_code);
30 // Synchronously request a new access token using |refresh_token_|.
31 // Returns true if a valid access token has been retrieved.
32 bool RefreshAccessToken();
34 // Used to set fake/mock objects for AppRemotingTestDriverEnvironment tests.
35 void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
36 void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
38 // Accessors for fields used by tests.
39 const std::string& access_token() const { return access_token_; }
40 const std::string& user_name() const { return user_name_; }
42 private:
43 // Used to retrieve an access token. If |auth_code| is empty, then the stored
44 // refresh_token will be used instead of |auth_code|.
45 // Returns true if a new, valid access token has been retrieved.
46 bool RetrieveAccessToken(const std::string& auth_code);
48 // Called after the access token fetcher completes.
49 // The tokens will be empty on failure.
50 void OnAccessTokenRetrieved(
51 base::Closure done_closure,
52 const std::string& access_token,
53 const std::string& refresh_token);
55 // Used for authenticating with the app remoting service API.
56 std::string access_token_;
58 // Used to retrieve an access token.
59 std::string refresh_token_;
61 // Used for authentication.
62 std::string user_name_;
64 // Service API to target when retrieving remote host connection information.
65 // TODO(joedow): Turn this into an enum when remote_host code is added.
66 std::string service_environment_;
68 // Access token fetcher used by TestDriverEnvironment tests.
69 remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
71 // RefreshTokenStore used by TestDriverEnvironment tests.
72 remoting::test::RefreshTokenStore* test_refresh_token_store_;
74 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment);
77 // Unfortunately a global var is how the GTEST framework handles sharing data
78 // between tests and keeping long-lived objects around. Used to share auth
79 // tokens and remote host connection information across tests.
80 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData;
82 } // namespace test
83 } // namespace remoting
85 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_