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