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

Unified Diff: remoting/test/chromoting_test_driver_environment.h

Issue 1237883002: Added chromoting test environment for the tests to share data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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/chromoting_test_driver_environment.h
diff --git a/remoting/test/chromoting_test_driver_environment.h b/remoting/test/chromoting_test_driver_environment.h
new file mode 100644
index 0000000000000000000000000000000000000000..d54429c230c28dd0ea919f2a1a175ff51855d9e4
--- /dev/null
+++ b/remoting/test/chromoting_test_driver_environment.h
@@ -0,0 +1,128 @@
+// 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_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
+#define REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/at_exit.h"
joedow 2015/07/15 03:04:53 Not used, remove
tonychun 2015/07/15 17:24:49 Done.
+#include "base/files/file_path.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
joedow 2015/07/15 03:04:53 You can forward declare this, you don't need to in
tonychun 2015/07/15 17:24:49 I used include because of what the C++ style guide
+#include "remoting/test/access_token_fetcher.h"
joedow 2015/07/15 03:04:53 Forward declare, you only use pointers to AccessTo
tonychun 2015/07/15 17:24:49 Done.
+#include "remoting/test/host_info.h"
+#include "remoting/test/host_list_fetcher.h"
joedow 2015/07/15 03:04:53 forward declare then remove
tonychun 2015/07/15 17:24:48 Done.
+#include "remoting/test/refresh_token_store.h"
joedow 2015/07/15 03:04:53 Forward declare then remove
tonychun 2015/07/15 17:24:49 Done.
+#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 retrieving the host list.
+class ChromotingTestDriverEnvironment : public testing::Environment {
+ public:
+ struct EnvironmentOptions {
+ EnvironmentOptions();
+ ~EnvironmentOptions();
+
+ std::string user_name;
+ std::string host_name;
+ base::FilePath refresh_token_file_path;
+ };
+
+ explicit ChromotingTestDriverEnvironment(const EnvironmentOptions& options);
+ ~ChromotingTestDriverEnvironment() override;
+
+ // Returns false if a valid access token cannot be retrieved.
+ bool Initialize(const std::string& auth_code);
+
+ // Retrieves connection information for all known hosts and displays
+ // their availability to STDOUT.
+ void DisplayHostList();
+
+ // Used to set fake/mock objects for ChromotingTestDriverEnvironment tests.
+ // The caller retains ownership of the supplied objects, and must ensure that
+ // they remain valid until the ChromotingTestDriverEnvironment instance has
+ // been destroyed.
+ void SetAccessTokenFetcherForTest(AccessTokenFetcher* access_token_fetcher);
+ void SetRefreshTokenStoreForTest(RefreshTokenStore* refresh_token_store);
+ void SetHostListFetcherForTest(HostListFetcher* host_list_fetcher);
+
+ // Accessors for fields used by tests.
+ const std::string& access_token() const { return access_token_; }
+ const std::string& host_name() const { return host_name_; }
+ const std::string& user_name() const { return user_name_; }
+ const std::vector<HostInfo>& host_list() const { return host_list_; }
+
+ private:
+ // testing::Environment interface.
+ 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 done_closure,
+ const std::string& retrieved_access_token,
+ const std::string& retrieved_refresh_token);
+
+ // Used to retrieve a host list from the directory service.
+ // Returns true if the request was successful and |host_list_| is valid.
+ bool RetrieveHostList();
+
+ // Called after the host info fetcher completes.
+ // |host_list_| is modified on failure.
joedow 2015/07/15 03:04:53 I think you can remove the second comment line, si
tonychun 2015/07/15 17:24:49 Done.
+ void OnHostListRetrieved(base::Closure done_closure,
+ const std::vector<HostInfo>& retrieved_host_list);
+
+ // Used for authenticating with the directory service.
+ std::string access_token_;
+
+ // Used to retrieve an access token.
+ std::string refresh_token_;
+
+ // Used to find remote host in host lost.
+ std::string host_name_;
+
+ // Used for authentication.
+ std::string user_name_;
+
+ // Path to a JSON file containing refresh tokens.
+ base::FilePath refresh_token_file_path_;
+
+ // Host info in host list used to connect to remote host.
+ std::vector<HostInfo> host_list_;
+
+ // Access token fetcher used by TestDriverEnvironment tests.
+ remoting::test::AccessTokenFetcher* test_access_token_fetcher_;
+
+ // RefreshTokenStore used by TestDriverEnvironment tests.
+ remoting::test::RefreshTokenStore* test_refresh_token_store_;
+
+ // HostListFetcher used by TestDriverEnvironment tests.
+ remoting::test::HostListFetcher* test_host_list_fetcher_;
+
+ // Used for running network request tasks.
+ scoped_ptr<base::MessageLoopForIO> message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromotingTestDriverEnvironment);
+};
+
+// Unfortunately a global var is how the GTEST framework handles sharing data
+// between tests and keeping long-lived objects around. Used to share auth
joedow 2015/07/15 03:04:53 s/auth/access
tonychun 2015/07/15 17:24:49 Done.
+// tokens and a host list across tests.
+extern ChromotingTestDriverEnvironment* ChromotingSharedData;
+
+} // namespace test
+} // namespace remoting
+
+#endif // REMOTING_TEST_CHROMOTING_TEST_DRIVER_ENVIRONMENT_H_

Powered by Google App Engine
This is Rietveld 408576698