OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "remoting/jingle_glue/log_to_server.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 #include "base/run_loop.h" | |
9 #include "remoting/jingle_glue/mock_objects.h" | |
10 #include "remoting/jingle_glue/server_log_entry_unittest.h" | |
11 #include "testing/gmock/include/gmock/gmock.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 using buzz::XmlElement; | |
15 using buzz::QName; | |
16 using testing::_; | |
17 using testing::DeleteArg; | |
18 using testing::InSequence; | |
19 using testing::Return; | |
20 | |
21 namespace remoting { | |
22 | |
23 namespace { | |
24 | |
25 const char kTestBotJid[] = "remotingunittest@bot.talk.google.com"; | |
26 const char kClientJid[] = "host@domain.com/1234"; | |
27 | |
28 MATCHER_P2(IsLogEntry, key, value, "") { | |
29 XmlElement* entry = GetSingleLogEntryFromStanza(arg); | |
30 if (!entry) { | |
31 return false; | |
32 } | |
33 | |
34 return entry->Attr(QName(std::string(), key)) == value; | |
35 } | |
36 | |
37 } // namespace | |
38 | |
39 class LogToServerTest : public testing::Test { | |
40 public: | |
41 LogToServerTest() {} | |
42 virtual 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)); | |
47 } | |
48 | |
49 protected: | |
50 base::MessageLoop message_loop_; | |
51 base::RunLoop run_loop_; | |
52 MockSignalStrategy signal_strategy_; | |
53 scoped_ptr<LogToServer> log_to_server_; | |
54 }; | |
55 | |
56 TEST_F(LogToServerTest, LogWhenConnected) { | |
57 { | |
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(); | |
70 } | |
71 | |
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(); | |
80 } | |
81 | |
82 TEST_F(LogToServerTest, DontLogWhenDisconnected) { | |
83 EXPECT_CALL(signal_strategy_, GetLocalJid()) | |
84 .WillRepeatedly(Return(kClientJid)); | |
85 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)).Times(0); | |
86 | |
87 ServerLogEntry entry; | |
88 entry.Set("foo", "bar"); | |
89 log_to_server_->Log(entry); | |
90 run_loop_.RunUntilIdle(); | |
91 } | |
92 | |
93 } // namespace remoting | |
OLD | NEW |