blob: 60e7c2f57c0b8cd0ad8f34f90f55ee77adc2194c [file] [log] [blame]
[email protected]988dfc3c2012-01-04 01:10:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]00c794a2011-11-22 22:48:552// 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]02f2de62011-11-23 03:45:1112#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
[email protected]00c794a2011-11-22 22:48:5513
14using testing::_;
[email protected]02f2de62011-11-23 03:45:1115using testing::DeleteArg;
[email protected]00c794a2011-11-22 22:48:5516using testing::InSequence;
[email protected]02f2de62011-11-23 03:45:1117using testing::Return;
[email protected]00c794a2011-11-22 22:48:5518
19namespace remoting {
20
21namespace {
22
23ACTION_P(QuitMainMessageLoop, message_loop) {
[email protected]b9a514dd2011-12-09 04:02:5624 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
[email protected]00c794a2011-11-22 22:48:5525}
26
27} // namespace
28
29class LogToServerTest : public testing::Test {
30 public:
31 LogToServerTest() {}
32 virtual void SetUp() OVERRIDE {
33 message_loop_proxy_ = base::MessageLoopProxy::current();
[email protected]988dfc3c2012-01-04 01:10:1134 EXPECT_CALL(signal_strategy_, AddListener(_));
35 log_to_server_.reset(new LogToServer(&signal_strategy_));
36 EXPECT_CALL(signal_strategy_, RemoveListener(_));
[email protected]00c794a2011-11-22 22:48:5537 }
38
39 protected:
[email protected]00c794a2011-11-22 22:48:5540 MessageLoop message_loop_;
[email protected]988dfc3c2012-01-04 01:10:1141 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
[email protected]00c794a2011-11-22 22:48:5542 MockSignalStrategy signal_strategy_;
[email protected]988dfc3c2012-01-04 01:10:1143 scoped_ptr<LogToServer> log_to_server_;
[email protected]00c794a2011-11-22 22:48:5544};
45
46TEST_F(LogToServerTest, SendNow) {
47 {
48 InSequence s;
[email protected]08128a312012-01-03 21:02:3949 EXPECT_CALL(signal_strategy_, GetLocalJid())
50 .WillRepeatedly(Return("[email protected]/1234"));
[email protected]00c794a2011-11-22 22:48:5551 EXPECT_CALL(signal_strategy_, AddListener(_));
52 EXPECT_CALL(signal_strategy_, GetNextId());
[email protected]02f2de62011-11-23 03:45:1153 EXPECT_CALL(signal_strategy_, SendStanza(_))
54 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
[email protected]00c794a2011-11-22 22:48:5555 EXPECT_CALL(signal_strategy_, RemoveListener(_))
56 .WillOnce(QuitMainMessageLoop(&message_loop_))
57 .RetiresOnSaturation();
58 }
[email protected]988dfc3c2012-01-04 01:10:1159 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
[email protected]00c794a2011-11-22 22:48:5560 log_to_server_->OnClientAuthenticated("[email protected]/5678");
[email protected]988dfc3c2012-01-04 01:10:1161 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
[email protected]00c794a2011-11-22 22:48:5562 message_loop_.Run();
63}
64
65TEST_F(LogToServerTest, SendLater) {
[email protected]988dfc3c2012-01-04 01:10:1166 log_to_server_->OnClientAuthenticated("[email protected]/5678");
[email protected]00c794a2011-11-22 22:48:5567 {
68 InSequence s;
[email protected]08128a312012-01-03 21:02:3969 EXPECT_CALL(signal_strategy_, GetLocalJid())
70 .WillRepeatedly(Return("[email protected]/1234"));
[email protected]00c794a2011-11-22 22:48:5571 EXPECT_CALL(signal_strategy_, AddListener(_));
72 EXPECT_CALL(signal_strategy_, GetNextId());
[email protected]02f2de62011-11-23 03:45:1173 EXPECT_CALL(signal_strategy_, SendStanza(_))
74 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
[email protected]00c794a2011-11-22 22:48:5575 EXPECT_CALL(signal_strategy_, RemoveListener(_))
76 .WillOnce(QuitMainMessageLoop(&message_loop_))
77 .RetiresOnSaturation();
78 }
[email protected]988dfc3c2012-01-04 01:10:1179 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
80 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
[email protected]00c794a2011-11-22 22:48:5581 message_loop_.Run();
82}
83
84TEST_F(LogToServerTest, SendTwoEntriesLater) {
[email protected]988dfc3c2012-01-04 01:10:1185 log_to_server_->OnClientAuthenticated("[email protected]/5678");
86 log_to_server_->OnClientAuthenticated("[email protected]/6789");
[email protected]00c794a2011-11-22 22:48:5587 {
88 InSequence s;
[email protected]08128a312012-01-03 21:02:3989 EXPECT_CALL(signal_strategy_, GetLocalJid())
90 .WillRepeatedly(Return("[email protected]/1234"));
[email protected]00c794a2011-11-22 22:48:5591 EXPECT_CALL(signal_strategy_, AddListener(_));
92 EXPECT_CALL(signal_strategy_, GetNextId());
[email protected]02f2de62011-11-23 03:45:1193 EXPECT_CALL(signal_strategy_, SendStanza(_))
94 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
[email protected]00c794a2011-11-22 22:48:5595 EXPECT_CALL(signal_strategy_, RemoveListener(_))
96 .WillOnce(QuitMainMessageLoop(&message_loop_))
97 .RetiresOnSaturation();
98 }
[email protected]988dfc3c2012-01-04 01:10:1199 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
100 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
[email protected]00c794a2011-11-22 22:48:55101 message_loop_.Run();
102}
103
104} // namespace remoting