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_CONNECTED_CLIENT_FIXTURE_H_ |
| 6 #define REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/threading/thread_checker.h" |
| 13 #include "remoting/test/remote_connection_observer.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace base { |
| 17 class MessageLoopForIO; |
| 18 class RunLoop; |
| 19 class Timer; |
| 20 } |
| 21 |
| 22 namespace remoting { |
| 23 namespace test { |
| 24 |
| 25 struct RemoteApplicationDetails; |
| 26 class TestChromotingClient; |
| 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. |
| 33 // All callbacks must occur on the same thread the object was created on. |
| 34 class AppRemotingConnectedClientFixture |
| 35 : public testing::TestWithParam<const char*>, |
| 36 public RemoteConnectionObserver { |
| 37 public: |
| 38 AppRemotingConnectedClientFixture(); |
| 39 ~AppRemotingConnectedClientFixture() override; |
| 40 |
| 41 protected: |
| 42 // Sends the request to the host and waits for a reply up to |max_wait_time|. |
| 43 // Returns true if we received a response within the maximum time limit. |
| 44 bool VerifyResponseForSimpleHostMessage( |
| 45 const std::string& message_request_title, |
| 46 const std::string& message_response_title, |
| 47 const std::string& message_payload, |
| 48 const base::TimeDelta& max_wait_time); |
| 49 |
| 50 private: |
| 51 // testing::Test interface. |
| 52 void SetUp() override; |
| 53 void TearDown() override; |
| 54 |
| 55 // RemoteConnectionObserver interface. |
| 56 void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
| 57 protocol::ErrorCode error_code) override; |
| 58 void ConnectionReady(bool ready) override; |
| 59 void HostMessageReceived(const protocol::ExtensionMessage& message) override; |
| 60 |
| 61 // Starts a connection with the remote host. |
| 62 void StartConnection(); |
| 63 |
| 64 // Sends client details to the host in order to complete the connection. |
| 65 void SendClientConnectionDetailsToHost(); |
| 66 |
| 67 // Handles onWindowAdded messages from the host. |
| 68 void HandleOnWindowAddedMessage( |
| 69 const remoting::protocol::ExtensionMessage& message); |
| 70 |
| 71 // Contains the details for the application being tested. |
| 72 const RemoteApplicationDetails& application_details_; |
| 73 |
| 74 // Called when an ExtensionMessage is received from the host. Used to |
| 75 // override default message handling. |
| 76 HostMessageReceivedCallback host_message_received_callback_; |
| 77 |
| 78 // Indicates whether the remote connection is ready to be used for testing. |
| 79 // True when a chromoting connection to the remote host has been established |
| 80 // and the main application window is visible. |
| 81 bool connection_is_ready_for_tests_; |
| 82 |
| 83 // Used to post tasks by |client_| and tests. |
| 84 scoped_ptr<base::MessageLoopForIO> message_loop_; |
| 85 |
| 86 // Used to run the thread's message loop. |
| 87 scoped_ptr<base::RunLoop> run_loop_; |
| 88 |
| 89 // Used for setting timeouts and delays. |
| 90 scoped_ptr<base::Timer> timer_; |
| 91 |
| 92 // Used to ensure RemoteConnectionObserver methods are called on the same |
| 93 // thread. |
| 94 base::ThreadChecker thread_checker_; |
| 95 |
| 96 // Creates and manages the connection to the remote host. |
| 97 scoped_ptr<TestChromotingClient> client_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(AppRemotingConnectedClientFixture); |
| 100 }; |
| 101 |
| 102 } // namespace test |
| 103 } // namespace remoting |
| 104 |
| 105 #endif // REMOTING_TEST_APP_REMOTING_CONNECTED_CLIENT_FIXTURE_H_ |
OLD | NEW |