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

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

Issue 1536713005: Cleanup ChannelMultiplexer tests to avoid dependency on FakeSession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connection_tests
Patch Set: Created 5 years 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/fake_stream_socket.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/fake_stream_socket.h" 5 #include "remoting/protocol/fake_stream_socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "net/base/address_list.h" 11 #include "net/base/address_list.h"
12 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/net_util.h" 14 #include "net/base/net_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace remoting { 17 namespace remoting {
18 namespace protocol { 18 namespace protocol {
19 19
20 FakeStreamSocket::FakeStreamSocket() 20 FakeStreamSocket::FakeStreamSocket()
21 : async_write_(false), 21 : task_runner_(base::ThreadTaskRunnerHandle::Get()), weak_factory_(this) {}
22 write_pending_(false),
23 write_limit_(0),
24 next_write_error_(net::OK),
25 next_read_error_(net::OK),
26 read_buffer_size_(0),
27 input_pos_(0),
28 task_runner_(base::ThreadTaskRunnerHandle::Get()),
29 weak_factory_(this) {
30 }
31 22
32 FakeStreamSocket::~FakeStreamSocket() { 23 FakeStreamSocket::~FakeStreamSocket() {
33 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); 24 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
34 if (peer_socket_) { 25 if (peer_socket_) {
35 task_runner_->PostTask( 26 task_runner_->PostTask(
36 FROM_HERE, base::Bind(&FakeStreamSocket::AppendReadError, peer_socket_, 27 FROM_HERE, base::Bind(&FakeStreamSocket::AppendReadError, peer_socket_,
37 net::ERR_CONNECTION_CLOSED)); 28 net::ERR_CONNECTION_CLOSED));
38 } 29 }
39 } 30 }
40 31
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 task_runner_->PostTask( 141 task_runner_->PostTask(
151 FROM_HERE, 142 FROM_HERE,
152 base::Bind(&FakeStreamSocket::AppendInputData, 143 base::Bind(&FakeStreamSocket::AppendInputData,
153 peer_socket_, 144 peer_socket_,
154 std::string(buf->data(), buf->data() + buf_len))); 145 std::string(buf->data(), buf->data() + buf_len)));
155 } 146 }
156 } 147 }
157 148
158 FakeStreamChannelFactory::FakeStreamChannelFactory() 149 FakeStreamChannelFactory::FakeStreamChannelFactory()
159 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 150 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
160 asynchronous_create_(false),
161 fail_create_(false),
162 weak_factory_(this) { 151 weak_factory_(this) {
163 } 152 }
164 153
165 FakeStreamChannelFactory::~FakeStreamChannelFactory() {} 154 FakeStreamChannelFactory::~FakeStreamChannelFactory() {}
166 155
167 FakeStreamSocket* FakeStreamChannelFactory::GetFakeChannel( 156 FakeStreamSocket* FakeStreamChannelFactory::GetFakeChannel(
168 const std::string& name) { 157 const std::string& name) {
169 return channels_[name].get(); 158 return channels_[name].get();
170 } 159 }
171 160
172 void FakeStreamChannelFactory::PairWith( 161 void FakeStreamChannelFactory::PairWith(
173 FakeStreamChannelFactory* peer_factory) { 162 FakeStreamChannelFactory* peer_factory) {
174 peer_factory_ = peer_factory->weak_factory_.GetWeakPtr(); 163 peer_factory_ = peer_factory->weak_factory_.GetWeakPtr();
175 peer_factory->peer_factory_ = weak_factory_.GetWeakPtr(); 164 peer_factory->peer_factory_ = weak_factory_.GetWeakPtr();
176 } 165 }
177 166
178 void FakeStreamChannelFactory::CreateChannel( 167 void FakeStreamChannelFactory::CreateChannel(
179 const std::string& name, 168 const std::string& name,
180 const ChannelCreatedCallback& callback) { 169 const ChannelCreatedCallback& callback) {
181 scoped_ptr<FakeStreamSocket> channel(new FakeStreamSocket()); 170 scoped_ptr<FakeStreamSocket> channel(new FakeStreamSocket());
182 channels_[name] = channel->GetWeakPtr(); 171 channels_[name] = channel->GetWeakPtr();
172 channel->set_async_write(async_write_);
183 173
184 if (peer_factory_) { 174 if (peer_factory_) {
185 FakeStreamSocket* peer_channel = peer_factory_->GetFakeChannel(name); 175 FakeStreamSocket* peer_channel = peer_factory_->GetFakeChannel(name);
186 if (peer_channel) 176 if (peer_channel)
187 channel->PairWith(peer_channel); 177 channel->PairWith(peer_channel);
188 } 178 }
189 179
190 if (fail_create_) 180 if (fail_create_)
191 channel.reset(); 181 channel.reset();
192 182
(...skipping 13 matching lines...) Expand all
206 if (channels_.find(name) != channels_.end()) 196 if (channels_.find(name) != channels_.end())
207 callback.Run(owned_channel.Pass()); 197 callback.Run(owned_channel.Pass());
208 } 198 }
209 199
210 void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) { 200 void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) {
211 channels_.erase(name); 201 channels_.erase(name);
212 } 202 }
213 203
214 } // namespace protocol 204 } // namespace protocol
215 } // namespace remoting 205 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/fake_stream_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698