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

Unified Diff: remoting/protocol/webrtc_transport_unittest.cc

Issue 2146213002: Add support for dynamic channels in WebrtcTransport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/webrtc_transport.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/webrtc_transport_unittest.cc
diff --git a/remoting/protocol/webrtc_transport_unittest.cc b/remoting/protocol/webrtc_transport_unittest.cc
index eb56c8b3aa75b26369ddbb6970c91c2e7c07612d..e564b66ca2705a76534045b67d50d084ef9bcd8c 100644
--- a/remoting/protocol/webrtc_transport_unittest.cc
+++ b/remoting/protocol/webrtc_transport_unittest.cc
@@ -13,6 +13,7 @@
#include "jingle/glue/thread_wrapper.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_request_context_getter.h"
+#include "remoting/base/compound_buffer.h"
#include "remoting/protocol/connection_tester.h"
#include "remoting/protocol/fake_authenticator.h"
#include "remoting/protocol/message_channel_factory.h"
@@ -34,9 +35,12 @@ const char kAuthKey[] = "test_auth_key";
class TestTransportEventHandler : public WebrtcTransport::EventHandler {
public:
typedef base::Callback<void(ErrorCode error)> ErrorCallback;
+ typedef base::Callback<void(const std::string& name,
+ std::unique_ptr<MessagePipe> pipe)>
+ IncomingChannelCallback;
TestTransportEventHandler() {}
- ~TestTransportEventHandler() {}
+ ~TestTransportEventHandler() override {}
// All callbacks must be set before the test handler is passed to a Transport
// object.
@@ -49,6 +53,9 @@ class TestTransportEventHandler : public WebrtcTransport::EventHandler {
void set_error_callback(const ErrorCallback& callback) {
error_callback_ = callback;
}
+ void set_incoming_channel_callback(const IncomingChannelCallback& callback) {
+ incoming_channel_callback_ = callback;
+ }
// WebrtcTransport::EventHandler interface.
void OnWebrtcTransportConnecting() override {
@@ -62,6 +69,15 @@ class TestTransportEventHandler : public WebrtcTransport::EventHandler {
void OnWebrtcTransportError(ErrorCode error) override {
error_callback_.Run(error);
}
+ void OnWebrtcTransportIncomingDataChannel(
+ const std::string& name,
+ std::unique_ptr<MessagePipe> pipe) override {
+ if (!incoming_channel_callback_.is_null()) {
+ incoming_channel_callback_.Run(name, std::move(pipe));
+ } else {
+ FAIL() << "Received unexpected incoming channel.";
+ }
+ }
void OnWebrtcTransportMediaStreamAdded(
scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
void OnWebrtcTransportMediaStreamRemoved(
@@ -71,10 +87,39 @@ class TestTransportEventHandler : public WebrtcTransport::EventHandler {
base::Closure connecting_callback_;
base::Closure connected_callback_;
ErrorCallback error_callback_;
+ IncomingChannelCallback incoming_channel_callback_;
DISALLOW_COPY_AND_ASSIGN(TestTransportEventHandler);
};
+class TestMessagePipeEventHandler : public MessagePipe::EventHandler {
+ public:
+ TestMessagePipeEventHandler() {}
+ ~TestMessagePipeEventHandler() override {}
+
+ void set_closed_callback(const base::Closure& callback) {
+ closed_callback_ = callback;
+ }
+
+ // MessagePipe::EventHandler interface.
+ void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override {
+ NOTREACHED();
+ }
+
+ void OnMessagePipeClosed() override {
+ if (!closed_callback_.is_null()) {
+ closed_callback_.Run();
+ } else {
+ FAIL() << "Channel closed unexpectedly.";
+ }
+ }
+
+ private:
+ base::Closure closed_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestMessagePipeEventHandler);
+};
+
} // namespace
class WebrtcTransportTest : public testing::Test {
@@ -169,10 +214,9 @@ class WebrtcTransportTest : public testing::Test {
EXPECT_EQ(OK, host_error_);
}
- void CreateClientDataStream() {
- client_transport_->incoming_channel_factory()->CreateChannel(
- kChannelName, base::Bind(&WebrtcTransportTest::OnClientChannelCreated,
- base::Unretained(this)));
+ void ExpectClientDataStream() {
+ client_event_handler_.set_incoming_channel_callback(base::Bind(
+ &WebrtcTransportTest::OnIncomingChannel, base::Unretained(this)));
}
void CreateHostDataStream() {
@@ -181,7 +225,9 @@ class WebrtcTransportTest : public testing::Test {
base::Unretained(this)));
}
- void OnClientChannelCreated(std::unique_ptr<MessagePipe> pipe) {
+ void OnIncomingChannel(const std::string& name,
+ std::unique_ptr<MessagePipe> pipe) {
+ EXPECT_EQ(kChannelName, name);
client_message_pipe_ = std::move(pipe);
if (run_loop_ && host_message_pipe_)
run_loop_->Quit();
@@ -211,6 +257,11 @@ class WebrtcTransportTest : public testing::Test {
run_loop_->Quit();
}
+ void OnHostChannelClosed() {
+ host_message_pipe_.reset();
+ run_loop_->Quit();
+ }
+
void QuitRunLoopOnCounter(int* counter) {
--(*counter);
if (*counter == 0)
@@ -233,6 +284,7 @@ class WebrtcTransportTest : public testing::Test {
std::unique_ptr<MessagePipe> client_message_pipe_;
std::unique_ptr<MessagePipe> host_message_pipe_;
+ TestMessagePipeEventHandler host_message_pipe_event_handler_;
ErrorCode client_error_ = OK;
ErrorCode host_error_ = OK;
@@ -259,7 +311,7 @@ TEST_F(WebrtcTransportTest, InvalidAuthKey) {
TEST_F(WebrtcTransportTest, DataStream) {
client_event_handler_.set_connecting_callback(base::Bind(
- &WebrtcTransportTest::CreateClientDataStream, base::Unretained(this)));
+ &WebrtcTransportTest::ExpectClientDataStream, base::Unretained(this)));
host_event_handler_.set_connecting_callback(base::Bind(
&WebrtcTransportTest::CreateHostDataStream, base::Unretained(this)));
@@ -286,7 +338,7 @@ TEST_F(WebrtcTransportTest, DataStreamLate) {
StartConnection();
WaitUntilConnected();
- CreateClientDataStream();
+ ExpectClientDataStream();
CreateHostDataStream();
run_loop_.reset(new base::RunLoop());
@@ -301,7 +353,7 @@ TEST_F(WebrtcTransportTest, TerminateDataChannel) {
StartConnection();
WaitUntilConnected();
- CreateClientDataStream();
+ ExpectClientDataStream();
CreateHostDataStream();
run_loop_.reset(new base::RunLoop());
@@ -312,6 +364,12 @@ TEST_F(WebrtcTransportTest, TerminateDataChannel) {
destroy_on_error_ = true;
+ // Expect that the channel is closed on the host side once the client closes
+ // the channel.
+ host_message_pipe_->Start(&host_message_pipe_event_handler_);
+ host_message_pipe_event_handler_.set_closed_callback(base::Bind(
+ &WebrtcTransportTest::OnHostChannelClosed, base::Unretained(this)));
+
// Destroy pipe on one side of the of the connection. It should get closed on
// the other side.
client_message_pipe_.reset();
@@ -319,9 +377,9 @@ TEST_F(WebrtcTransportTest, TerminateDataChannel) {
run_loop_.reset(new base::RunLoop());
run_loop_->Run();
- // Check that OnSessionError() has been called.
- EXPECT_EQ(CHANNEL_CONNECTION_ERROR, host_error_);
- EXPECT_FALSE(host_transport_);
+ // Check that OnHostChannelClosed() has been called.
+ EXPECT_EQ(OK, host_error_);
+ EXPECT_FALSE(host_message_pipe_);
}
} // namespace protocol
« no previous file with comments | « remoting/protocol/webrtc_transport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698