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 "remoting/protocol/ice_transport.h" | 5 #include "remoting/protocol/ice_transport.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.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 "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "jingle/glue/thread_wrapper.h" | 13 #include "jingle/glue/thread_wrapper.h" |
14 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
15 #include "remoting/protocol/chromium_port_allocator.h" | 15 #include "remoting/protocol/chromium_port_allocator.h" |
16 #include "remoting/protocol/connection_tester.h" | 16 #include "remoting/protocol/connection_tester.h" |
17 #include "remoting/protocol/fake_authenticator.h" | 17 #include "remoting/protocol/fake_authenticator.h" |
18 #include "remoting/protocol/p2p_stream_socket.h" | 18 #include "remoting/protocol/p2p_stream_socket.h" |
19 #include "remoting/protocol/stream_channel_factory.h" | 19 #include "remoting/protocol/stream_channel_factory.h" |
20 #include "remoting/protocol/transport_context.h" | 20 #include "remoting/protocol/transport_context.h" |
21 #include "remoting/signaling/fake_signal_strategy.h" | |
22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 23 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
25 | 24 |
26 using testing::_; | 25 using testing::_; |
27 | 26 |
28 namespace remoting { | 27 namespace remoting { |
29 namespace protocol { | 28 namespace protocol { |
30 | 29 |
31 namespace { | 30 namespace { |
(...skipping 13 matching lines...) Expand all Loading... |
45 EXPECT_GE(*counter, 0); | 44 EXPECT_GE(*counter, 0); |
46 if (*counter == 0) | 45 if (*counter == 0) |
47 run_loop->Quit(); | 46 run_loop->Quit(); |
48 } | 47 } |
49 | 48 |
50 class MockChannelCreatedCallback { | 49 class MockChannelCreatedCallback { |
51 public: | 50 public: |
52 MOCK_METHOD1(OnDone, void(P2PStreamSocket* socket)); | 51 MOCK_METHOD1(OnDone, void(P2PStreamSocket* socket)); |
53 }; | 52 }; |
54 | 53 |
55 class TestTransportEventHandler : public Transport::EventHandler { | 54 class TestTransportEventHandler : public IceTransport::EventHandler { |
56 public: | 55 public: |
57 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> message)> | |
58 TransportInfoCallback; | |
59 typedef base::Callback<void(ErrorCode error)> ErrorCallback; | 56 typedef base::Callback<void(ErrorCode error)> ErrorCallback; |
60 | 57 |
61 TestTransportEventHandler() {} | 58 TestTransportEventHandler() {} |
62 ~TestTransportEventHandler() {} | 59 ~TestTransportEventHandler() {} |
63 | 60 |
64 // Both callback must be set before the test handler is passed to a Transport | |
65 // object. | |
66 void set_transport_info_callback(const TransportInfoCallback& callback) { | |
67 transport_info_callback_ = callback; | |
68 } | |
69 void set_connected_callback(const base::Closure& callback) { | |
70 connected_callback_ = callback; | |
71 } | |
72 void set_error_callback(const ErrorCallback& callback) { | 61 void set_error_callback(const ErrorCallback& callback) { |
73 error_callback_ = callback; | 62 error_callback_ = callback; |
74 } | 63 } |
75 | 64 |
76 // Transport::EventHandler interface. | 65 // IceTransport::EventHandler interface. |
77 void OnOutgoingTransportInfo(scoped_ptr<buzz::XmlElement> message) override { | 66 void OnIceTransportRouteChange(const std::string& channel_name, |
78 transport_info_callback_.Run(std::move(message)); | |
79 } | |
80 void OnTransportRouteChange(const std::string& channel_name, | |
81 const TransportRoute& route) override {} | 67 const TransportRoute& route) override {} |
82 void OnTransportConnected() override { | 68 void OnIceTransportError(ErrorCode error) override { |
83 connected_callback_.Run(); | |
84 } | |
85 void OnTransportError(ErrorCode error) override { | |
86 error_callback_.Run(error); | 69 error_callback_.Run(error); |
87 } | 70 } |
88 | 71 |
89 private: | 72 private: |
90 TransportInfoCallback transport_info_callback_; | |
91 base::Closure connected_callback_; | |
92 ErrorCallback error_callback_; | 73 ErrorCallback error_callback_; |
93 | 74 |
94 DISALLOW_COPY_AND_ASSIGN(TestTransportEventHandler); | 75 DISALLOW_COPY_AND_ASSIGN(TestTransportEventHandler); |
95 }; | 76 }; |
96 | 77 |
97 } // namespace | 78 } // namespace |
98 | 79 |
99 class IceTransportTest : public testing::Test { | 80 class IceTransportTest : public testing::Test { |
100 public: | 81 public: |
101 IceTransportTest() { | 82 IceTransportTest() { |
(...skipping 20 matching lines...) Expand all Loading... |
122 } | 103 } |
123 | 104 |
124 void DeliverTransportInfo(scoped_ptr<IceTransport>* target_transport, | 105 void DeliverTransportInfo(scoped_ptr<IceTransport>* target_transport, |
125 scoped_ptr<buzz::XmlElement> transport_info) { | 106 scoped_ptr<buzz::XmlElement> transport_info) { |
126 ASSERT_TRUE(target_transport); | 107 ASSERT_TRUE(target_transport); |
127 EXPECT_TRUE( | 108 EXPECT_TRUE( |
128 (*target_transport)->ProcessTransportInfo(transport_info.get())); | 109 (*target_transport)->ProcessTransportInfo(transport_info.get())); |
129 } | 110 } |
130 | 111 |
131 void InitializeConnection() { | 112 void InitializeConnection() { |
132 host_transport_.reset(new IceTransport(new TransportContext( | 113 host_transport_.reset( |
133 signal_strategy_.get(), | 114 new IceTransport(TransportContext::ForTests(TransportRole::SERVER), |
134 make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), | 115 &host_event_handler_)); |
135 network_settings_, TransportRole::SERVER))); | |
136 if (!host_authenticator_) { | 116 if (!host_authenticator_) { |
137 host_authenticator_.reset(new FakeAuthenticator( | 117 host_authenticator_.reset(new FakeAuthenticator( |
138 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, true)); | 118 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, true)); |
139 } | 119 } |
140 | 120 |
141 client_transport_.reset(new IceTransport(new TransportContext( | 121 client_transport_.reset( |
142 signal_strategy_.get(), | 122 new IceTransport(TransportContext::ForTests(TransportRole::CLIENT), |
143 make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), | 123 &client_event_handler_)); |
144 network_settings_, TransportRole::CLIENT))); | |
145 if (!client_authenticator_) { | 124 if (!client_authenticator_) { |
146 client_authenticator_.reset(new FakeAuthenticator( | 125 client_authenticator_.reset(new FakeAuthenticator( |
147 FakeAuthenticator::CLIENT, 0, FakeAuthenticator::ACCEPT, true)); | 126 FakeAuthenticator::CLIENT, 0, FakeAuthenticator::ACCEPT, true)); |
148 } | 127 } |
149 | 128 |
150 // Connect signaling between the two IceTransport objects. | |
151 host_event_handler_.set_transport_info_callback( | |
152 base::Bind(&IceTransportTest::ProcessTransportInfo, | |
153 base::Unretained(this), &client_transport_)); | |
154 client_event_handler_.set_transport_info_callback( | |
155 base::Bind(&IceTransportTest::ProcessTransportInfo, | |
156 base::Unretained(this), &host_transport_)); | |
157 | |
158 host_event_handler_.set_connected_callback(base::Bind(&base::DoNothing)); | |
159 host_event_handler_.set_error_callback(base::Bind( | 129 host_event_handler_.set_error_callback(base::Bind( |
160 &IceTransportTest::OnTransportError, base::Unretained(this))); | 130 &IceTransportTest::OnTransportError, base::Unretained(this))); |
161 | |
162 client_event_handler_.set_connected_callback(base::Bind(&base::DoNothing)); | |
163 client_event_handler_.set_error_callback(base::Bind( | 131 client_event_handler_.set_error_callback(base::Bind( |
164 &IceTransportTest::OnTransportError, base::Unretained(this))); | 132 &IceTransportTest::OnTransportError, base::Unretained(this))); |
165 | 133 |
166 host_transport_->Start(&host_event_handler_, host_authenticator_.get()); | 134 // Start both transports. |
167 client_transport_->Start(&client_event_handler_, | 135 host_transport_->Start( |
168 client_authenticator_.get()); | 136 host_authenticator_.get(), |
| 137 base::Bind(&IceTransportTest::ProcessTransportInfo, |
| 138 base::Unretained(this), &client_transport_)); |
| 139 client_transport_->Start( |
| 140 client_authenticator_.get(), |
| 141 base::Bind(&IceTransportTest::ProcessTransportInfo, |
| 142 base::Unretained(this), &host_transport_)); |
169 } | 143 } |
170 | 144 |
171 void WaitUntilConnected() { | 145 void WaitUntilConnected() { |
172 run_loop_.reset(new base::RunLoop()); | 146 run_loop_.reset(new base::RunLoop()); |
173 | 147 |
174 int counter = 2; | 148 int counter = 2; |
175 EXPECT_CALL(client_channel_callback_, OnDone(_)) | 149 EXPECT_CALL(client_channel_callback_, OnDone(_)) |
176 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); | 150 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); |
177 EXPECT_CALL(host_channel_callback_, OnDone(_)) | 151 EXPECT_CALL(host_channel_callback_, OnDone(_)) |
178 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); | 152 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); |
(...skipping 18 matching lines...) Expand all Loading... |
197 error_ = error; | 171 error_ = error; |
198 run_loop_->Quit(); | 172 run_loop_->Quit(); |
199 } | 173 } |
200 | 174 |
201 protected: | 175 protected: |
202 base::MessageLoopForIO message_loop_; | 176 base::MessageLoopForIO message_loop_; |
203 scoped_ptr<base::RunLoop> run_loop_; | 177 scoped_ptr<base::RunLoop> run_loop_; |
204 | 178 |
205 NetworkSettings network_settings_; | 179 NetworkSettings network_settings_; |
206 | 180 |
207 scoped_ptr<FakeSignalStrategy> signal_strategy_; | |
208 | |
209 base::TimeDelta transport_info_delay_; | 181 base::TimeDelta transport_info_delay_; |
210 | 182 |
211 scoped_ptr<IceTransport> host_transport_; | 183 scoped_ptr<IceTransport> host_transport_; |
212 TestTransportEventHandler host_event_handler_; | 184 TestTransportEventHandler host_event_handler_; |
213 scoped_ptr<FakeAuthenticator> host_authenticator_; | 185 scoped_ptr<FakeAuthenticator> host_authenticator_; |
214 | 186 |
215 scoped_ptr<IceTransport> client_transport_; | 187 scoped_ptr<IceTransport> client_transport_; |
216 TestTransportEventHandler client_event_handler_; | 188 TestTransportEventHandler client_event_handler_; |
217 scoped_ptr<FakeAuthenticator> client_authenticator_; | 189 scoped_ptr<FakeAuthenticator> client_authenticator_; |
218 | 190 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 321 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
350 kMessageSize, kMessages); | 322 kMessageSize, kMessages); |
351 tester.Start(); | 323 tester.Start(); |
352 message_loop_.Run(); | 324 message_loop_.Run(); |
353 tester.CheckResults(); | 325 tester.CheckResults(); |
354 } | 326 } |
355 | 327 |
356 | 328 |
357 } // namespace protocol | 329 } // namespace protocol |
358 } // namespace remoting | 330 } // namespace remoting |
OLD | NEW |