tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 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_CHROMOTING_TEST_FIXTURE_H_ |
| 6 | #define REMOTING_TEST_CHROMOTING_TEST_FIXTURE_H_ |
| 7 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
avi | 5a080f01 | 2015-12-22 23:15:43 | [diff] [blame] | 10 | #include "base/macros.h" |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 11 | #include "base/threading/thread_checker.h" |
| 12 | #include "testing/gtest/include/gtest/gtest.h" |
| 13 | |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 14 | namespace remoting { |
| 15 | namespace test { |
| 16 | |
| 17 | class ConnectionTimeObserver; |
| 18 | class TestChromotingClient; |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 19 | |
| 20 | // Provides chromoting connection capabilities for tests to use. Performance |
| 21 | // metrics of the established connection are readily available to calculate |
| 22 | // through the ConnectionTimeObserver. |
| 23 | class ChromotingTestFixture |
| 24 | : public testing::Test { |
| 25 | public: |
| 26 | ChromotingTestFixture(); |
| 27 | ~ChromotingTestFixture() override; |
| 28 | |
| 29 | // Client initiates a session with a host to establish a chromoting |
| 30 | // connection. Only has |timeout| seconds to connect to host. |
| 31 | bool ConnectToHost(const base::TimeDelta& timeout); |
| 32 | |
| 33 | // Ends a chromoting connection with the host. |
| 34 | void Disconnect(); |
| 35 | |
| 36 | protected: |
| 37 | // Observes and saves the times when a chromoting client changes its state. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 38 | std::unique_ptr<ConnectionTimeObserver> connection_time_observer_; |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | // testing::Test overrides. |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 42 | void TearDown() override; |
| 43 | |
tonychun | 43fcaac | 2015-08-13 02:52:22 | [diff] [blame] | 44 | // Creates |connection_time_observer_| to attach to |test_chromoting_client_|. |
| 45 | void CreateObserver(); |
| 46 | |
| 47 | // Detaches |connection_time_observer_| and destroys it. |
| 48 | void DestroyObserver(); |
| 49 | |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 50 | // Creates and manages the connection to the remote host. |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 51 | std::unique_ptr<TestChromotingClient> test_chromoting_client_; |
tonychun | 29b7095 | 2015-08-06 04:03:12 | [diff] [blame] | 52 | |
| 53 | base::ThreadChecker thread_checker_; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(ChromotingTestFixture); |
| 56 | }; |
| 57 | |
| 58 | } // namespace test |
| 59 | } // namespace remoting |
| 60 | |
| 61 | #endif // REMOTING_TEST_CHROMOTING_TEST_FIXTURE_H_ |