Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / remoting / test / chromoting_test_driver_tests.cc
blob52c58e6686b38bb7759391f2eed1c6cbe1fcceed
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"
6 #include "remoting/test/connection_time_observer.h"
8 namespace {
9 const base::TimeDelta kPinBasedMaxConnectionTimeInSeconds =
10 base::TimeDelta::FromSeconds(4);
11 const int kPinBasedMaxAuthenticationTimeMs = 2000;
12 const int kMaxTimeToConnectMs = 2000;
15 namespace remoting {
16 namespace test {
18 // Note: Make sure to restart the host before running this test. Connecting to
19 // a previously connected host will output the time to reconnect versus the time
20 // to connect.
21 TEST_F(ChromotingTestFixture, TestMeasurePinBasedAuthentication) {
22 bool connected = ConnectToHost(kPinBasedMaxConnectionTimeInSeconds);
23 EXPECT_TRUE(connected);
25 Disconnect();
26 EXPECT_FALSE(connection_time_observer_->GetStateTransitionTime(
27 protocol::ConnectionToHost::State::INITIALIZING,
28 protocol::ConnectionToHost::State::CLOSED).is_max());
30 int authentication_time = connection_time_observer_->GetStateTransitionTime(
31 protocol::ConnectionToHost::State::INITIALIZING,
32 protocol::ConnectionToHost::State::AUTHENTICATED).InMilliseconds();
33 EXPECT_LE(authentication_time, kPinBasedMaxAuthenticationTimeMs);
35 int authenticated_to_connected_time =
36 connection_time_observer_->GetStateTransitionTime(
37 protocol::ConnectionToHost::State::AUTHENTICATED,
38 protocol::ConnectionToHost::State::CONNECTED).InMilliseconds();
39 EXPECT_LE(authenticated_to_connected_time, kMaxTimeToConnectMs);
41 connection_time_observer_->DisplayConnectionStats();
44 // Note: Make sure to restart the host before running this test. If the host
45 // is not restarted after a previous connection, then the first connection will
46 // be a reconnect and the second connection will be a second reconnect.
47 TEST_F(ChromotingTestFixture, TestMeasureReconnectPerformance) {
48 bool connected = ConnectToHost(kPinBasedMaxConnectionTimeInSeconds);
49 EXPECT_TRUE(connected);
51 Disconnect();
52 EXPECT_FALSE(connection_time_observer_->GetStateTransitionTime(
53 protocol::ConnectionToHost::State::INITIALIZING,
54 protocol::ConnectionToHost::State::CLOSED).is_max());
56 int authentication_time = connection_time_observer_->GetStateTransitionTime(
57 protocol::ConnectionToHost::State::INITIALIZING,
58 protocol::ConnectionToHost::State::AUTHENTICATED).InMilliseconds();
59 EXPECT_LE(authentication_time, kPinBasedMaxAuthenticationTimeMs);
61 int authenticated_to_connected_time =
62 connection_time_observer_->GetStateTransitionTime(
63 protocol::ConnectionToHost::State::AUTHENTICATED,
64 protocol::ConnectionToHost::State::CONNECTED).InMilliseconds();
65 EXPECT_LE(authenticated_to_connected_time, kMaxTimeToConnectMs);
67 // Begin reconnection to same host.
68 connected = ConnectToHost(kPinBasedMaxConnectionTimeInSeconds);
69 EXPECT_TRUE(connected);
71 Disconnect();
72 EXPECT_FALSE(connection_time_observer_->GetStateTransitionTime(
73 protocol::ConnectionToHost::State::INITIALIZING,
74 protocol::ConnectionToHost::State::CLOSED).is_max());
76 authentication_time = connection_time_observer_->GetStateTransitionTime(
77 protocol::ConnectionToHost::State::INITIALIZING,
78 protocol::ConnectionToHost::State::AUTHENTICATED).InMilliseconds();
79 EXPECT_LE(authentication_time, kPinBasedMaxAuthenticationTimeMs);
81 authenticated_to_connected_time =
82 connection_time_observer_->GetStateTransitionTime(
83 protocol::ConnectionToHost::State::AUTHENTICATED,
84 protocol::ConnectionToHost::State::CONNECTED).InMilliseconds();
85 EXPECT_LE(authenticated_to_connected_time, kMaxTimeToConnectMs);
87 connection_time_observer_->DisplayConnectionStats();
90 } // namespace test
91 } // namespace remoting