OLD | NEW |
---|---|
(Empty) | |
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 #include "remoting/test/connection_time_observer.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/time/time.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace remoting { | |
13 namespace test { | |
14 | |
15 class ConnectionTimeObserverTest : public ::testing::Test { | |
16 public: | |
17 ConnectionTimeObserverTest(); | |
18 ~ConnectionTimeObserverTest() override; | |
19 | |
20 std::map<protocol::ConnectionToHost::State, base::TimeTicks> test_map_; | |
21 | |
22 protected: | |
23 // Test interface. | |
24 void SetUp() override; | |
25 | |
26 private: | |
27 DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserverTest); | |
28 }; | |
29 | |
30 ConnectionTimeObserverTest::ConnectionTimeObserverTest() { | |
31 } | |
32 | |
33 ConnectionTimeObserverTest::~ConnectionTimeObserverTest() { | |
34 } | |
35 | |
36 void ConnectionTimeObserverTest::SetUp() { | |
37 base::TimeTicks now = base::TimeTicks::Now(); | |
38 test_map_.insert(std::make_pair( | |
39 protocol::ConnectionToHost::State::INITIALIZING, | |
40 now + base::TimeDelta::FromMilliseconds(10))); | |
41 test_map_.insert(std::make_pair( | |
42 protocol::ConnectionToHost::State::CONNECTING, | |
43 now + base::TimeDelta::FromMilliseconds(20))); | |
44 test_map_.insert(std::make_pair( | |
45 protocol::ConnectionToHost::State::AUTHENTICATED, | |
46 now + base::TimeDelta::FromMilliseconds(30))); | |
47 test_map_.insert(std::make_pair( | |
48 protocol::ConnectionToHost::State::CONNECTED, | |
49 now + base::TimeDelta::FromMilliseconds(40))); | |
50 test_map_.insert(std::make_pair( | |
51 protocol::ConnectionToHost::State::CLOSED, | |
52 now + base::TimeDelta::FromMilliseconds(50))); | |
53 } | |
54 | |
55 TEST_F(ConnectionTimeObserverTest, ChromotingConnectionSuccess) { | |
56 ConnectionTimeObserver connection_time_observer; | |
57 | |
58 connection_time_observer.SetTransitionTimesMapForTest(test_map_); | |
59 | |
60 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
61 protocol::ConnectionToHost::State::INITIALIZING, | |
62 protocol::ConnectionToHost::State::CONNECTING).InMilliseconds(), 10); | |
63 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
64 protocol::ConnectionToHost::State::CONNECTING, | |
65 protocol::ConnectionToHost::State::AUTHENTICATED).InMilliseconds(), 10); | |
66 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
67 protocol::ConnectionToHost::State::AUTHENTICATED, | |
68 protocol::ConnectionToHost::State::CONNECTED).InMilliseconds(), 10); | |
69 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
70 protocol::ConnectionToHost::State::CONNECTED, | |
71 protocol::ConnectionToHost::State::CLOSED).InMilliseconds(), 10); | |
72 } | |
73 | |
74 TEST_F(ConnectionTimeObserverTest, StartStateNotFound) { | |
75 ConnectionTimeObserver connection_time_observer; | |
76 | |
77 connection_time_observer.SetTransitionTimesMapForTest(test_map_); | |
78 | |
79 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
80 protocol::ConnectionToHost::State::FAILED, | |
81 protocol::ConnectionToHost::State::CLOSED), | |
82 base::TimeDelta::Max()); | |
83 } | |
84 | |
85 TEST_F(ConnectionTimeObserverTest, EndStateNotFound) { | |
86 ConnectionTimeObserver connection_time_observer; | |
87 | |
88 connection_time_observer.SetTransitionTimesMapForTest(test_map_); | |
89 | |
90 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
91 protocol::ConnectionToHost::State::INITIALIZING, | |
92 protocol::ConnectionToHost::State::FAILED), | |
93 base::TimeDelta::Max()); | |
94 } | |
95 | |
96 TEST_F(ConnectionTimeObserverTest, NegativeTranitionDelay) { | |
joedow
2015/07/24 13:38:29
s/Tranition/Transition
tonychun
2015/07/27 16:03:38
Done.
| |
97 ConnectionTimeObserver connection_time_observer; | |
98 | |
99 connection_time_observer.SetTransitionTimesMapForTest(test_map_); | |
100 | |
101 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
102 protocol::ConnectionToHost::State::CLOSED, | |
103 protocol::ConnectionToHost::State::INITIALIZING), | |
104 base::TimeDelta::Max()); | |
105 } | |
106 | |
107 TEST_F(ConnectionTimeObserverTest, TestOnConnectionStateChanged) { | |
108 ConnectionTimeObserver connection_time_observer; | |
109 | |
110 connection_time_observer.SetTransitionTimesMapForTest(test_map_); | |
111 | |
112 // Should fail to find FAILED. | |
113 EXPECT_EQ(connection_time_observer.GetStateTransitionDelay( | |
114 protocol::ConnectionToHost::State::INITIALIZING, | |
115 protocol::ConnectionToHost::State::FAILED), | |
116 base::TimeDelta::Max()); | |
117 | |
118 // Registers the time at which FAILED state occurred into the map. | |
119 connection_time_observer.ConnectionStateChanged( | |
120 protocol::ConnectionToHost::State::FAILED, | |
121 protocol::ErrorCode::PEER_IS_OFFLINE); | |
122 | |
123 EXPECT_GT(connection_time_observer.GetStateTransitionDelay( | |
124 protocol::ConnectionToHost::State::INITIALIZING, | |
125 protocol::ConnectionToHost::State::FAILED).InMilliseconds(), 0); | |
joedow
2015/07/24 13:38:29
You probably want to use the is_zero() method on t
tonychun
2015/07/27 16:03:38
Done.
| |
126 } | |
joedow
2015/07/24 13:38:29
You should add a test that sets two states via Con
tonychun
2015/07/27 16:03:38
Done.
| |
127 | |
128 } // namespace test | |
129 } // namespace remoting | |
OLD | NEW |