Commit 764fcbc6 authored by sergeyu's avatar sergeyu Committed by Commit bot

Cleanup ChannelMultiplexer tests to avoid dependency on FakeSession.

Previously these tests were using FakeSession. Updated them
to use FakeStreamChannelFactory.

Review URL: https://codereview.chromium.org/1536713005

Cr-Commit-Position: refs/heads/master@{#365963}
parent c4c42fe0
......@@ -12,7 +12,7 @@
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/protocol/connection_tester.h"
#include "remoting/protocol/fake_session.h"
#include "remoting/protocol/fake_stream_socket.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -71,30 +71,16 @@ class ChannelMultiplexerTest : public testing::Test {
protected:
void SetUp() override {
host_channel_factory_.PairWith(&client_channel_factory_);
// Create pair of multiplexers and connect them to each other.
host_mux_.reset(new ChannelMultiplexer(
host_session_.GetTransport()->GetStreamChannelFactory(),
kMuxChannelName));
client_mux_.reset(new ChannelMultiplexer(
client_session_.GetTransport()->GetStreamChannelFactory(),
kMuxChannelName));
}
host_mux_.reset(
new ChannelMultiplexer(&host_channel_factory_, kMuxChannelName));
client_mux_.reset(
new ChannelMultiplexer(&client_channel_factory_, kMuxChannelName));
// Connect sockets to each other. Must be called after we've created at least
// one channel with each multiplexer.
void ConnectSockets() {
FakeStreamSocket* host_socket =
host_session_.GetTransport()
->GetStreamChannelFactory()
->GetFakeChannel(ChannelMultiplexer::kMuxChannelName);
FakeStreamSocket* client_socket =
client_session_.GetTransport()
->GetStreamChannelFactory()
->GetFakeChannel(ChannelMultiplexer::kMuxChannelName);
host_socket->PairWith(client_socket);
// Make writes asynchronous in one direction.
host_socket->set_async_write(true);
// Make writes asynchronous in one direction
host_channel_factory_.set_async_write(true);
}
void CreateChannel(const std::string& name,
......@@ -136,8 +122,8 @@ class ChannelMultiplexerTest : public testing::Test {
base::MessageLoop message_loop_;
FakeSession host_session_;
FakeSession client_session_;
FakeStreamChannelFactory host_channel_factory_;
FakeStreamChannelFactory client_channel_factory_;
scoped_ptr<ChannelMultiplexer> host_mux_;
scoped_ptr<ChannelMultiplexer> client_mux_;
......@@ -155,8 +141,6 @@ TEST_F(ChannelMultiplexerTest, OneChannel) {
ASSERT_NO_FATAL_FAILURE(
CreateChannel(kTestChannelName, &host_socket, &client_socket));
ConnectSockets();
StreamConnectionTester tester(host_socket.get(), client_socket.get(),
kMessageSize, kMessages);
tester.Start();
......@@ -175,8 +159,6 @@ TEST_F(ChannelMultiplexerTest, TwoChannels) {
ASSERT_NO_FATAL_FAILURE(
CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
ConnectSockets();
StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(),
kMessageSize, kMessages);
StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(),
......@@ -212,8 +194,6 @@ TEST_F(ChannelMultiplexerTest, FourChannels) {
ASSERT_NO_FATAL_FAILURE(
CreateChannel("ch4", &host_socket4, &client_socket4));
ConnectSockets();
StreamConnectionTester tester1(host_socket1_.get(), client_socket1_.get(),
kMessageSize, kMessages);
StreamConnectionTester tester2(host_socket2_.get(), client_socket2_.get(),
......@@ -247,11 +227,8 @@ TEST_F(ChannelMultiplexerTest, WriteFailSync) {
ASSERT_NO_FATAL_FAILURE(
CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
ConnectSockets();
FakeStreamSocket* socket =
host_session_.GetTransport()->GetStreamChannelFactory()->GetFakeChannel(
kMuxChannelName);
host_channel_factory_.GetFakeChannel(kMuxChannelName);
socket->set_next_write_error(net::ERR_FAILED);
socket->set_async_write(false);
......@@ -283,11 +260,8 @@ TEST_F(ChannelMultiplexerTest, WriteFailAsync) {
ASSERT_NO_FATAL_FAILURE(
CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
ConnectSockets();
FakeStreamSocket* socket =
host_session_.GetTransport()->GetStreamChannelFactory()->GetFakeChannel(
kMuxChannelName);
host_channel_factory_.GetFakeChannel(kMuxChannelName);
socket->set_next_write_error(net::ERR_FAILED);
socket->set_async_write(true);
......@@ -318,11 +292,8 @@ TEST_F(ChannelMultiplexerTest, DeleteWhenFailed) {
ASSERT_NO_FATAL_FAILURE(
CreateChannel(kTestChannelName2, &host_socket2_, &client_socket2_));
ConnectSockets();
FakeStreamSocket* socket =
host_session_.GetTransport()->GetStreamChannelFactory()->GetFakeChannel(
kMuxChannelName);
host_channel_factory_.GetFakeChannel(kMuxChannelName);
socket->set_next_write_error(net::ERR_FAILED);
socket->set_async_write(true);
......@@ -356,10 +327,8 @@ TEST_F(ChannelMultiplexerTest, DeleteWhenFailed) {
}
TEST_F(ChannelMultiplexerTest, SessionFail) {
host_session_.GetTransport()->GetStreamChannelFactory()
->set_asynchronous_create(true);
host_session_.GetTransport()->GetStreamChannelFactory()
->set_fail_create(true);
host_channel_factory_.set_asynchronous_create(true);
host_channel_factory_.set_fail_create(true);
MockConnectCallback cb1;
MockConnectCallback cb2;
......
......@@ -18,16 +18,7 @@ namespace remoting {
namespace protocol {
FakeStreamSocket::FakeStreamSocket()
: async_write_(false),
write_pending_(false),
write_limit_(0),
next_write_error_(net::OK),
next_read_error_(net::OK),
read_buffer_size_(0),
input_pos_(0),
task_runner_(base::ThreadTaskRunnerHandle::Get()),
weak_factory_(this) {
}
: task_runner_(base::ThreadTaskRunnerHandle::Get()), weak_factory_(this) {}
FakeStreamSocket::~FakeStreamSocket() {
EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
......@@ -157,8 +148,6 @@ void FakeStreamSocket::DoWrite(const scoped_refptr<net::IOBuffer>& buf,
FakeStreamChannelFactory::FakeStreamChannelFactory()
: task_runner_(base::ThreadTaskRunnerHandle::Get()),
asynchronous_create_(false),
fail_create_(false),
weak_factory_(this) {
}
......@@ -180,6 +169,7 @@ void FakeStreamChannelFactory::CreateChannel(
const ChannelCreatedCallback& callback) {
scoped_ptr<FakeStreamSocket> channel(new FakeStreamSocket());
channels_[name] = channel->GetWeakPtr();
channel->set_async_write(async_write_);
if (peer_factory_) {
FakeStreamSocket* peer_channel = peer_factory_->GetFakeChannel(name);
......
......@@ -79,20 +79,20 @@ class FakeStreamSocket : public P2PStreamSocket {
const net::CompletionCallback& callback);
void DoWrite(const scoped_refptr<net::IOBuffer>& buf, int buf_len);
bool async_write_;
bool write_pending_;
int write_limit_;
int next_write_error_;
bool async_write_ = false;
bool write_pending_ = false;
int write_limit_ = 0;
int next_write_error_ = 0;
int next_read_error_;
int next_read_error_ = 0;
scoped_refptr<net::IOBuffer> read_buffer_;
int read_buffer_size_;
int read_buffer_size_ = 0;
net::CompletionCallback read_callback_;
base::WeakPtr<FakeStreamSocket> peer_socket_;
std::string written_data_;
std::string input_data_;
int input_pos_;
int input_pos_ = 0;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::WeakPtrFactory<FakeStreamSocket> weak_factory_;
......@@ -112,6 +112,9 @@ class FakeStreamChannelFactory : public StreamChannelFactory {
void set_fail_create(bool fail_create) { fail_create_ = fail_create; }
// Enables asynchronous Write() on created channels.
void set_async_write(bool async_write) { async_write_ = async_write; }
FakeStreamSocket* GetFakeChannel(const std::string& name);
// Pairs the socket with |peer_socket|. Deleting either of the paired sockets
......@@ -129,10 +132,12 @@ class FakeStreamChannelFactory : public StreamChannelFactory {
const ChannelCreatedCallback& callback);
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
bool asynchronous_create_;
std::map<std::string, base::WeakPtr<FakeStreamSocket> > channels_;
bool asynchronous_create_ = false;
std::map<std::string, base::WeakPtr<FakeStreamSocket>> channels_;
bool fail_create_ = false;
bool fail_create_;
bool async_write_ = false;
base::WeakPtr<FakeStreamChannelFactory> peer_factory_;
base::WeakPtrFactory<FakeStreamChannelFactory> weak_factory_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment