1 // Copyright 2014 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.
5 #include "remoting/signaling/log_to_server.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "remoting/signaling/mock_signal_strategy.h"
10 #include "remoting/signaling/server_log_entry_unittest.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using buzz::XmlElement
;
17 using testing::DeleteArg
;
18 using testing::InSequence
;
19 using testing::Return
;
25 const char kTestBotJid
[] = "remotingunittest@bot.talk.google.com";
26 const char kClientJid
[] = "host@domain.com/1234";
28 MATCHER_P2(IsLogEntry
, key
, value
, "") {
29 XmlElement
* entry
= GetSingleLogEntryFromStanza(arg
);
34 return entry
->Attr(QName(std::string(), key
)) == value
;
39 class LogToServerTest
: public testing::Test
{
42 void SetUp() override
{
43 EXPECT_CALL(signal_strategy_
, AddListener(_
));
44 EXPECT_CALL(signal_strategy_
, RemoveListener(_
));
46 new LogToServer(ServerLogEntry::ME2ME
, &signal_strategy_
, kTestBotJid
));
50 base::MessageLoop message_loop_
;
51 base::RunLoop run_loop_
;
52 MockSignalStrategy signal_strategy_
;
53 scoped_ptr
<LogToServer
> log_to_server_
;
56 TEST_F(LogToServerTest
, LogWhenConnected
) {
59 EXPECT_CALL(signal_strategy_
, GetLocalJid())
60 .WillRepeatedly(Return(kClientJid
));
61 EXPECT_CALL(signal_strategy_
, AddListener(_
));
62 EXPECT_CALL(signal_strategy_
, GetNextId());
63 EXPECT_CALL(signal_strategy_
, SendStanzaPtr(IsLogEntry("a", "1")))
64 .WillOnce(DoAll(DeleteArg
<0>(), Return(true)));
65 EXPECT_CALL(signal_strategy_
, GetNextId());
66 EXPECT_CALL(signal_strategy_
, SendStanzaPtr(IsLogEntry("b", "2")))
67 .WillOnce(DoAll(DeleteArg
<0>(), Return(true)));
68 EXPECT_CALL(signal_strategy_
, RemoveListener(_
))
69 .RetiresOnSaturation();
72 ServerLogEntry entry1
;
73 ServerLogEntry entry2
;
76 log_to_server_
->Log(entry1
);
77 log_to_server_
->OnSignalStrategyStateChange(SignalStrategy::CONNECTED
);
78 log_to_server_
->Log(entry2
);
79 run_loop_
.RunUntilIdle();
82 TEST_F(LogToServerTest
, DontLogWhenDisconnected
) {
83 EXPECT_CALL(signal_strategy_
, GetLocalJid())
84 .WillRepeatedly(Return(kClientJid
));
85 EXPECT_CALL(signal_strategy_
, SendStanzaPtr(_
)).Times(0);
88 entry
.Set("foo", "bar");
89 log_to_server_
->Log(entry
);
90 run_loop_
.RunUntilIdle();
93 } // namespace remoting