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 void ChromotingTestFixture::CreateObserver() {
31 if (connection_time_observer_
) {
35 connection_time_observer_
.reset(new ConnectionTimeObserver());
36 test_chromoting_client_
->AddRemoteConnectionObserver(
37 connection_time_observer_
.get());
40 void ChromotingTestFixture::DestroyObserver() {
41 if (!connection_time_observer_
) {
45 test_chromoting_client_
->RemoveRemoteConnectionObserver(
46 connection_time_observer_
.get());
47 connection_time_observer_
.reset();
50 bool ChromotingTestFixture::ConnectToHost(
51 const base::TimeDelta
& max_time_to_connect
) {
52 DCHECK(thread_checker_
.CalledOnValidThread());
54 if (!g_chromoting_shared_data
->host_info().IsReadyForConnection()) {
55 LOG(ERROR
) << "Can't connect to " << g_chromoting_shared_data
->host_name();
59 // Host is online and ready, initiate a remote session.
60 base::RunLoop run_loop
;
64 base::Timer
timer(true, false);
65 timer
.Start(FROM_HERE
, max_time_to_connect
, run_loop
.QuitClosure());
67 connection_time_observer_
->ConnectionStateChanged(
68 protocol::ConnectionToHost::State::INITIALIZING
,
69 protocol::ErrorCode::OK
);
70 test_chromoting_client_
->StartConnection(
71 g_chromoting_shared_data
->host_info().GenerateConnectionSetupInfo(
72 g_chromoting_shared_data
->access_token(),
73 g_chromoting_shared_data
->user_name(),
74 g_chromoting_shared_data
->pin()));
77 // Note: Under different network conditions, connection time will have
78 // greater variance. |max_time_to_connect| may need to be larger in high
79 // latency network environments.
80 if (connection_time_observer_
->GetStateTransitionTime(
81 protocol::ConnectionToHost::State::INITIALIZING
,
82 protocol::ConnectionToHost::State::CONNECTED
).is_max()) {
83 LOG(ERROR
) << "Chromoting client did not connect to requested host";
90 void ChromotingTestFixture::TearDown() {
91 // If a chromoting connection is still connected, we want to end the
92 // connection before starting the next test.
98 } // namespace remoting