OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
12 #include "remoting/protocol/fake_session.h" | 12 #include "remoting/protocol/fake_session.h" |
13 #include "remoting/protocol/ice_connection_to_client.h" | 13 #include "remoting/protocol/ice_connection_to_client.h" |
14 #include "remoting/protocol/ice_connection_to_host.h" | 14 #include "remoting/protocol/ice_connection_to_host.h" |
15 #include "remoting/protocol/protocol_mock_objects.h" | 15 #include "remoting/protocol/protocol_mock_objects.h" |
| 16 #include "remoting/protocol/transport_context.h" |
16 #include "remoting/protocol/webrtc_connection_to_client.h" | 17 #include "remoting/protocol/webrtc_connection_to_client.h" |
17 #include "remoting/protocol/webrtc_connection_to_host.h" | 18 #include "remoting/protocol/webrtc_connection_to_host.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using ::testing::_; | 22 using ::testing::_; |
22 using ::testing::InvokeWithoutArgs; | 23 using ::testing::InvokeWithoutArgs; |
23 using ::testing::NotNull; | 24 using ::testing::NotNull; |
24 using ::testing::StrictMock; | 25 using ::testing::StrictMock; |
25 | 26 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 61 |
61 protected: | 62 protected: |
62 void SetUp() override { | 63 void SetUp() override { |
63 // Create fake sessions. | 64 // Create fake sessions. |
64 host_session_ = new FakeSession(); | 65 host_session_ = new FakeSession(); |
65 owned_client_session_.reset(new FakeSession()); | 66 owned_client_session_.reset(new FakeSession()); |
66 client_session_ = owned_client_session_.get(); | 67 client_session_ = owned_client_session_.get(); |
67 | 68 |
68 // Create Connection objects | 69 // Create Connection objects |
69 if (GetParam()) { | 70 if (GetParam()) { |
70 host_connection_.reset( | 71 host_connection_.reset(new WebrtcConnectionToClient( |
71 new WebrtcConnectionToClient(make_scoped_ptr(host_session_))); | 72 make_scoped_ptr(host_session_), |
| 73 TransportContext::ForTests(protocol::TransportRole::SERVER))); |
72 client_connection_.reset(new WebrtcConnectionToHost()); | 74 client_connection_.reset(new WebrtcConnectionToHost()); |
73 | 75 |
74 } else { | 76 } else { |
75 host_connection_.reset(new IceConnectionToClient( | 77 host_connection_.reset(new IceConnectionToClient( |
76 make_scoped_ptr(host_session_), message_loop_.task_runner())); | 78 make_scoped_ptr(host_session_), |
| 79 TransportContext::ForTests(protocol::TransportRole::SERVER), |
| 80 message_loop_.task_runner())); |
77 client_connection_.reset(new IceConnectionToHost()); | 81 client_connection_.reset(new IceConnectionToHost()); |
78 } | 82 } |
79 | 83 |
80 // Setup host side. | 84 // Setup host side. |
81 host_connection_->SetEventHandler(&host_event_handler_); | 85 host_connection_->SetEventHandler(&host_event_handler_); |
82 host_connection_->set_clipboard_stub(&host_clipboard_stub_); | 86 host_connection_->set_clipboard_stub(&host_clipboard_stub_); |
83 host_connection_->set_host_stub(&host_stub_); | 87 host_connection_->set_host_stub(&host_stub_); |
84 host_connection_->set_input_stub(&host_input_stub_); | 88 host_connection_->set_input_stub(&host_input_stub_); |
85 | 89 |
86 // Setup client side. | 90 // Setup client side. |
87 client_connection_->set_client_stub(&client_stub_); | 91 client_connection_->set_client_stub(&client_stub_); |
88 client_connection_->set_clipboard_stub(&client_clipboard_stub_); | 92 client_connection_->set_clipboard_stub(&client_clipboard_stub_); |
89 client_connection_->set_video_stub(&client_video_stub_); | 93 client_connection_->set_video_stub(&client_video_stub_); |
90 } | 94 } |
91 | 95 |
92 void Connect() { | 96 void Connect() { |
93 { | 97 { |
94 testing::InSequence sequence; | 98 testing::InSequence sequence; |
95 EXPECT_CALL(host_event_handler_, | 99 EXPECT_CALL(host_event_handler_, |
96 OnConnectionAuthenticating(host_connection_.get())); | 100 OnConnectionAuthenticating(host_connection_.get())); |
97 EXPECT_CALL(host_event_handler_, | 101 EXPECT_CALL(host_event_handler_, |
98 OnConnectionAuthenticated(host_connection_.get())); | 102 OnConnectionAuthenticated(host_connection_.get())); |
99 } | 103 } |
100 EXPECT_CALL(host_event_handler_, | 104 EXPECT_CALL(host_event_handler_, |
101 OnConnectionChannelsConnected(host_connection_.get())); | 105 OnConnectionChannelsConnected(host_connection_.get())) |
| 106 .WillOnce( |
| 107 InvokeWithoutArgs(this, &ConnectionTest::OnHostConnected)); |
| 108 EXPECT_CALL(host_event_handler_, OnRouteChange(_, _, _)) |
| 109 .Times(testing::AnyNumber()); |
102 | 110 |
103 { | 111 { |
104 testing::InSequence sequence; | 112 testing::InSequence sequence; |
105 EXPECT_CALL(client_event_handler_, | 113 EXPECT_CALL(client_event_handler_, |
106 OnConnectionState(ConnectionToHost::CONNECTING, OK)); | 114 OnConnectionState(ConnectionToHost::CONNECTING, OK)); |
107 EXPECT_CALL(client_event_handler_, | 115 EXPECT_CALL(client_event_handler_, |
108 OnConnectionState(ConnectionToHost::AUTHENTICATED, OK)); | 116 OnConnectionState(ConnectionToHost::AUTHENTICATED, OK)); |
109 EXPECT_CALL(client_event_handler_, | 117 EXPECT_CALL(client_event_handler_, |
110 OnConnectionState(ConnectionToHost::CONNECTED, OK)); | 118 OnConnectionState(ConnectionToHost::CONNECTED, OK)) |
| 119 .WillOnce(InvokeWithoutArgs( |
| 120 this, &ConnectionTest::OnClientConnected)); |
111 } | 121 } |
| 122 EXPECT_CALL(client_event_handler_, OnRouteChanged(_, _)) |
| 123 .Times(testing::AnyNumber()); |
112 | 124 |
113 client_connection_->Connect(std::move(owned_client_session_), | 125 client_connection_->Connect( |
114 &client_event_handler_); | 126 std::move(owned_client_session_), |
| 127 TransportContext::ForTests(protocol::TransportRole::CLIENT), |
| 128 &client_event_handler_); |
115 client_session_->SimulateConnection(host_session_); | 129 client_session_->SimulateConnection(host_session_); |
116 base::RunLoop().RunUntilIdle(); | 130 |
| 131 run_loop_.reset(new base::RunLoop()); |
| 132 run_loop_->Run(); |
| 133 |
| 134 EXPECT_TRUE(client_connected_); |
| 135 EXPECT_TRUE(host_connected_); |
117 } | 136 } |
118 | 137 |
119 void TearDown() override { | 138 void TearDown() override { |
120 client_connection_.reset(); | 139 client_connection_.reset(); |
121 host_connection_.reset(); | 140 host_connection_.reset(); |
122 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
123 } | 142 } |
124 | 143 |
125 base::MessageLoop message_loop_; | 144 void OnHostConnected() { |
| 145 host_connected_ = true; |
| 146 if (client_connected_ && run_loop_) |
| 147 run_loop_->Quit(); |
| 148 } |
| 149 |
| 150 void OnClientConnected() { |
| 151 client_connected_ = true; |
| 152 if (host_connected_ && run_loop_) |
| 153 run_loop_->Quit(); |
| 154 } |
| 155 |
| 156 base::MessageLoopForIO message_loop_; |
| 157 scoped_ptr<base::RunLoop> run_loop_; |
126 | 158 |
127 MockConnectionToClientEventHandler host_event_handler_; | 159 MockConnectionToClientEventHandler host_event_handler_; |
128 MockClipboardStub host_clipboard_stub_; | 160 MockClipboardStub host_clipboard_stub_; |
129 MockHostStub host_stub_; | 161 MockHostStub host_stub_; |
130 MockInputStub host_input_stub_; | 162 MockInputStub host_input_stub_; |
131 scoped_ptr<ConnectionToClient> host_connection_; | 163 scoped_ptr<ConnectionToClient> host_connection_; |
132 FakeSession* host_session_; // Owned by |host_connection_|. | 164 FakeSession* host_session_; // Owned by |host_connection_|. |
| 165 bool host_connected_ = false; |
133 | 166 |
134 MockConnectionToHostEventCallback client_event_handler_; | 167 MockConnectionToHostEventCallback client_event_handler_; |
135 MockClientStub client_stub_; | 168 MockClientStub client_stub_; |
136 MockClipboardStub client_clipboard_stub_; | 169 MockClipboardStub client_clipboard_stub_; |
137 MockVideoStub client_video_stub_; | 170 MockVideoStub client_video_stub_; |
138 scoped_ptr<ConnectionToHost> client_connection_; | 171 scoped_ptr<ConnectionToHost> client_connection_; |
139 FakeSession* client_session_; // Owned by |client_connection_|. | 172 FakeSession* client_session_; // Owned by |client_connection_|. |
140 scoped_ptr<FakeSession> owned_client_session_; | 173 scoped_ptr<FakeSession> owned_client_session_; |
| 174 bool client_connected_ = false; |
141 | 175 |
142 private: | 176 private: |
143 DISALLOW_COPY_AND_ASSIGN(ConnectionTest); | 177 DISALLOW_COPY_AND_ASSIGN(ConnectionTest); |
144 }; | 178 }; |
145 | 179 |
146 INSTANTIATE_TEST_CASE_P(Ice, ConnectionTest, ::testing::Values(false)); | 180 INSTANTIATE_TEST_CASE_P(Ice, ConnectionTest, ::testing::Values(false)); |
147 INSTANTIATE_TEST_CASE_P(Webrtc, ConnectionTest, ::testing::Values(true)); | 181 INSTANTIATE_TEST_CASE_P(Webrtc, ConnectionTest, ::testing::Values(true)); |
148 | 182 |
149 TEST_P(ConnectionTest, RejectConnection) { | 183 TEST_P(ConnectionTest, RejectConnection) { |
150 EXPECT_CALL(client_event_handler_, | 184 EXPECT_CALL(client_event_handler_, |
151 OnConnectionState(ConnectionToHost::CONNECTING, OK)); | 185 OnConnectionState(ConnectionToHost::CONNECTING, OK)); |
152 EXPECT_CALL(client_event_handler_, | 186 EXPECT_CALL(client_event_handler_, |
153 OnConnectionState(ConnectionToHost::CLOSED, OK)); | 187 OnConnectionState(ConnectionToHost::CLOSED, OK)); |
154 | 188 |
155 client_connection_->Connect(std::move(owned_client_session_), | 189 client_connection_->Connect( |
156 &client_event_handler_); | 190 std::move(owned_client_session_), |
| 191 TransportContext::ForTests(protocol::TransportRole::CLIENT), |
| 192 &client_event_handler_); |
157 client_session_->event_handler()->OnSessionStateChange(Session::CLOSED); | 193 client_session_->event_handler()->OnSessionStateChange(Session::CLOSED); |
158 } | 194 } |
159 | 195 |
160 TEST_P(ConnectionTest, Disconnect) { | 196 TEST_P(ConnectionTest, Disconnect) { |
161 Connect(); | 197 Connect(); |
162 | 198 |
163 EXPECT_CALL(client_event_handler_, | 199 EXPECT_CALL(client_event_handler_, |
164 OnConnectionState(ConnectionToHost::CLOSED, OK)); | 200 OnConnectionState(ConnectionToHost::CLOSED, OK)); |
165 EXPECT_CALL(host_event_handler_, | 201 EXPECT_CALL(host_event_handler_, |
166 OnConnectionClosed(host_connection_.get(), OK)); | 202 OnConnectionClosed(host_connection_.get(), OK)); |
(...skipping 29 matching lines...) Expand all Loading... |
196 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event))); | 232 EXPECT_CALL(host_input_stub_, InjectKeyEvent(EqualsKeyEvent(event))); |
197 | 233 |
198 // Send capabilities from the client. | 234 // Send capabilities from the client. |
199 client_connection_->input_stub()->InjectKeyEvent(event); | 235 client_connection_->input_stub()->InjectKeyEvent(event); |
200 | 236 |
201 base::RunLoop().RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
202 } | 238 } |
203 | 239 |
204 } // namespace protocol | 240 } // namespace protocol |
205 } // namespace remoting | 241 } // namespace remoting |
OLD | NEW |