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_store.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace remoting { |
| 14 namespace test { |
| 15 |
| 16 class AppRemotingTestDriverEnvironmentUnittestHelper; |
| 17 |
| 18 // Globally accessible to all test fixtures and cases and has its |
| 19 // lifetime managed by the GTest framework. It is responsible for managing |
| 20 // access tokens and caching remote host connection information. |
| 21 // TODO(joedow) Add remote host connection functionality. |
| 22 class AppRemotingTestDriverEnvironment : public testing::Environment { |
| 23 public: |
| 24 AppRemotingTestDriverEnvironment( |
| 25 const std::string& user_name, |
| 26 const std::string& service_environment); |
| 27 ~AppRemotingTestDriverEnvironment() override; |
| 28 |
| 29 // Returns false if a valid access token cannot be retrieved. |
| 30 bool Initialize(const std::string& auth_code); |
| 31 |
| 32 // Synchronously request a new access token using |refresh_token_|. |
| 33 // Returns true if a valid access token has been retrieved. |
| 34 bool RefreshAccessToken(); |
| 35 |
| 36 // Accessors for fields used by tests. |
| 37 const std::string& access_token() const { return access_token_; } |
| 38 const std::string& user_name() const { return user_name_; } |
| 39 |
| 40 private: |
| 41 friend class AppRemotingTestDriverEnvironmentUnittestHelper; |
| 42 |
| 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); |
| 47 |
| 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); |
| 54 |
| 55 // Used for authenticating with the app remoting service API. |
| 56 std::string access_token_; |
| 57 |
| 58 // Used to retrieve an access token. |
| 59 std::string refresh_token_; |
| 60 |
| 61 // Used for authentication. |
| 62 std::string user_name_; |
| 63 |
| 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_; |
| 67 |
| 68 // Access token fetcher used by TestDriverEnvironment tests. |
| 69 scoped_ptr<remoting::test::AccessTokenFetcher> test_access_token_fetcher_; |
| 70 |
| 71 // Used to read/write the refresh token from the disk. |
| 72 scoped_ptr<remoting::test::RefreshTokenStore> |
| 73 refresh_token_store_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment); |
| 76 }; |
| 77 |
| 78 // Unfortunately a global var is how the GTEST framework handles sharing data |
| 79 // between tests and keeping long-lived objects around. Used to share auth |
| 80 // tokens and remote host connection information across tests. |
| 81 extern AppRemotingTestDriverEnvironment* AppRemotingSharedData; |
| 82 |
| 83 } // namespace test |
| 84 } // namespace remoting |
| 85 |
| 86 #endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_ |
OLD | NEW |