Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: remoting/protocol/ice_transport_unittest.cc

Issue 1545743002: Move ownership of Transport out of Session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass_client
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/ice_transport_channel.cc ('k') | remoting/protocol/jingle_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "jingle/glue/thread_wrapper.h" 16 #include "jingle/glue/thread_wrapper.h"
17 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
18 #include "remoting/protocol/chromium_port_allocator.h" 18 #include "remoting/protocol/chromium_port_allocator.h"
19 #include "remoting/protocol/connection_tester.h" 19 #include "remoting/protocol/connection_tester.h"
20 #include "remoting/protocol/fake_authenticator.h" 20 #include "remoting/protocol/fake_authenticator.h"
21 #include "remoting/protocol/p2p_stream_socket.h" 21 #include "remoting/protocol/p2p_stream_socket.h"
22 #include "remoting/protocol/stream_channel_factory.h" 22 #include "remoting/protocol/stream_channel_factory.h"
23 #include "remoting/protocol/transport_context.h" 23 #include "remoting/protocol/transport_context.h"
24 #include "remoting/signaling/fake_signal_strategy.h"
25 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 26 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
28 27
29 using testing::_; 28 using testing::_;
30 29
31 namespace remoting { 30 namespace remoting {
32 namespace protocol { 31 namespace protocol {
33 32
34 namespace { 33 namespace {
(...skipping 13 matching lines...) Expand all
48 EXPECT_GE(*counter, 0); 47 EXPECT_GE(*counter, 0);
49 if (*counter == 0) 48 if (*counter == 0)
50 run_loop->Quit(); 49 run_loop->Quit();
51 } 50 }
52 51
53 class MockChannelCreatedCallback { 52 class MockChannelCreatedCallback {
54 public: 53 public:
55 MOCK_METHOD1(OnDone, void(P2PStreamSocket* socket)); 54 MOCK_METHOD1(OnDone, void(P2PStreamSocket* socket));
56 }; 55 };
57 56
58 class TestTransportEventHandler : public Transport::EventHandler { 57 class TestTransportEventHandler : public IceTransport::EventHandler {
59 public: 58 public:
60 typedef base::Callback<void(scoped_ptr<buzz::XmlElement> message)>
61 TransportInfoCallback;
62 typedef base::Callback<void(ErrorCode error)> ErrorCallback; 59 typedef base::Callback<void(ErrorCode error)> ErrorCallback;
63 60
64 TestTransportEventHandler() {} 61 TestTransportEventHandler() {}
65 ~TestTransportEventHandler() {} 62 ~TestTransportEventHandler() {}
66 63
67 // Both callback must be set before the test handler is passed to a Transport
68 // object.
69 void set_transport_info_callback(const TransportInfoCallback& callback) {
70 transport_info_callback_ = callback;
71 }
72 void set_connected_callback(const base::Closure& callback) {
73 connected_callback_ = callback;
74 }
75 void set_error_callback(const ErrorCallback& callback) { 64 void set_error_callback(const ErrorCallback& callback) {
76 error_callback_ = callback; 65 error_callback_ = callback;
77 } 66 }
78 67
79 // Transport::EventHandler interface. 68 // IceTransport::EventHandler interface.
80 void OnOutgoingTransportInfo(scoped_ptr<buzz::XmlElement> message) override { 69 void OnIceTransportRouteChange(const std::string& channel_name,
81 transport_info_callback_.Run(std::move(message));
82 }
83 void OnTransportRouteChange(const std::string& channel_name,
84 const TransportRoute& route) override {} 70 const TransportRoute& route) override {}
85 void OnTransportConnected() override { 71 void OnIceTransportError(ErrorCode error) override {
86 connected_callback_.Run();
87 }
88 void OnTransportError(ErrorCode error) override {
89 error_callback_.Run(error); 72 error_callback_.Run(error);
90 } 73 }
91 74
92 private: 75 private:
93 TransportInfoCallback transport_info_callback_;
94 base::Closure connected_callback_;
95 ErrorCallback error_callback_; 76 ErrorCallback error_callback_;
96 77
97 DISALLOW_COPY_AND_ASSIGN(TestTransportEventHandler); 78 DISALLOW_COPY_AND_ASSIGN(TestTransportEventHandler);
98 }; 79 };
99 80
100 } // namespace 81 } // namespace
101 82
102 class IceTransportTest : public testing::Test { 83 class IceTransportTest : public testing::Test {
103 public: 84 public:
104 IceTransportTest() { 85 IceTransportTest() {
(...skipping 20 matching lines...) Expand all
125 } 106 }
126 107
127 void DeliverTransportInfo(scoped_ptr<IceTransport>* target_transport, 108 void DeliverTransportInfo(scoped_ptr<IceTransport>* target_transport,
128 scoped_ptr<buzz::XmlElement> transport_info) { 109 scoped_ptr<buzz::XmlElement> transport_info) {
129 ASSERT_TRUE(target_transport); 110 ASSERT_TRUE(target_transport);
130 EXPECT_TRUE( 111 EXPECT_TRUE(
131 (*target_transport)->ProcessTransportInfo(transport_info.get())); 112 (*target_transport)->ProcessTransportInfo(transport_info.get()));
132 } 113 }
133 114
134 void InitializeConnection() { 115 void InitializeConnection() {
135 host_transport_.reset(new IceTransport(new TransportContext( 116 host_transport_.reset(
136 signal_strategy_.get(), 117 new IceTransport(TransportContext::ForTests(TransportRole::SERVER),
137 make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), 118 &host_event_handler_));
138 network_settings_, TransportRole::SERVER)));
139 if (!host_authenticator_) { 119 if (!host_authenticator_) {
140 host_authenticator_.reset(new FakeAuthenticator( 120 host_authenticator_.reset(new FakeAuthenticator(
141 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, true)); 121 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, true));
142 } 122 }
143 123
144 client_transport_.reset(new IceTransport(new TransportContext( 124 client_transport_.reset(
145 signal_strategy_.get(), 125 new IceTransport(TransportContext::ForTests(TransportRole::CLIENT),
146 make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), 126 &client_event_handler_));
147 network_settings_, TransportRole::CLIENT)));
148 if (!client_authenticator_) { 127 if (!client_authenticator_) {
149 client_authenticator_.reset(new FakeAuthenticator( 128 client_authenticator_.reset(new FakeAuthenticator(
150 FakeAuthenticator::CLIENT, 0, FakeAuthenticator::ACCEPT, true)); 129 FakeAuthenticator::CLIENT, 0, FakeAuthenticator::ACCEPT, true));
151 } 130 }
152 131
153 // Connect signaling between the two IceTransport objects.
154 host_event_handler_.set_transport_info_callback(
155 base::Bind(&IceTransportTest::ProcessTransportInfo,
156 base::Unretained(this), &client_transport_));
157 client_event_handler_.set_transport_info_callback(
158 base::Bind(&IceTransportTest::ProcessTransportInfo,
159 base::Unretained(this), &host_transport_));
160
161 host_event_handler_.set_connected_callback(base::Bind(&base::DoNothing));
162 host_event_handler_.set_error_callback(base::Bind( 132 host_event_handler_.set_error_callback(base::Bind(
163 &IceTransportTest::OnTransportError, base::Unretained(this))); 133 &IceTransportTest::OnTransportError, base::Unretained(this)));
164
165 client_event_handler_.set_connected_callback(base::Bind(&base::DoNothing));
166 client_event_handler_.set_error_callback(base::Bind( 134 client_event_handler_.set_error_callback(base::Bind(
167 &IceTransportTest::OnTransportError, base::Unretained(this))); 135 &IceTransportTest::OnTransportError, base::Unretained(this)));
168 136
169 host_transport_->Start(&host_event_handler_, host_authenticator_.get()); 137 // Start both transports.
170 client_transport_->Start(&client_event_handler_, 138 host_transport_->Start(
171 client_authenticator_.get()); 139 host_authenticator_.get(),
140 base::Bind(&IceTransportTest::ProcessTransportInfo,
141 base::Unretained(this), &client_transport_));
142 client_transport_->Start(
143 client_authenticator_.get(),
144 base::Bind(&IceTransportTest::ProcessTransportInfo,
145 base::Unretained(this), &host_transport_));
172 } 146 }
173 147
174 void WaitUntilConnected() { 148 void WaitUntilConnected() {
175 run_loop_.reset(new base::RunLoop()); 149 run_loop_.reset(new base::RunLoop());
176 150
177 int counter = 2; 151 int counter = 2;
178 EXPECT_CALL(client_channel_callback_, OnDone(_)) 152 EXPECT_CALL(client_channel_callback_, OnDone(_))
179 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); 153 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter));
180 EXPECT_CALL(host_channel_callback_, OnDone(_)) 154 EXPECT_CALL(host_channel_callback_, OnDone(_))
181 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter)); 155 .WillOnce(QuitRunLoopOnCounter(run_loop_.get(), &counter));
(...skipping 18 matching lines...) Expand all
200 error_ = error; 174 error_ = error;
201 run_loop_->Quit(); 175 run_loop_->Quit();
202 } 176 }
203 177
204 protected: 178 protected:
205 base::MessageLoopForIO message_loop_; 179 base::MessageLoopForIO message_loop_;
206 scoped_ptr<base::RunLoop> run_loop_; 180 scoped_ptr<base::RunLoop> run_loop_;
207 181
208 NetworkSettings network_settings_; 182 NetworkSettings network_settings_;
209 183
210 scoped_ptr<FakeSignalStrategy> signal_strategy_;
211
212 base::TimeDelta transport_info_delay_; 184 base::TimeDelta transport_info_delay_;
213 185
214 scoped_ptr<IceTransport> host_transport_; 186 scoped_ptr<IceTransport> host_transport_;
215 TestTransportEventHandler host_event_handler_; 187 TestTransportEventHandler host_event_handler_;
216 scoped_ptr<FakeAuthenticator> host_authenticator_; 188 scoped_ptr<FakeAuthenticator> host_authenticator_;
217 189
218 scoped_ptr<IceTransport> client_transport_; 190 scoped_ptr<IceTransport> client_transport_;
219 TestTransportEventHandler client_event_handler_; 191 TestTransportEventHandler client_event_handler_;
220 scoped_ptr<FakeAuthenticator> client_authenticator_; 192 scoped_ptr<FakeAuthenticator> client_authenticator_;
221 193
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), 324 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
353 kMessageSize, kMessages); 325 kMessageSize, kMessages);
354 tester.Start(); 326 tester.Start();
355 message_loop_.Run(); 327 message_loop_.Run();
356 tester.CheckResults(); 328 tester.CheckResults();
357 } 329 }
358 330
359 331
360 } // namespace protocol 332 } // namespace protocol
361 } // namespace remoting 333 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/ice_transport_channel.cc ('k') | remoting/protocol/jingle_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698