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.
5 #include "remoting/test/chromoting_test_fixture.h"
7 #include "base/logging.h"
8 #include "base/run_loop.h"
9 #include "base/timer/timer.h"
10 #include "remoting/test/chromoting_test_driver_environment.h"
11 #include "remoting/test/connection_setup_info.h"
12 #include "remoting/test/connection_time_observer.h"
13 #include "remoting/test/host_info.h"
14 #include "remoting/test/test_chromoting_client.h"
19 ChromotingTestFixture::ChromotingTestFixture()
20 : test_chromoting_client_(new TestChromotingClient()) {
23 ChromotingTestFixture::~ChromotingTestFixture() {
26 void ChromotingTestFixture::Disconnect() {
27 test_chromoting_client_
->EndConnection();
30 bool ChromotingTestFixture::ConnectToHost(
31 const base::TimeDelta
& max_time_to_connect
) {
32 DCHECK(thread_checker_
.CalledOnValidThread());
34 if (!g_chromoting_shared_data
->host_info().IsReadyForConnection()) {
35 LOG(ERROR
) << "Can't connect to " << g_chromoting_shared_data
->host_name();
39 // Host is online and ready, initiate a remote session.
40 base::RunLoop run_loop
;
42 base::Timer
timer(true, false);
43 timer
.Start(FROM_HERE
, max_time_to_connect
, run_loop
.QuitClosure());
45 connection_time_observer_
->ConnectionStateChanged(
46 protocol::ConnectionToHost::State::INITIALIZING
,
47 protocol::ErrorCode::OK
);
48 test_chromoting_client_
->StartConnection(
49 g_chromoting_shared_data
->host_info().GenerateConnectionSetupInfo(
50 g_chromoting_shared_data
->access_token(),
51 g_chromoting_shared_data
->user_name(),
52 g_chromoting_shared_data
->pin()));
55 // Note: Under different network conditions, connection time will have
56 // greater variance. |max_time_to_connect| may need to be larger in high
57 // latency network environments.
58 if (connection_time_observer_
->GetStateTransitionTime(
59 protocol::ConnectionToHost::State::INITIALIZING
,
60 protocol::ConnectionToHost::State::CONNECTED
).is_max()) {
61 LOG(ERROR
) << "Chromoting client did not connect to requested host";
68 void ChromotingTestFixture::SetUp() {
69 connection_time_observer_
.reset(new ConnectionTimeObserver());
70 test_chromoting_client_
->AddRemoteConnectionObserver(
71 connection_time_observer_
.get());
74 void ChromotingTestFixture::TearDown() {
75 // If a chromoting connection is still connected, we want to end the
76 // connection before starting the next test.
78 test_chromoting_client_
->RemoveRemoteConnectionObserver(
79 connection_time_observer_
.get());
83 } // namespace remoting