| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_ | 5 #ifndef REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_ |
| 6 #define REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_ | 6 #define REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "remoting/test/remote_connection_observer.h" | 13 #include "remoting/test/remote_connection_observer.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class RunLoop; | 17 class RunLoop; |
| 18 class Timer; | 18 class Timer; |
| 19 class Lock; | 19 class Lock; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 namespace test { | 23 namespace test { |
| 24 | 24 |
| 25 struct RemoteApplicationDetails; | 25 struct RemoteApplicationDetails; |
| 26 class TestChromotingClient; | 26 class TestChromotingClient; |
| 27 | 27 |
| 28 // Allows for custom handling of ExtensionMessage messages. | |
| 29 typedef base::Callback<void(const protocol::ExtensionMessage& message)> | |
| 30 HostMessageReceivedCallback; | |
| 31 | |
| 32 // Creates a connection to a remote host which is available for tests to use. | 28 // Creates a connection to a remote host which is available for tests to use. |
| 33 // A TestChromotingClient is required from caller. | 29 // A TestChromotingClient is required from caller. |
| 34 class AppRemotingConnectionHelper | 30 class AppRemotingConnectionHelper |
| 35 : public RemoteConnectionObserver { | 31 : public RemoteConnectionObserver { |
| 36 public: | 32 public: |
| 37 explicit AppRemotingConnectionHelper( | 33 explicit AppRemotingConnectionHelper( |
| 38 const RemoteApplicationDetails& application_details); | 34 const RemoteApplicationDetails& application_details); |
| 39 ~AppRemotingConnectionHelper() override; | 35 ~AppRemotingConnectionHelper() override; |
| 40 | 36 |
| 41 // Initialize internal structures. | 37 // Initialize internal structures. |
| 42 void Initialize(scoped_ptr<TestChromotingClient> test_chromoting_client); | 38 void Initialize(scoped_ptr<TestChromotingClient> test_chromoting_client); |
| 43 | 39 |
| 44 // Starts a connection with the remote host. | 40 // Starts a connection with the remote host. |
| 45 // NOTE: Initialize() must be called before calling this method. | 41 // NOTE: Initialize() must be called before calling this method. |
| 46 bool StartConnection(); | 42 bool StartConnection(); |
| 47 | 43 |
| 48 // Stubs used to send messages to the remote host. Caller should not release | 44 // Stubs used to send messages to the remote host. Caller should not release |
| 49 // the objects. | 45 // the objects. |
| 50 protocol::ClipboardStub* clipboard_forwarder(); | 46 protocol::ClipboardStub* clipboard_forwarder(); |
| 51 protocol::HostStub* host_stub(); | 47 protocol::HostStub* host_stub(); |
| 52 protocol::InputStub* input_stub(); | 48 protocol::InputStub* input_stub(); |
| 53 | 49 |
| 54 // Setter for |host_message_received_callback_|. | 50 // Returns the test chromoting client. |
| 55 void SetHostMessageReceivedCallback( | 51 // NOTE: Caller should not release the object. |
| 56 HostMessageReceivedCallback host_message_received_callback); | 52 TestChromotingClient* GetTestChromotingClient() { return client_.get(); } |
| 57 | 53 |
| 54 // Returns true if connection is ready for tests. |
| 58 bool ConnectionIsReadyForTest() { return connection_is_ready_for_tests_; } | 55 bool ConnectionIsReadyForTest() { return connection_is_ready_for_tests_; } |
| 59 | 56 |
| 60 private: | 57 private: |
| 61 // RemoteConnectionObserver interface. | 58 // RemoteConnectionObserver interface. |
| 62 void ConnectionStateChanged(protocol::ConnectionToHost::State state, | 59 void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
| 63 protocol::ErrorCode error_code) override; | 60 protocol::ErrorCode error_code) override; |
| 64 void ConnectionReady(bool ready) override; | 61 void ConnectionReady(bool ready) override; |
| 65 void HostMessageReceived(const protocol::ExtensionMessage& message) override; | 62 void HostMessageReceived(const protocol::ExtensionMessage& message) override; |
| 66 | 63 |
| 67 // Sends client details to the host in order to complete the connection. | 64 // Sends client details to the host in order to complete the connection. |
| 68 void SendClientConnectionDetailsToHost(); | 65 void SendClientConnectionDetailsToHost(); |
| 69 | 66 |
| 70 // Handles onWindowAdded messages from the host. | 67 // Handles onWindowAdded messages from the host. |
| 71 void HandleOnWindowAddedMessage( | 68 void HandleOnWindowAddedMessage( |
| 72 const remoting::protocol::ExtensionMessage& message); | 69 const remoting::protocol::ExtensionMessage& message); |
| 73 | 70 |
| 74 // Contains the details for the application being tested. | 71 // Contains the details for the application being tested. |
| 75 const RemoteApplicationDetails& application_details_; | 72 const RemoteApplicationDetails& application_details_; |
| 76 | 73 |
| 77 // Called when an ExtensionMessage is received from the host. Used to | |
| 78 // override default message handling. | |
| 79 HostMessageReceivedCallback host_message_received_callback_; | |
| 80 | |
| 81 // Indicates whether the remote connection is ready to be used for testing. | 74 // Indicates whether the remote connection is ready to be used for testing. |
| 82 // True when a chromoting connection to the remote host has been established | 75 // True when a chromoting connection to the remote host has been established |
| 83 // and the main application window is visible. | 76 // and the main application window is visible. |
| 84 bool connection_is_ready_for_tests_; | 77 bool connection_is_ready_for_tests_; |
| 85 | 78 |
| 86 // Used to run the thread's message loop. | 79 // Used to run the thread's message loop. |
| 87 scoped_ptr<base::RunLoop> run_loop_; | 80 scoped_ptr<base::RunLoop> run_loop_; |
| 88 | 81 |
| 89 // Used for setting timeouts and delays. | 82 // Used for setting timeouts and delays. |
| 90 scoped_ptr<base::Timer> timer_; | 83 scoped_ptr<base::Timer> timer_; |
| 91 | 84 |
| 92 // Used to ensure RemoteConnectionObserver methods are called on the same | 85 // Used to ensure RemoteConnectionObserver methods are called on the same |
| 93 // thread. | 86 // thread. |
| 94 base::ThreadChecker thread_checker_; | 87 base::ThreadChecker thread_checker_; |
| 95 | 88 |
| 96 // Creates and manages the connection to the remote host. | 89 // Creates and manages the connection to the remote host. |
| 97 scoped_ptr<TestChromotingClient> client_; | 90 scoped_ptr<TestChromotingClient> client_; |
| 98 | 91 |
| 99 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectionHelper); | 92 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectionHelper); |
| 100 }; | 93 }; |
| 101 | 94 |
| 102 } // namespace test | 95 } // namespace test |
| 103 } // namespace remoting | 96 } // namespace remoting |
| 104 | 97 |
| 105 #endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_ | 98 #endif // REMOTING_TEST_APP_REMOTING_CONNECTION_HELPER_H_ |
| OLD | NEW |