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

Unified Diff: remoting/protocol/connection_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 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/connection_unittest.cc
diff --git a/remoting/protocol/connection_unittest.cc b/remoting/protocol/connection_unittest.cc
index 9e32163f34184a9dd29c2d406a70c311de5226e9..425a3c1b3a6f38df454d035bd9da3627b5b49c5a 100644
--- a/remoting/protocol/connection_unittest.cc
+++ b/remoting/protocol/connection_unittest.cc
@@ -10,6 +10,7 @@
#include "remoting/protocol/ice_connection_to_client.h"
#include "remoting/protocol/ice_connection_to_host.h"
#include "remoting/protocol/protocol_mock_objects.h"
+#include "remoting/protocol/transport_context.h"
#include "remoting/protocol/webrtc_connection_to_client.h"
#include "remoting/protocol/webrtc_connection_to_host.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -64,13 +65,16 @@ class ConnectionTest : public testing::Test,
// Create Connection objects
if (GetParam()) {
- host_connection_.reset(
- new WebrtcConnectionToClient(make_scoped_ptr(host_session_)));
+ host_connection_.reset(new WebrtcConnectionToClient(
+ make_scoped_ptr(host_session_),
+ TransportContext::ForTests(protocol::TransportRole::SERVER)));
client_connection_.reset(new WebrtcConnectionToHost());
} else {
host_connection_.reset(new IceConnectionToClient(
- make_scoped_ptr(host_session_), message_loop_.task_runner()));
+ make_scoped_ptr(host_session_),
+ TransportContext::ForTests(protocol::TransportRole::SERVER),
+ message_loop_.task_runner()));
client_connection_.reset(new IceConnectionToHost());
}
@@ -95,7 +99,11 @@ class ConnectionTest : public testing::Test,
OnConnectionAuthenticated(host_connection_.get()));
}
EXPECT_CALL(host_event_handler_,
- OnConnectionChannelsConnected(host_connection_.get()));
+ OnConnectionChannelsConnected(host_connection_.get()))
+ .WillOnce(
+ InvokeWithoutArgs(this, &ConnectionTest::OnHostConnected));
+ EXPECT_CALL(host_event_handler_, OnRouteChange(_, _, _))
+ .Times(testing::AnyNumber());
{
testing::InSequence sequence;
@@ -104,13 +112,24 @@ class ConnectionTest : public testing::Test,
EXPECT_CALL(client_event_handler_,
OnConnectionState(ConnectionToHost::AUTHENTICATED, OK));
EXPECT_CALL(client_event_handler_,
- OnConnectionState(ConnectionToHost::CONNECTED, OK));
+ OnConnectionState(ConnectionToHost::CONNECTED, OK))
+ .WillOnce(InvokeWithoutArgs(
+ this, &ConnectionTest::OnClientConnected));
}
+ EXPECT_CALL(client_event_handler_, OnRouteChanged(_, _))
+ .Times(testing::AnyNumber());
- client_connection_->Connect(std::move(owned_client_session_),
- &client_event_handler_);
+ client_connection_->Connect(
+ std::move(owned_client_session_),
+ TransportContext::ForTests(protocol::TransportRole::CLIENT),
+ &client_event_handler_);
client_session_->SimulateConnection(host_session_);
- base::RunLoop().RunUntilIdle();
+
+ run_loop_.reset(new base::RunLoop());
+ run_loop_->Run();
+
+ EXPECT_TRUE(client_connected_);
+ EXPECT_TRUE(host_connected_);
}
void TearDown() override {
@@ -119,7 +138,20 @@ class ConnectionTest : public testing::Test,
base::RunLoop().RunUntilIdle();
}
- base::MessageLoop message_loop_;
+ void OnHostConnected() {
+ host_connected_ = true;
+ if (client_connected_ && run_loop_)
+ run_loop_->Quit();
+ }
+
+ void OnClientConnected() {
+ client_connected_ = true;
+ if (host_connected_ && run_loop_)
+ run_loop_->Quit();
+ }
+
+ base::MessageLoopForIO message_loop_;
+ scoped_ptr<base::RunLoop> run_loop_;
MockConnectionToClientEventHandler host_event_handler_;
MockClipboardStub host_clipboard_stub_;
@@ -127,6 +159,7 @@ class ConnectionTest : public testing::Test,
MockInputStub host_input_stub_;
scoped_ptr<ConnectionToClient> host_connection_;
FakeSession* host_session_; // Owned by |host_connection_|.
+ bool host_connected_ = false;
MockConnectionToHostEventCallback client_event_handler_;
MockClientStub client_stub_;
@@ -135,6 +168,7 @@ class ConnectionTest : public testing::Test,
scoped_ptr<ConnectionToHost> client_connection_;
FakeSession* client_session_; // Owned by |client_connection_|.
scoped_ptr<FakeSession> owned_client_session_;
+ bool client_connected_ = false;
private:
DISALLOW_COPY_AND_ASSIGN(ConnectionTest);
@@ -149,8 +183,10 @@ TEST_P(ConnectionTest, RejectConnection) {
EXPECT_CALL(client_event_handler_,
OnConnectionState(ConnectionToHost::CLOSED, OK));
- client_connection_->Connect(std::move(owned_client_session_),
- &client_event_handler_);
+ client_connection_->Connect(
+ std::move(owned_client_session_),
+ TransportContext::ForTests(protocol::TransportRole::CLIENT),
+ &client_event_handler_);
client_session_->event_handler()->OnSessionStateChange(Session::CLOSED);
}

Powered by Google App Engine
This is Rietveld 408576698