diff --git a/remoting/test/chromoting_test_driver_tests.cc b/remoting/test/chromoting_test_driver_tests.cc index a1f4c402152dcc..2216be64ac66dc 100644 --- a/remoting/test/chromoting_test_driver_tests.cc +++ b/remoting/test/chromoting_test_driver_tests.cc @@ -2,21 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/test/chromoting_test_driver_environment.h" #include "remoting/test/chromoting_test_fixture.h" #include "remoting/test/connection_time_observer.h" namespace { const base::TimeDelta kPinBasedMaxConnectionTimeInSeconds = - base::TimeDelta::FromSeconds(5); -const int kPinBasedMaxAuthenticationTimeMs = 4000; -const int kMaxTimeToConnectMs = 1000; + base::TimeDelta::FromSeconds(4); +const int kPinBasedMaxAuthenticationTimeMs = 2000; +const int kMaxTimeToConnectMs = 2000; } namespace remoting { namespace test { -TEST_F(ChromotingTestFixture, DISABLED_TestMeasurePinBasedAuthentication) { +TEST_F(ChromotingTestFixture, TestMeasurePinBasedAuthentication) { bool connected = ConnectToHost(kPinBasedMaxConnectionTimeInSeconds); EXPECT_TRUE(connected); @@ -35,9 +34,11 @@ TEST_F(ChromotingTestFixture, DISABLED_TestMeasurePinBasedAuthentication) { protocol::ConnectionToHost::State::AUTHENTICATED, protocol::ConnectionToHost::State::CONNECTED).InMilliseconds(); EXPECT_LE(authenticated_to_connected_time, kMaxTimeToConnectMs); + + connection_time_observer_->DisplayConnectionStats(); } -TEST_F(ChromotingTestFixture, DISABLED_TestMeasureReconnectPerformance) { +TEST_F(ChromotingTestFixture, TestMeasureReconnectPerformance) { bool connected = ConnectToHost(kPinBasedMaxConnectionTimeInSeconds); EXPECT_TRUE(connected); @@ -57,6 +58,8 @@ TEST_F(ChromotingTestFixture, DISABLED_TestMeasureReconnectPerformance) { protocol::ConnectionToHost::State::CONNECTED).InMilliseconds(); EXPECT_LE(authenticated_to_connected_time, kMaxTimeToConnectMs); + connection_time_observer_->DisplayConnectionStats(); + // Begin reconnection to same host. connected = ConnectToHost(kPinBasedMaxConnectionTimeInSeconds); EXPECT_TRUE(connected); @@ -76,13 +79,8 @@ TEST_F(ChromotingTestFixture, DISABLED_TestMeasureReconnectPerformance) { protocol::ConnectionToHost::State::AUTHENTICATED, protocol::ConnectionToHost::State::CONNECTED).InMilliseconds(); EXPECT_LE(authenticated_to_connected_time, kMaxTimeToConnectMs); -} -// TODO(TonyChun): Remove #include "chromoting_test_driver_environment.h" and -// this test once connecting to the lab's Linux host is working. -TEST(HostListTest, VerifyRequestedHostIsInHostList) { - EXPECT_TRUE(g_chromoting_shared_data); - EXPECT_TRUE(g_chromoting_shared_data->host_info().IsReadyForConnection()); + connection_time_observer_->DisplayConnectionStats(); } } // namespace test diff --git a/remoting/test/chromoting_test_fixture.cc b/remoting/test/chromoting_test_fixture.cc index 537fab20c548c7..705995f0d5532d 100644 --- a/remoting/test/chromoting_test_fixture.cc +++ b/remoting/test/chromoting_test_fixture.cc @@ -27,6 +27,26 @@ void ChromotingTestFixture::Disconnect() { test_chromoting_client_->EndConnection(); } +void ChromotingTestFixture::CreateObserver() { + if (connection_time_observer_) { + DestroyObserver(); + } + + connection_time_observer_.reset(new ConnectionTimeObserver()); + test_chromoting_client_->AddRemoteConnectionObserver( + connection_time_observer_.get()); +} + +void ChromotingTestFixture::DestroyObserver() { + if (!connection_time_observer_) { + return; + } + + test_chromoting_client_->RemoveRemoteConnectionObserver( + connection_time_observer_.get()); + connection_time_observer_.reset(); +} + bool ChromotingTestFixture::ConnectToHost( const base::TimeDelta& max_time_to_connect) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -39,6 +59,8 @@ bool ChromotingTestFixture::ConnectToHost( // Host is online and ready, initiate a remote session. base::RunLoop run_loop; + CreateObserver(); + base::Timer timer(true, false); timer.Start(FROM_HERE, max_time_to_connect, run_loop.QuitClosure()); @@ -65,18 +87,11 @@ bool ChromotingTestFixture::ConnectToHost( return true; } -void ChromotingTestFixture::SetUp() { - connection_time_observer_.reset(new ConnectionTimeObserver()); - test_chromoting_client_->AddRemoteConnectionObserver( - connection_time_observer_.get()); -} - void ChromotingTestFixture::TearDown() { // If a chromoting connection is still connected, we want to end the // connection before starting the next test. Disconnect(); - test_chromoting_client_->RemoveRemoteConnectionObserver( - connection_time_observer_.get()); + DestroyObserver(); } } // namespace test diff --git a/remoting/test/chromoting_test_fixture.h b/remoting/test/chromoting_test_fixture.h index b2d1a675a63c0e..d6804228011063 100644 --- a/remoting/test/chromoting_test_fixture.h +++ b/remoting/test/chromoting_test_fixture.h @@ -43,9 +43,14 @@ class ChromotingTestFixture private: // testing::Test overrides. - void SetUp() override; void TearDown() override; + // Creates |connection_time_observer_| to attach to |test_chromoting_client_|. + void CreateObserver(); + + // Detaches |connection_time_observer_| and destroys it. + void DestroyObserver(); + // Creates and manages the connection to the remote host. scoped_ptr test_chromoting_client_;