OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 "base/message_loop.h" |
| 6 #include "media/base/data_buffer.h" |
| 7 #include "remoting/base/mock_objects.h" |
| 8 #include "remoting/host/client_connection.h" |
| 9 #include "remoting/host/mock_objects.h" |
| 10 #include "remoting/jingle_glue/mock_objects.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 |
| 13 using ::testing::_; |
| 14 using ::testing::NotNull; |
| 15 |
| 16 namespace remoting { |
| 17 |
| 18 class ClientConnectionTest : public testing::Test { |
| 19 public: |
| 20 ClientConnectionTest() { |
| 21 } |
| 22 |
| 23 protected: |
| 24 virtual void SetUp() { |
| 25 decoder_ = new MockProtocolDecoder(); |
| 26 channel_ = new MockJingleChannel(); |
| 27 |
| 28 // Allocate a ClientConnection object with the mock objects. we give the |
| 29 // ownership of decoder to the viewer. |
| 30 viewer_ = new ClientConnection(&message_loop_, |
| 31 decoder_, |
| 32 &handler_); |
| 33 |
| 34 viewer_->set_jingle_channel(channel_.get()); |
| 35 } |
| 36 |
| 37 MessageLoop message_loop_; |
| 38 MockProtocolDecoder* decoder_; |
| 39 MockClientConnectionEventHandler handler_; |
| 40 scoped_refptr<MockJingleChannel> channel_; |
| 41 scoped_refptr<ClientConnection> viewer_; |
| 42 |
| 43 private: |
| 44 DISALLOW_COPY_AND_ASSIGN(ClientConnectionTest); |
| 45 }; |
| 46 |
| 47 TEST_F(ClientConnectionTest, SendUpdateStream) { |
| 48 // Tell the viewer we are starting an update stream. |
| 49 EXPECT_CALL(*channel_, Write(_)); |
| 50 viewer_->SendBeginUpdateStreamMessage(); |
| 51 |
| 52 // Then send the actual data. |
| 53 EXPECT_CALL(*channel_, Write(_)); |
| 54 chromotocol_pb::UpdateStreamPacketHeader* header |
| 55 = new chromotocol_pb::UpdateStreamPacketHeader(); |
| 56 header->set_x(0); |
| 57 header->set_y(0); |
| 58 header->set_width(640); |
| 59 header->set_height(480); |
| 60 scoped_refptr<media::DataBuffer> data = new media::DataBuffer(10); |
| 61 viewer_->SendUpdateStreamPacketMessage(header, data); |
| 62 delete header; |
| 63 |
| 64 // Send the end of update message. |
| 65 EXPECT_CALL(*channel_, Write(_)); |
| 66 viewer_->SendEndUpdateStreamMessage(); |
| 67 |
| 68 // And then close the connection to ClientConnection. |
| 69 EXPECT_CALL(*channel_, Close()); |
| 70 viewer_->Disconnect(); |
| 71 } |
| 72 |
| 73 TEST_F(ClientConnectionTest, StateChange) { |
| 74 EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); |
| 75 viewer_->OnStateChange(channel_.get(), JingleChannel::OPEN); |
| 76 message_loop_.RunAllPending(); |
| 77 |
| 78 EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); |
| 79 viewer_->OnStateChange(channel_.get(), JingleChannel::CLOSED); |
| 80 message_loop_.RunAllPending(); |
| 81 |
| 82 EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); |
| 83 viewer_->OnStateChange(channel_.get(), JingleChannel::FAILED); |
| 84 message_loop_.RunAllPending(); |
| 85 } |
| 86 |
| 87 TEST_F(ClientConnectionTest, ParseMessages) { |
| 88 scoped_refptr<media::DataBuffer> data; |
| 89 |
| 90 // Give the data to the ClientConnection, it will use ProtocolDecoder to |
| 91 // decode the messages. |
| 92 EXPECT_CALL(*decoder_, ParseClientMessages(data, NotNull())); |
| 93 EXPECT_CALL(handler_, HandleMessages(viewer_.get(), NotNull())); |
| 94 |
| 95 viewer_->OnPacketReceived(channel_.get(), data); |
| 96 message_loop_.RunAllPending(); |
| 97 } |
| 98 |
| 99 } // namespace remoting |
OLD | NEW |