Index: remoting/host/client_connection_unittest.cc |
=================================================================== |
--- remoting/host/client_connection_unittest.cc (revision 0) |
+++ remoting/host/client_connection_unittest.cc (revision 0) |
@@ -0,0 +1,99 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/message_loop.h" |
+#include "media/base/data_buffer.h" |
+#include "remoting/base/mock_objects.h" |
+#include "remoting/host/client_connection.h" |
+#include "remoting/host/mock_objects.h" |
+#include "remoting/jingle_glue/mock_objects.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+ |
+using ::testing::_; |
+using ::testing::NotNull; |
+ |
+namespace remoting { |
+ |
+class ClientConnectionTest : public testing::Test { |
+ public: |
+ ClientConnectionTest() { |
+ } |
+ |
+ protected: |
+ virtual void SetUp() { |
+ decoder_ = new MockProtocolDecoder(); |
+ channel_ = new MockJingleChannel(); |
+ |
+ // Allocate a ClientConnection object with the mock objects. we give the |
+ // ownership of decoder to the viewer. |
+ viewer_ = new ClientConnection(&message_loop_, |
+ decoder_, |
+ &handler_); |
+ |
+ viewer_->set_jingle_channel(channel_.get()); |
+ } |
+ |
+ MessageLoop message_loop_; |
+ MockProtocolDecoder* decoder_; |
+ MockClientConnectionEventHandler handler_; |
+ scoped_refptr<MockJingleChannel> channel_; |
+ scoped_refptr<ClientConnection> viewer_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ClientConnectionTest); |
+}; |
+ |
+TEST_F(ClientConnectionTest, SendUpdateStream) { |
+ // Tell the viewer we are starting an update stream. |
+ EXPECT_CALL(*channel_, Write(_)); |
+ viewer_->SendBeginUpdateStreamMessage(); |
+ |
+ // Then send the actual data. |
+ EXPECT_CALL(*channel_, Write(_)); |
+ chromotocol_pb::UpdateStreamPacketHeader* header |
+ = new chromotocol_pb::UpdateStreamPacketHeader(); |
+ header->set_x(0); |
+ header->set_y(0); |
+ header->set_width(640); |
+ header->set_height(480); |
+ scoped_refptr<media::DataBuffer> data = new media::DataBuffer(10); |
+ viewer_->SendUpdateStreamPacketMessage(header, data); |
+ delete header; |
+ |
+ // Send the end of update message. |
+ EXPECT_CALL(*channel_, Write(_)); |
+ viewer_->SendEndUpdateStreamMessage(); |
+ |
+ // And then close the connection to ClientConnection. |
+ EXPECT_CALL(*channel_, Close()); |
+ viewer_->Disconnect(); |
+} |
+ |
+TEST_F(ClientConnectionTest, StateChange) { |
+ EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); |
+ viewer_->OnStateChange(channel_.get(), JingleChannel::OPEN); |
+ message_loop_.RunAllPending(); |
+ |
+ EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); |
+ viewer_->OnStateChange(channel_.get(), JingleChannel::CLOSED); |
+ message_loop_.RunAllPending(); |
+ |
+ EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); |
+ viewer_->OnStateChange(channel_.get(), JingleChannel::FAILED); |
+ message_loop_.RunAllPending(); |
+} |
+ |
+TEST_F(ClientConnectionTest, ParseMessages) { |
+ scoped_refptr<media::DataBuffer> data; |
+ |
+ // Give the data to the ClientConnection, it will use ProtocolDecoder to |
+ // decode the messages. |
+ EXPECT_CALL(*decoder_, ParseClientMessages(data, NotNull())); |
+ EXPECT_CALL(handler_, HandleMessages(viewer_.get(), NotNull())); |
+ |
+ viewer_->OnPacketReceived(channel_.get(), data); |
+ message_loop_.RunAllPending(); |
+} |
+ |
+} // namespace remoting |
Property changes on: remoting/host/client_connection_unittest.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |