OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/protocol/webrtc_connection_to_client.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "remoting/base/constants.h" |
| 11 #include "remoting/protocol/fake_session.h" |
| 12 #include "remoting/protocol/message_serialization.h" |
| 13 #include "remoting/protocol/protocol_mock_objects.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace remoting { |
| 17 namespace protocol { |
| 18 |
| 19 class WebrtcConnectionToClientTest : public testing::Test { |
| 20 public: |
| 21 WebrtcConnectionToClientTest() {} |
| 22 |
| 23 protected: |
| 24 void SetUp() override { |
| 25 session_ = new FakeSession(); |
| 26 |
| 27 // Allocate a ClientConnection object with the mock objects. |
| 28 connection_.reset(new WebrtcConnectionToClient(make_scoped_ptr(session_))); |
| 29 connection_->SetEventHandler(&handler_); |
| 30 EXPECT_CALL(handler_, OnConnectionAuthenticated(connection_.get())) |
| 31 .WillOnce(InvokeWithoutArgs( |
| 32 this, &WebrtcConnectionToClientTest::ConnectStubs)); |
| 33 EXPECT_CALL(handler_, OnConnectionChannelsConnected(connection_.get())); |
| 34 session_->event_handler()->OnSessionStateChange(Session::ACCEPTED); |
| 35 session_->event_handler()->OnSessionStateChange(Session::AUTHENTICATED); |
| 36 session_->event_handler()->OnSessionStateChange(Session::CONNECTED); |
| 37 base::RunLoop().RunUntilIdle(); |
| 38 } |
| 39 |
| 40 void TearDown() override { |
| 41 connection_.reset(); |
| 42 base::RunLoop().RunUntilIdle(); |
| 43 } |
| 44 |
| 45 void ConnectStubs() { |
| 46 connection_->set_clipboard_stub(&clipboard_stub_); |
| 47 connection_->set_host_stub(&host_stub_); |
| 48 connection_->set_input_stub(&input_stub_); |
| 49 } |
| 50 |
| 51 base::MessageLoop message_loop_; |
| 52 MockConnectionToClientEventHandler handler_; |
| 53 MockClipboardStub clipboard_stub_; |
| 54 MockHostStub host_stub_; |
| 55 MockInputStub input_stub_; |
| 56 scoped_ptr<ConnectionToClient> connection_; |
| 57 |
| 58 FakeSession* session_; |
| 59 |
| 60 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(WebrtcConnectionToClientTest); |
| 62 }; |
| 63 |
| 64 TEST_F(WebrtcConnectionToClientTest, SendCapabilitesMessage) { |
| 65 Capabilities capabilities; |
| 66 connection_->client_stub()->SetCapabilities(capabilities); |
| 67 |
| 68 base::RunLoop().RunUntilIdle(); |
| 69 |
| 70 // Verify that something has been written. |
| 71 // TODO(sergeyu): Verify that the correct data has been written. |
| 72 FakeStreamSocket* channel = |
| 73 session_->GetTransport()->GetStreamChannelFactory()->GetFakeChannel( |
| 74 kControlChannelName); |
| 75 ASSERT_TRUE(channel); |
| 76 EXPECT_FALSE(channel->written_data().empty()); |
| 77 |
| 78 ControlMessage message; |
| 79 message.mutable_capabilities()->CopyFrom(capabilities); |
| 80 scoped_refptr<net::IOBufferWithSize> expected_message = |
| 81 SerializeAndFrameMessage(message); |
| 82 EXPECT_EQ(std::string(expected_message->data(), expected_message->size()), |
| 83 channel->written_data()); |
| 84 |
| 85 // And then close the connection to ConnectionToClient. |
| 86 connection_->Disconnect(protocol::OK); |
| 87 |
| 88 base::RunLoop().RunUntilIdle(); |
| 89 } |
| 90 |
| 91 // TODO(sergeyu): Add more tests here after Session is refactored not to own |
| 92 // Transport, which will allow to use real WebrtcTransport with FakeSession. |
| 93 |
| 94 } // namespace protocol |
| 95 } // namespace remoting |
OLD | NEW |