diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 01:18:04 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 01:18:04 +0000 |
commit | cd8d237c83f5fcd1fc0d06e9fdd840fb4e24ac94 (patch) | |
tree | efeef519dfd771c46b9f616fbdca1bbcaa04fadf /remoting/protocol/connection_to_client_unittest.cc | |
parent | 8281e0b5d1afe79d257f4e6c1b5156533aa12c0f (diff) | |
download | chromium_src-cd8d237c83f5fcd1fc0d06e9fdd840fb4e24ac94.zip chromium_src-cd8d237c83f5fcd1fc0d06e9fdd840fb4e24ac94.tar.gz chromium_src-cd8d237c83f5fcd1fc0d06e9fdd840fb4e24ac94.tar.bz2 |
Moving/Rename host/ClientConnection.{h,cc} -> protocol/ConnectionToClient.{h,cc}
Also move the unittest.
BUG=None
TEST=compiles
Review URL: http://codereview.chromium.org/4352002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65009 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/connection_to_client_unittest.cc')
-rw-r--r-- | remoting/protocol/connection_to_client_unittest.cc | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/remoting/protocol/connection_to_client_unittest.cc b/remoting/protocol/connection_to_client_unittest.cc new file mode 100644 index 0000000..45b9143 --- /dev/null +++ b/remoting/protocol/connection_to_client_unittest.cc @@ -0,0 +1,91 @@ +// 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 "remoting/base/mock_objects.h" +#include "remoting/host/mock_objects.h" +#include "remoting/protocol/fake_session.h" +#include "remoting/protocol/connection_to_client.h" +#include "remoting/protocol/mock_objects.h" +#include "testing/gmock/include/gmock/gmock.h" + +using ::testing::_; +using ::testing::NotNull; +using ::testing::StrictMock; + +namespace remoting { +namespace protocol { + +class ConnectionToClientTest : public testing::Test { + public: + ConnectionToClientTest() { + } + + protected: + virtual void SetUp() { + session_ = new protocol::FakeSession(); + session_->set_message_loop(&message_loop_); + + // Allocate a ClientConnection object with the mock objects. + viewer_ = new ConnectionToClient(&message_loop_, &handler_); + viewer_->Init(session_); + EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); + session_->state_change_callback()->Run( + protocol::Session::CONNECTED); + message_loop_.RunAllPending(); + } + + MessageLoop message_loop_; + MockConnectionToClientEventHandler handler_; + scoped_refptr<ConnectionToClient> viewer_; + + scoped_refptr<protocol::FakeSession> session_; + + private: + DISALLOW_COPY_AND_ASSIGN(ConnectionToClientTest); +}; + +TEST_F(ConnectionToClientTest, SendUpdateStream) { + // Then send the actual data. + VideoPacket packet; + viewer_->SendVideoPacket(packet); + + // And then close the connection to ConnectionToClient. + viewer_->Disconnect(); + + message_loop_.RunAllPending(); + + // Verify that something has been written. + // TODO(sergeyu): Verify that the correct data has been written. + EXPECT_GT(session_->video_channel()->written_data().size(), 0u); +} + +TEST_F(ConnectionToClientTest, StateChange) { + EXPECT_CALL(handler_, OnConnectionClosed(viewer_.get())); + session_->state_change_callback()->Run(protocol::Session::CLOSED); + message_loop_.RunAllPending(); + + EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get())); + session_->state_change_callback()->Run(protocol::Session::FAILED); + message_loop_.RunAllPending(); +} + +// Test that we can close client connection more than once and operations +// after the connection is closed has no effect. +TEST_F(ConnectionToClientTest, Close) { + viewer_->Disconnect(); + message_loop_.RunAllPending(); + EXPECT_TRUE(session_->is_closed()); + + VideoPacket packet; + viewer_->SendVideoPacket(packet); + viewer_->Disconnect(); + message_loop_.RunAllPending(); + + // Verify that nothing has been written. + EXPECT_EQ(session_->video_channel()->written_data().size(), 0u); +} + +} // namespace protocol +} // namespace remoting |