Chromium Code Reviews| Index: remoting/host/log_to_server_unittest.cc |
| diff --git a/remoting/host/log_to_server_unittest.cc b/remoting/host/log_to_server_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..54a0ba3494a4f365c2c636f75e07af130644bd5d |
| --- /dev/null |
| +++ b/remoting/host/log_to_server_unittest.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright (c) 2011 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 "base/message_loop_proxy.h" |
| +#include "remoting/jingle_glue/mock_objects.h" |
| +#include "remoting/host/log_to_server.h" |
| +#include "testing/gmock_mutant.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using testing::_; |
| +using testing::InSequence; |
| + |
| +namespace remoting { |
| + |
| +namespace { |
| + |
| +ACTION_P(QuitMainMessageLoop, message_loop) { |
| + message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| +} |
| + |
| +} |
| + |
| +class LogToServerTest : public testing::Test { |
|
Sergey Ulanov
2011/11/17 01:16:33
Thanks for writing unittests!
simonmorris
2011/11/18 19:23:04
You're welcome!
|
| + public: |
| + LogToServerTest() {} |
| + virtual void SetUp() OVERRIDE { |
| + message_loop_proxy_ = base::MessageLoopProxy::current(); |
| + log_to_server_ = new LogToServer(message_loop_proxy_); |
| + } |
| + |
| + protected: |
| + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| + scoped_refptr<LogToServer> log_to_server_; |
| + MessageLoop message_loop_; |
| + MockSignalStrategy signal_strategy_; |
| +}; |
| + |
| +TEST_F(LogToServerTest, SendNow) { |
| + { |
| + InSequence s; |
| + EXPECT_CALL(signal_strategy_, AddListener(_)); |
| + EXPECT_CALL(signal_strategy_, GetNextId()); |
| + EXPECT_CALL(signal_strategy_, SendStanza(_)); |
| + EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| + .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| + .RetiresOnSaturation(); |
| + } |
| + log_to_server_->OnSignallingConnected(&signal_strategy_, |
| + "host@domain.com/1234"); |
| + log_to_server_->OnClientAuthenticated("client@domain.com/5678"); |
| + log_to_server_->OnSignallingDisconnected(); |
| + message_loop_.Run(); |
| +} |
| + |
| +TEST_F(LogToServerTest, SendLater) { |
| + { |
| + InSequence s; |
| + EXPECT_CALL(signal_strategy_, AddListener(_)); |
| + EXPECT_CALL(signal_strategy_, GetNextId()); |
| + EXPECT_CALL(signal_strategy_, SendStanza(_)); |
| + EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| + .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| + .RetiresOnSaturation(); |
| + } |
| + log_to_server_->OnClientAuthenticated("client@domain.com/5678"); |
| + log_to_server_->OnSignallingConnected(&signal_strategy_, |
| + "host@domain.com/1234"); |
| + log_to_server_->OnSignallingDisconnected(); |
| + message_loop_.Run(); |
| +} |
| + |
| +TEST_F(LogToServerTest, SendTwoEntriesLater) { |
| + { |
| + InSequence s; |
| + EXPECT_CALL(signal_strategy_, AddListener(_)); |
| + EXPECT_CALL(signal_strategy_, GetNextId()); |
| + EXPECT_CALL(signal_strategy_, SendStanza(_)); |
| + EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| + .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| + .RetiresOnSaturation(); |
| + } |
| + log_to_server_->OnClientAuthenticated("client@domain.com/5678"); |
| + log_to_server_->OnClientAuthenticated("client2@domain.com/6789"); |
| + log_to_server_->OnSignallingConnected(&signal_strategy_, |
| + "host@domain.com/1234"); |
| + log_to_server_->OnSignallingDisconnected(); |
| + message_loop_.Run(); |
| +} |
| + |
| +} // namespace remoting |