summaryrefslogtreecommitdiffstats
path: root/remoting/test/app_remoting_connection_helper.h
diff options
context:
space:
mode:
authorliaoyuke <liaoyuke@chromium.org>2015-06-29 13:41:20 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-29 20:42:00 +0000
commit8b8cfafb1fef61acd80136c03eccc8c2059f1382 (patch)
tree7a3ee146c9f786ae6f14d7289988dffcb3337769 /remoting/test/app_remoting_connection_helper.h
parentfb48e303d8b3d6f2d34464e1b0674c92add82a38 (diff)
downloadchromium_src-8b8cfafb1fef61acd80136c03eccc8c2059f1382.zip
chromium_src-8b8cfafb1fef61acd80136c03eccc8c2059f1382.tar.gz
chromium_src-8b8cfafb1fef61acd80136c03eccc8c2059f1382.tar.bz2
Refactored AppRemotingConnectedClientFixture to decouple AppRemotingConnectionHelper.
BUG= Review URL: https://codereview.chromium.org/1213453004 Cr-Commit-Position: refs/heads/master@{#336631}
Diffstat (limited to 'remoting/test/app_remoting_connection_helper.h')
-rw-r--r--remoting/test/app_remoting_connection_helper.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/remoting/test/app_remoting_connection_helper.h b/remoting/test/app_remoting_connection_helper.h
new file mode 100644
index 0000000..d0557c9
--- /dev/null
+++ b/remoting/test/app_remoting_connection_helper.h
@@ -0,0 +1,104 @@
+// 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_CONNECTION_HELPER_H_
+#define REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "remoting/test/remote_connection_observer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+class RunLoop;
+class Timer;
+class Lock;
+}
+
+namespace remoting {
+namespace test {
+
+struct RemoteApplicationDetails;
+class TestChromotingClient;
+
+// Allows for custom handling of ExtensionMessage messages.
+typedef base::Callback<void(const protocol::ExtensionMessage& message)>
+ HostMessageReceivedCallback;
+
+// Creates a connection to a remote host which is available for tests to use.
+// All callbacks must occur on the same thread the object was created on.
+class AppRemotingConnectionHelper
+ : public RemoteConnectionObserver {
+ public:
+ AppRemotingConnectionHelper(
+ const RemoteApplicationDetails& application_details);
+ ~AppRemotingConnectionHelper() override;
+
+ // Initialize internal structures.
+ void Initialize();
+
+ // Starts a connection with the remote host.
+ bool StartConnection();
+
+ // Stubs used to send messages to the remote host.
+ protocol::ClipboardStub* clipboard_forwarder();
+ protocol::HostStub* host_stub();
+ protocol::InputStub* input_stub();
+
+ // Setter for |host_message_received_callback_|.
+ void SetHostMessageReceivedCallback(
+ HostMessageReceivedCallback host_message_received_callback);
+
+ // Reset |host_message_received_callback_ to null|.
+ void ResetHostMessageReceivedCallback();
+
+ private:
+ // RemoteConnectionObserver interface.
+ void ConnectionStateChanged(protocol::ConnectionToHost::State state,
+ protocol::ErrorCode error_code) override;
+ void ConnectionReady(bool ready) override;
+ void HostMessageReceived(const protocol::ExtensionMessage& message) override;
+
+ // Sends client details to the host in order to complete the connection.
+ void SendClientConnectionDetailsToHost();
+
+ // Handles onWindowAdded messages from the host.
+ void HandleOnWindowAddedMessage(
+ const remoting::protocol::ExtensionMessage& message);
+
+ // Contains the details for the application being tested.
+ const RemoteApplicationDetails& application_details_;
+
+ // Called when an ExtensionMessage is received from the host. Used to
+ // override default message handling.
+ HostMessageReceivedCallback host_message_received_callback_;
+
+ // Indicates whether the remote connection is ready to be used for testing.
+ // True when a chromoting connection to the remote host has been established
+ // and the main application window is visible.
+ bool connection_is_ready_for_tests_;
+
+ // Used to run the thread's message loop.
+ scoped_ptr<base::RunLoop> run_loop_;
+
+ // Used for setting timeouts and delays.
+ scoped_ptr<base::Timer> timer_;
+
+ // Used to ensure RemoteConnectionObserver methods are called on the same
+ // thread.
+ base::ThreadChecker thread_checker_;
+
+ // Creates and manages the connection to the remote host.
+ scoped_ptr<TestChromotingClient> client_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectionHelper);
+};
+
+} // namespace test
+} // namespace remoting
+
+#endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_