[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 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 "base/message_loop_proxy.h" |
| 7 | #include "remoting/jingle_glue/mock_objects.h" |
| 8 | #include "remoting/host/log_to_server.h" |
| 9 | #include "testing/gmock_mutant.h" |
| 10 | #include "testing/gmock/include/gmock/gmock.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 02f2de6 | 2011-11-23 03:45:11 | [diff] [blame] | 12 | #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 13 | |
| 14 | using testing::_; |
[email protected] | 02f2de6 | 2011-11-23 03:45:11 | [diff] [blame] | 15 | using testing::DeleteArg; |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 16 | using testing::InSequence; |
[email protected] | 02f2de6 | 2011-11-23 03:45:11 | [diff] [blame] | 17 | using testing::Return; |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 18 | |
| 19 | namespace remoting { |
| 20 | |
| 21 | namespace { |
| 22 | |
| 23 | ACTION_P(QuitMainMessageLoop, message_loop) { |
[email protected] | b9a514dd | 2011-12-09 04:02:56 | [diff] [blame] | 24 | message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | } // namespace |
| 28 | |
| 29 | class LogToServerTest : public testing::Test { |
| 30 | public: |
| 31 | LogToServerTest() {} |
| 32 | virtual void SetUp() OVERRIDE { |
| 33 | message_loop_proxy_ = base::MessageLoopProxy::current(); |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 34 | EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 35 | log_to_server_.reset(new LogToServer(&signal_strategy_)); |
| 36 | EXPECT_CALL(signal_strategy_, RemoveListener(_)); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | protected: |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 40 | MessageLoop message_loop_; |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 41 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 42 | MockSignalStrategy signal_strategy_; |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 43 | scoped_ptr<LogToServer> log_to_server_; |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | TEST_F(LogToServerTest, SendNow) { |
| 47 | { |
| 48 | InSequence s; |
[email protected] | 08128a31 | 2012-01-03 21:02:39 | [diff] [blame] | 49 | EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 50 | .WillRepeatedly(Return("[email protected]/1234")); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 51 | EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 52 | EXPECT_CALL(signal_strategy_, GetNextId()); |
[email protected] | 02f2de6 | 2011-11-23 03:45:11 | [diff] [blame] | 53 | EXPECT_CALL(signal_strategy_, SendStanza(_)) |
| 54 | .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 55 | EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 56 | .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| 57 | .RetiresOnSaturation(); |
| 58 | } |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 59 | log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 60 | log_to_server_->OnClientAuthenticated("[email protected]/5678"); |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 61 | log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 62 | message_loop_.Run(); |
| 63 | } |
| 64 | |
| 65 | TEST_F(LogToServerTest, SendLater) { |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 66 | log_to_server_->OnClientAuthenticated("[email protected]/5678"); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 67 | { |
| 68 | InSequence s; |
[email protected] | 08128a31 | 2012-01-03 21:02:39 | [diff] [blame] | 69 | EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 70 | .WillRepeatedly(Return("[email protected]/1234")); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 71 | EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 72 | EXPECT_CALL(signal_strategy_, GetNextId()); |
[email protected] | 02f2de6 | 2011-11-23 03:45:11 | [diff] [blame] | 73 | EXPECT_CALL(signal_strategy_, SendStanza(_)) |
| 74 | .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 75 | EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 76 | .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| 77 | .RetiresOnSaturation(); |
| 78 | } |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 79 | log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 80 | log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 81 | message_loop_.Run(); |
| 82 | } |
| 83 | |
| 84 | TEST_F(LogToServerTest, SendTwoEntriesLater) { |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 85 | log_to_server_->OnClientAuthenticated("[email protected]/5678"); |
| 86 | log_to_server_->OnClientAuthenticated("[email protected]/6789"); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 87 | { |
| 88 | InSequence s; |
[email protected] | 08128a31 | 2012-01-03 21:02:39 | [diff] [blame] | 89 | EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 90 | .WillRepeatedly(Return("[email protected]/1234")); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 91 | EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 92 | EXPECT_CALL(signal_strategy_, GetNextId()); |
[email protected] | 02f2de6 | 2011-11-23 03:45:11 | [diff] [blame] | 93 | EXPECT_CALL(signal_strategy_, SendStanza(_)) |
| 94 | .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 95 | EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 96 | .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| 97 | .RetiresOnSaturation(); |
| 98 | } |
[email protected] | 988dfc3c | 2012-01-04 01:10:11 | [diff] [blame^] | 99 | log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 100 | log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
[email protected] | 00c794a | 2011-11-22 22:48:55 | [diff] [blame] | 101 | message_loop_.Run(); |
| 102 | } |
| 103 | |
| 104 | } // namespace remoting |