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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/test/app_remoting_test_driver_environment.h
diff --git a/remoting/test/app_remoting_test_driver_environment.h b/remoting/test/app_remoting_test_driver_environment.h
new file mode 100644
index 0000000000000000000000000000000000000000..b48a0233e77c07b9a5fc382e58db4fb893fc2730
--- /dev/null
+++ b/remoting/test/app_remoting_test_driver_environment.h
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
+#define REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "remoting/test/access_token_fetcher.h"
+#include "remoting/test/refresh_token_store.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+namespace test {
+
+// Globally accessible to all test fixtures and cases and has its
+// lifetime managed by the GTest framework. It is responsible for managing
+// access tokens and caching remote host connection information.
+// TODO(joedow) Add remote host connection functionality.
+class AppRemotingTestDriverEnvironment : public testing::Environment {
+ public:
+ AppRemotingTestDriverEnvironment(
+ const std::string& user_name,
+ const std::string& service_environment);
+ ~AppRemotingTestDriverEnvironment() override;
+
+ // Returns false if a valid access token cannot be retrieved.
+ bool Initialize(const std::string& auth_code);
+
+ // Synchronously request a new access token using |refresh_token_|.
+ // Returns true if a valid access token has been retrieved.
+ bool RefreshAccessToken();
+
+ // 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.
+ void SetAccessTokenFetcherForTest(
+ 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.
+
+ // 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.
+ void SetRefreshTokenStoreForTest(
+ scoped_ptr<remoting::test::RefreshTokenStoreInterface> mock_token_store);
+
+ // Accessors for fields used by tests.
+ const std::string& access_token() const { return access_token_; }
+ const std::string& user_name() const { return user_name_; }
+
+ private:
+ // Environment interface.
+ void SetUp() override;
+ void TearDown() override;
+
+ // Used to retrieve an access token. If |auth_code| is empty, then the stored
+ // refresh_token will be used instead of |auth_code|.
+ // Returns true if a new, valid access token has been retrieved.
+ bool RetrieveAccessToken(const std::string& auth_code);
+
+ // Called after the access token fetcher completes.
+ // The tokens will be empty on failure.
+ void OnAccessTokenRetrieved(
+ base::Closure run_loop_quit_closure,
+ const std::string& access_token,
+ const std::string& refresh_token);
+
+ // Used for authenticating with the app remoting service API.
+ std::string access_token_;
+
+ // Used to retrieve an access token.
+ std::string refresh_token_;
+
+ // Used for authentication.
+ std::string user_name_;
+
+ // Service API to target when retrieving remote host connection information.
+ // TODO(joedow): Turn this into an enum when remote_host code is added.
+ std::string service_environment_;
+
+ // Access token fetcher to use for testing.
+ scoped_ptr<remoting::test::AccessTokenFetcher> mock_access_token_fetcher_;
+
+ // Used to read/write the refresh token from the disk.
+ scoped_ptr<remoting::test::RefreshTokenStoreInterface>
+ refresh_token_store_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppRemotingTestDriverEnvironment);
+};
+
+// Unfortunately a global var is how the GTEST framework handles sharing data
+// between tests and keeping long-lived objects around. Used to share auth
+// tokens and remote host connection information across tests.
+extern AppRemotingTestDriverEnvironment* AppRemotingSharedData;
+
+} // namespace test
+} // namespace remoting
+
+#endif // REMOTING_TEST_APP_REMOTING_TEST_DRIVER_ENVIRONMENT_H_

Powered by Google App Engine
This is Rietveld 408576698