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

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

Issue 2104363004: Remove remaining calls to deprecated MessageLoop methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab Created 4 years, 5 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/authenticator_test_base.h ('k') | remoting/protocol/connection_tester.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/channel_multiplexer.h" 5 #include "remoting/protocol/channel_multiplexer.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"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 std::unique_ptr<P2PStreamSocket>* host_socket, 92 std::unique_ptr<P2PStreamSocket>* host_socket,
93 std::unique_ptr<P2PStreamSocket>* client_socket) { 93 std::unique_ptr<P2PStreamSocket>* client_socket) {
94 int counter = 2; 94 int counter = 2;
95 host_mux_->CreateChannel(name, base::Bind( 95 host_mux_->CreateChannel(name, base::Bind(
96 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this), 96 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this),
97 host_socket, &counter)); 97 host_socket, &counter));
98 client_mux_->CreateChannel(name, base::Bind( 98 client_mux_->CreateChannel(name, base::Bind(
99 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this), 99 &ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this),
100 client_socket, &counter)); 100 client_socket, &counter));
101 101
102 message_loop_.Run(); 102 base::RunLoop().Run();
103 103
104 EXPECT_TRUE(host_socket->get()); 104 EXPECT_TRUE(host_socket->get());
105 EXPECT_TRUE(client_socket->get()); 105 EXPECT_TRUE(client_socket->get());
106 } 106 }
107 107
108 void OnChannelConnected(std::unique_ptr<P2PStreamSocket>* storage, 108 void OnChannelConnected(std::unique_ptr<P2PStreamSocket>* storage,
109 int* counter, 109 int* counter,
110 std::unique_ptr<P2PStreamSocket> socket) { 110 std::unique_ptr<P2PStreamSocket> socket) {
111 *storage = std::move(socket); 111 *storage = std::move(socket);
112 --(*counter); 112 --(*counter);
113 EXPECT_GE(*counter, 0); 113 EXPECT_GE(*counter, 0);
114 if (*counter == 0) 114 if (*counter == 0)
115 QuitCurrentThread(); 115 QuitCurrentThread();
116 } 116 }
117 117
118 scoped_refptr<net::IOBufferWithSize> CreateTestBuffer(int size) { 118 scoped_refptr<net::IOBufferWithSize> CreateTestBuffer(int size) {
119 scoped_refptr<net::IOBufferWithSize> result = 119 scoped_refptr<net::IOBufferWithSize> result =
120 new net::IOBufferWithSize(size); 120 new net::IOBufferWithSize(size);
121 for (int i = 0; i< size; ++i) { 121 for (int i = 0; i< size; ++i) {
122 result->data()[i] = rand() % 256; 122 result->data()[i] = rand() % 256;
123 } 123 }
124 return result; 124 return result;
125 } 125 }
126 126
127 private:
128 // Must be instantiated before the FakeStreamChannelFactories below.
127 base::MessageLoop message_loop_; 129 base::MessageLoop message_loop_;
128 130
131 protected:
129 FakeStreamChannelFactory host_channel_factory_; 132 FakeStreamChannelFactory host_channel_factory_;
130 FakeStreamChannelFactory client_channel_factory_; 133 FakeStreamChannelFactory client_channel_factory_;
131 134
132 std::unique_ptr<ChannelMultiplexer> host_mux_; 135 std::unique_ptr<ChannelMultiplexer> host_mux_;
133 std::unique_ptr<ChannelMultiplexer> client_mux_; 136 std::unique_ptr<ChannelMultiplexer> client_mux_;
134 137
135 std::unique_ptr<P2PStreamSocket> host_socket1_; 138 std::unique_ptr<P2PStreamSocket> host_socket1_;
136 std::unique_ptr<P2PStreamSocket> client_socket1_; 139 std::unique_ptr<P2PStreamSocket> client_socket1_;
137 std::unique_ptr<P2PStreamSocket> host_socket2_; 140 std::unique_ptr<P2PStreamSocket> host_socket2_;
138 std::unique_ptr<P2PStreamSocket> client_socket2_; 141 std::unique_ptr<P2PStreamSocket> client_socket2_;
139 }; 142 };
140 143
141 144
142 TEST_F(ChannelMultiplexerTest, OneChannel) { 145 TEST_F(ChannelMultiplexerTest, OneChannel) {
143 std::unique_ptr<P2PStreamSocket> host_socket; 146 std::unique_ptr<P2PStreamSocket> host_socket;
144 std::unique_ptr<P2PStreamSocket> client_socket; 147 std::unique_ptr<P2PStreamSocket> client_socket;
145 ASSERT_NO_FATAL_FAILURE( 148 ASSERT_NO_FATAL_FAILURE(
146 CreateChannel(kTestChannelName, &host_socket, &client_socket)); 149 CreateChannel(kTestChannelName, &host_socket, &client_socket));
147 150
148 StreamConnectionTester tester(host_socket.get(), client_socket.get(), 151 StreamConnectionTester tester(host_socket.get(), client_socket.get(),
149 kMessageSize, kMessages); 152 kMessageSize, kMessages);
150 tester.Start(); 153 tester.Start();
151 message_loop_.Run(); 154 base::RunLoop().Run();
152 tester.CheckResults(); 155 tester.CheckResults();
153 } 156 }
154 157
155 TEST_F(ChannelMultiplexerTest, TwoChannels) { 158 TEST_F(ChannelMultiplexerTest, TwoChannels) {
156 std::unique_ptr<P2PStreamSocket> host_socket1_; 159 std::unique_ptr<P2PStreamSocket> host_socket1_;
157 std::unique_ptr<P2PStreamSocket> client_socket1_; 160 std::unique_ptr<P2PStreamSocket> client_socket1_;
158 ASSERT_NO_FATAL_FAILURE( 161 ASSERT_NO_FATAL_FAILURE(
159 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_)); 162 CreateChannel(kTestChannelName, &host_socket1_, &client_socket1_));
160 163
161 std::unique_ptr<P2PStreamSocket> host_socket2_; 164 std::unique_ptr<P2PStreamSocket> host_socket2_;
162 std::unique_ptr<P2PStreamSocket> client_socket2_; 165 std::unique_ptr<P2PStreamSocket> client_socket2_;
163 ASSERT_NO_FATAL_FAILURE( 166 ASSERT_NO_FATAL_FAILURE(
164 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_)); 167 CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
165 168
166 StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(), 169 StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(),
167 kMessageSize, kMessages); 170 kMessageSize, kMessages);
168 StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(), 171 StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(),
169 kMessageSize, kMessages); 172 kMessageSize, kMessages);
170 tester1.Start(); 173 tester1.Start();
171 tester2.Start(); 174 tester2.Start();
172 while (!tester1.done() || !tester2.done()) { 175 while (!tester1.done() || !tester2.done()) {
173 message_loop_.Run(); 176 base::RunLoop().Run();
174 } 177 }
175 tester1.CheckResults(); 178 tester1.CheckResults();
176 tester2.CheckResults(); 179 tester2.CheckResults();
177 } 180 }
178 181
179 // Four channels, two in each direction 182 // Four channels, two in each direction
180 TEST_F(ChannelMultiplexerTest, FourChannels) { 183 TEST_F(ChannelMultiplexerTest, FourChannels) {
181 std::unique_ptr<P2PStreamSocket> host_socket1_; 184 std::unique_ptr<P2PStreamSocket> host_socket1_;
182 std::unique_ptr<P2PStreamSocket> client_socket1_; 185 std::unique_ptr<P2PStreamSocket> client_socket1_;
183 ASSERT_NO_FATAL_FAILURE( 186 ASSERT_NO_FATAL_FAILURE(
(...skipping 21 matching lines...) Expand all
205 StreamConnectionTester tester3(client_socket3.get(), host_socket3.get(), 208 StreamConnectionTester tester3(client_socket3.get(), host_socket3.get(),
206 kMessageSize, kMessages); 209 kMessageSize, kMessages);
207 StreamConnectionTester tester4(client_socket4.get(), host_socket4.get(), 210 StreamConnectionTester tester4(client_socket4.get(), host_socket4.get(),
208 kMessageSize, kMessages); 211 kMessageSize, kMessages);
209 tester1.Start(); 212 tester1.Start();
210 tester2.Start(); 213 tester2.Start();
211 tester3.Start(); 214 tester3.Start();
212 tester4.Start(); 215 tester4.Start();
213 while (!tester1.done() || !tester2.done() || 216 while (!tester1.done() || !tester2.done() ||
214 !tester3.done() || !tester4.done()) { 217 !tester3.done() || !tester4.done()) {
215 message_loop_.Run(); 218 base::RunLoop().Run();
216 } 219 }
217 tester1.CheckResults(); 220 tester1.CheckResults();
218 tester2.CheckResults(); 221 tester2.CheckResults();
219 tester3.CheckResults(); 222 tester3.CheckResults();
220 tester4.CheckResults(); 223 tester4.CheckResults();
221 } 224 }
222 225
223 TEST_F(ChannelMultiplexerTest, WriteFailSync) { 226 TEST_F(ChannelMultiplexerTest, WriteFailSync) {
224 std::unique_ptr<P2PStreamSocket> host_socket1_; 227 std::unique_ptr<P2PStreamSocket> host_socket1_;
225 std::unique_ptr<P2PStreamSocket> client_socket1_; 228 std::unique_ptr<P2PStreamSocket> client_socket1_;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 .WillOnce(InvokeWithoutArgs( 350 .WillOnce(InvokeWithoutArgs(
348 this, &ChannelMultiplexerTest::DeleteAfterSessionFail)); 351 this, &ChannelMultiplexerTest::DeleteAfterSessionFail));
349 EXPECT_CALL(cb2, OnConnectedPtr(_)) 352 EXPECT_CALL(cb2, OnConnectedPtr(_))
350 .Times(0); 353 .Times(0);
351 354
352 base::RunLoop().RunUntilIdle(); 355 base::RunLoop().RunUntilIdle();
353 } 356 }
354 357
355 } // namespace protocol 358 } // namespace protocol
356 } // namespace remoting 359 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/authenticator_test_base.h ('k') | remoting/protocol/connection_tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698