Roll src/third_party/WebKit 787a07c:716df21 (svn 201034:201036)
[chromium-blink-merge.git] / remoting / signaling / log_to_server_unittest.cc
blob494d3077e3e9cab46414ea962dbcf6e7def70527
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;
15 using buzz::QName;
16 using testing::_;
17 using testing::DeleteArg;
18 using testing::InSequence;
19 using testing::Return;
21 namespace remoting {
23 namespace {
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);
30 if (!entry) {
31 return false;
34 return entry->Attr(QName(std::string(), key)) == value;
37 } // namespace
39 class LogToServerTest : public testing::Test {
40 public:
41 LogToServerTest() {}
42 void SetUp() override {
43 EXPECT_CALL(signal_strategy_, AddListener(_));
44 EXPECT_CALL(signal_strategy_, RemoveListener(_));
45 log_to_server_.reset(
46 new LogToServer(ServerLogEntry::ME2ME, &signal_strategy_, kTestBotJid));
49 protected:
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) {
58 InSequence s;
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;
74 entry1.Set("a", "1");
75 entry2.Set("b", "2");
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);
87 ServerLogEntry entry;
88 entry.Set("foo", "bar");
89 log_to_server_->Log(entry);
90 run_loop_.RunUntilIdle();
93 } // namespace remoting