1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Copyright 2014 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 "remoting/signaling/log_to_server.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "remoting/signaling/mock_signal_strategy.h"
#include "remoting/signaling/server_log_entry_unittest.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using buzz::XmlElement;
using buzz::QName;
using testing::_;
using testing::DeleteArg;
using testing::InSequence;
using testing::Return;
namespace remoting {
namespace {
const char kTestBotJid[] = "remotingunittest@bot.talk.google.com";
const char kClientJid[] = "host@domain.com/1234";
MATCHER_P2(IsLogEntry, key, value, "") {
XmlElement* entry = GetSingleLogEntryFromStanza(arg);
if (!entry) {
return false;
}
return entry->Attr(QName(std::string(), key)) == value;
}
} // namespace
class LogToServerTest : public testing::Test {
public:
LogToServerTest() {}
void SetUp() override {
EXPECT_CALL(signal_strategy_, AddListener(_));
EXPECT_CALL(signal_strategy_, RemoveListener(_));
log_to_server_.reset(
new LogToServer(ServerLogEntry::ME2ME, &signal_strategy_, kTestBotJid));
}
protected:
base::MessageLoop message_loop_;
base::RunLoop run_loop_;
MockSignalStrategy signal_strategy_;
scoped_ptr<LogToServer> log_to_server_;
};
TEST_F(LogToServerTest, LogWhenConnected) {
{
InSequence s;
EXPECT_CALL(signal_strategy_, GetLocalJid())
.WillRepeatedly(Return(kClientJid));
EXPECT_CALL(signal_strategy_, AddListener(_));
EXPECT_CALL(signal_strategy_, GetNextId());
EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsLogEntry("a", "1")))
.WillOnce(DoAll(DeleteArg<0>(), Return(true)));
EXPECT_CALL(signal_strategy_, GetNextId());
EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsLogEntry("b", "2")))
.WillOnce(DoAll(DeleteArg<0>(), Return(true)));
EXPECT_CALL(signal_strategy_, RemoveListener(_))
.RetiresOnSaturation();
}
ServerLogEntry entry1;
ServerLogEntry entry2;
entry1.Set("a", "1");
entry2.Set("b", "2");
log_to_server_->Log(entry1);
log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
log_to_server_->Log(entry2);
run_loop_.RunUntilIdle();
}
TEST_F(LogToServerTest, DontLogWhenDisconnected) {
EXPECT_CALL(signal_strategy_, GetLocalJid())
.WillRepeatedly(Return(kClientJid));
EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)).Times(0);
ServerLogEntry entry;
entry.Set("foo", "bar");
log_to_server_->Log(entry);
run_loop_.RunUntilIdle();
}
} // namespace remoting
|