Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: remoting/host/host_status_logger_unittest.cc

Issue 320403002: Pull out common code from client and host versions of LogToServer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unittests for LogToServer Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/host_status_logger.cc ('k') | remoting/host/it2me/it2me_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/host_status_logger.h"
6
5 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
6 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
7 #include "remoting/host/host_status_monitor_fake.h" 9 #include "remoting/host/host_status_monitor_fake.h"
8 #include "remoting/host/log_to_server.h"
9 #include "remoting/jingle_glue/mock_objects.h" 10 #include "remoting/jingle_glue/mock_objects.h"
10 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gmock_mutant.h" 12 #include "testing/gmock_mutant.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
14 15
15 using buzz::XmlElement; 16 using buzz::XmlElement;
16 using buzz::QName; 17 using buzz::QName;
17 using testing::_; 18 using testing::_;
18 using testing::DeleteArg; 19 using testing::DeleteArg;
(...skipping 23 matching lines...) Expand all
42 node->Attr(QName(std::string(), "mode")) == "me2me" && 43 node->Attr(QName(std::string(), "mode")) == "me2me" &&
43 node->Attr(QName(std::string(), "connection-type")) == 44 node->Attr(QName(std::string(), "connection-type")) ==
44 connection_type); 45 connection_type);
45 } 46 }
46 47
47 MATCHER_P(IsClientConnected, connection_type, "") { 48 MATCHER_P(IsClientConnected, connection_type, "") {
48 if (arg->Name() != QName(kJabberClientNamespace, "iq")) { 49 if (arg->Name() != QName(kJabberClientNamespace, "iq")) {
49 return false; 50 return false;
50 } 51 }
51 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement(); 52 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement();
52 if (log_stanza->Name() !=QName(kChromotingNamespace, "log")) { 53 if (log_stanza->Name() != QName(kChromotingNamespace, "log")) {
53 return false; 54 return false;
54 } 55 }
55 if (log_stanza->NextChild()) { 56 if (log_stanza->NextChild()) {
56 return false; 57 return false;
57 } 58 }
58 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement(); 59 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement();
59 if (!IsLogEntryForConnection(log_entry, connection_type)) { 60 if (!IsLogEntryForConnection(log_entry, connection_type)) {
60 return false; 61 return false;
61 } 62 }
62 if (log_entry->NextChild()) { 63 if (log_entry->NextChild()) {
63 return false; 64 return false;
64 } 65 }
65 return true; 66 return true;
66 } 67 }
67 68
68 MATCHER_P2(IsTwoClientsConnected, connection_type1, connection_type2, "") { 69 MATCHER_P2(IsTwoClientsConnected, connection_type1, connection_type2, "") {
69 if (arg->Name() != QName(kJabberClientNamespace, "iq")) { 70 if (arg->Name() != QName(kJabberClientNamespace, "iq")) {
70 return false; 71 return false;
71 } 72 }
72 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement(); 73 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement();
73 if (log_stanza->Name() !=QName(kChromotingNamespace, "log")) { 74 if (log_stanza->Name() != QName(kChromotingNamespace, "log")) {
74 return false; 75 return false;
75 } 76 }
76 if (log_stanza->NextChild()) { 77 if (log_stanza->NextChild()) {
77 return false; 78 return false;
78 } 79 }
79 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement(); 80 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement();
80 if (!IsLogEntryForConnection(log_entry, connection_type1)) { 81 if (!IsLogEntryForConnection(log_entry, connection_type1)) {
81 return false; 82 return false;
82 } 83 }
83 log_entry = log_entry->NextChild()->AsElement(); 84 log_entry = log_entry->NextChild()->AsElement();
(...skipping 30 matching lines...) Expand all
114 return false; 115 return false;
115 } 116 }
116 if (log_entry->NextChild()) { 117 if (log_entry->NextChild()) {
117 return false; 118 return false;
118 } 119 }
119 return true; 120 return true;
120 } 121 }
121 122
122 } // namespace 123 } // namespace
123 124
124 class LogToServerTest : public testing::Test { 125 class HostStatusLoggerTest : public testing::Test {
125 public: 126 public:
126 LogToServerTest() {} 127 HostStatusLoggerTest() {}
127 virtual void SetUp() OVERRIDE { 128 virtual void SetUp() OVERRIDE {
128 message_loop_proxy_ = base::MessageLoopProxy::current(); 129 message_loop_proxy_ = base::MessageLoopProxy::current();
129 EXPECT_CALL(signal_strategy_, AddListener(_)); 130 EXPECT_CALL(signal_strategy_, AddListener(_));
130 log_to_server_.reset( 131 host_status_logger_.reset(
131 new LogToServer(host_status_monitor_.AsWeakPtr(), 132 new HostStatusLogger(host_status_monitor_.AsWeakPtr(),
132 ServerLogEntry::ME2ME, 133 ServerLogEntry::ME2ME,
133 &signal_strategy_, 134 &signal_strategy_,
134 kTestBotJid)); 135 kTestBotJid));
135 EXPECT_CALL(signal_strategy_, RemoveListener(_)); 136 EXPECT_CALL(signal_strategy_, RemoveListener(_));
136 } 137 }
137 138
138 protected: 139 protected:
139 base::MessageLoop message_loop_; 140 base::MessageLoop message_loop_;
140 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 141 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
141 MockSignalStrategy signal_strategy_; 142 MockSignalStrategy signal_strategy_;
142 scoped_ptr<LogToServer> log_to_server_; 143 scoped_ptr<HostStatusLogger> host_status_logger_;
143 HostStatusMonitorFake host_status_monitor_; 144 HostStatusMonitorFake host_status_monitor_;
144 }; 145 };
145 146
146 TEST_F(LogToServerTest, SendNow) { 147 TEST_F(HostStatusLoggerTest, SendNow) {
147 { 148 {
148 InSequence s; 149 InSequence s;
149 EXPECT_CALL(signal_strategy_, GetLocalJid()) 150 EXPECT_CALL(signal_strategy_, GetLocalJid())
150 .WillRepeatedly(Return(kHostJid)); 151 .WillRepeatedly(Return(kHostJid));
151 EXPECT_CALL(signal_strategy_, AddListener(_)); 152 EXPECT_CALL(signal_strategy_, AddListener(_));
152 EXPECT_CALL(signal_strategy_, GetNextId()); 153 EXPECT_CALL(signal_strategy_, GetNextId());
153 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) 154 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct")))
154 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 155 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
155 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 156 EXPECT_CALL(signal_strategy_, RemoveListener(_))
156 .WillOnce(QuitMainMessageLoop(&message_loop_)) 157 .WillOnce(QuitMainMessageLoop(&message_loop_))
157 .RetiresOnSaturation(); 158 .RetiresOnSaturation();
158 } 159 }
159 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 160 host_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
160 protocol::TransportRoute route; 161 protocol::TransportRoute route;
161 route.type = protocol::TransportRoute::DIRECT; 162 route.type = protocol::TransportRoute::DIRECT;
162 log_to_server_->OnClientRouteChange(kClientJid1, "video", route); 163 host_status_logger_->OnClientRouteChange(kClientJid1, "video", route);
163 log_to_server_->OnClientAuthenticated(kClientJid1); 164 host_status_logger_->OnClientAuthenticated(kClientJid1);
164 log_to_server_->OnClientConnected(kClientJid1); 165 host_status_logger_->OnClientConnected(kClientJid1);
165 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 166 host_status_logger_->SetSignalingStateForTest(
167 SignalStrategy::DISCONNECTED);
166 message_loop_.Run(); 168 message_loop_.Run();
167 } 169 }
168 170
169 TEST_F(LogToServerTest, SendLater) { 171 TEST_F(HostStatusLoggerTest, SendLater) {
170 protocol::TransportRoute route; 172 protocol::TransportRoute route;
171 route.type = protocol::TransportRoute::DIRECT; 173 route.type = protocol::TransportRoute::DIRECT;
172 log_to_server_->OnClientRouteChange(kClientJid1, "video", route); 174 host_status_logger_->OnClientRouteChange(kClientJid1, "video", route);
173 log_to_server_->OnClientAuthenticated(kClientJid1); 175 host_status_logger_->OnClientAuthenticated(kClientJid1);
174 log_to_server_->OnClientConnected(kClientJid1); 176 host_status_logger_->OnClientConnected(kClientJid1);
175 { 177 {
176 InSequence s; 178 InSequence s;
177 EXPECT_CALL(signal_strategy_, GetLocalJid()) 179 EXPECT_CALL(signal_strategy_, GetLocalJid())
178 .WillRepeatedly(Return(kHostJid)); 180 .WillRepeatedly(Return(kHostJid));
179 EXPECT_CALL(signal_strategy_, AddListener(_)); 181 EXPECT_CALL(signal_strategy_, AddListener(_));
180 EXPECT_CALL(signal_strategy_, GetNextId()); 182 EXPECT_CALL(signal_strategy_, GetNextId());
181 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) 183 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct")))
182 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 184 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
183 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 185 EXPECT_CALL(signal_strategy_, RemoveListener(_))
184 .WillOnce(QuitMainMessageLoop(&message_loop_)) 186 .WillOnce(QuitMainMessageLoop(&message_loop_))
185 .RetiresOnSaturation(); 187 .RetiresOnSaturation();
186 } 188 }
187 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 189 host_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
188 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 190 host_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
189 message_loop_.Run(); 191 message_loop_.Run();
190 } 192 }
191 193
192 TEST_F(LogToServerTest, SendTwoEntriesLater) { 194 TEST_F(HostStatusLoggerTest, SendTwoEntriesLater) {
193 protocol::TransportRoute route1; 195 protocol::TransportRoute route1;
194 route1.type = protocol::TransportRoute::DIRECT; 196 route1.type = protocol::TransportRoute::DIRECT;
195 log_to_server_->OnClientRouteChange(kClientJid1, "video", route1); 197 host_status_logger_->OnClientRouteChange(kClientJid1, "video", route1);
196 log_to_server_->OnClientAuthenticated(kClientJid1); 198 host_status_logger_->OnClientAuthenticated(kClientJid1);
197 log_to_server_->OnClientConnected(kClientJid1); 199 host_status_logger_->OnClientConnected(kClientJid1);
198 protocol::TransportRoute route2; 200 protocol::TransportRoute route2;
199 route2.type = protocol::TransportRoute::STUN; 201 route2.type = protocol::TransportRoute::STUN;
200 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2); 202 host_status_logger_->OnClientRouteChange(kClientJid2, "video", route2);
201 log_to_server_->OnClientAuthenticated(kClientJid2); 203 host_status_logger_->OnClientAuthenticated(kClientJid2);
202 log_to_server_->OnClientConnected(kClientJid2); 204 host_status_logger_->OnClientConnected(kClientJid2);
203 { 205 {
204 InSequence s; 206 InSequence s;
205 EXPECT_CALL(signal_strategy_, GetLocalJid()) 207 EXPECT_CALL(signal_strategy_, GetLocalJid())
206 .WillRepeatedly(Return(kHostJid)); 208 .WillRepeatedly(Return(kHostJid));
207 EXPECT_CALL(signal_strategy_, AddListener(_)); 209 EXPECT_CALL(signal_strategy_, AddListener(_));
208 EXPECT_CALL(signal_strategy_, GetNextId()); 210 EXPECT_CALL(signal_strategy_, GetNextId());
209 EXPECT_CALL(signal_strategy_, SendStanzaPtr( 211 EXPECT_CALL(signal_strategy_,
210 IsTwoClientsConnected("direct", "stun"))) 212 SendStanzaPtr(IsTwoClientsConnected("direct", "stun")))
211 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 213 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
212 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 214 EXPECT_CALL(signal_strategy_, RemoveListener(_))
213 .WillOnce(QuitMainMessageLoop(&message_loop_)) 215 .WillOnce(QuitMainMessageLoop(&message_loop_))
214 .RetiresOnSaturation(); 216 .RetiresOnSaturation();
215 } 217 }
216 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 218 host_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
217 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 219 host_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
218 message_loop_.Run(); 220 message_loop_.Run();
219 } 221 }
220 222
221 TEST_F(LogToServerTest, HandleRouteChangeInUnusualOrder) { 223 TEST_F(HostStatusLoggerTest, HandleRouteChangeInUnusualOrder) {
222 { 224 {
223 InSequence s; 225 InSequence s;
224 EXPECT_CALL(signal_strategy_, GetLocalJid()) 226 EXPECT_CALL(signal_strategy_, GetLocalJid())
225 .WillRepeatedly(Return(kHostJid)); 227 .WillRepeatedly(Return(kHostJid));
226 EXPECT_CALL(signal_strategy_, AddListener(_)); 228 EXPECT_CALL(signal_strategy_, AddListener(_));
227 EXPECT_CALL(signal_strategy_, GetNextId()); 229 EXPECT_CALL(signal_strategy_, GetNextId());
228 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) 230 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct")))
229 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 231 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
230 EXPECT_CALL(signal_strategy_, GetNextId()); 232 EXPECT_CALL(signal_strategy_, GetNextId());
231 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientDisconnected())) 233 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientDisconnected()))
232 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 234 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
233 EXPECT_CALL(signal_strategy_, GetNextId()); 235 EXPECT_CALL(signal_strategy_, GetNextId());
234 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("stun"))) 236 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("stun")))
235 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 237 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
236 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 238 EXPECT_CALL(signal_strategy_, RemoveListener(_))
237 .WillOnce(QuitMainMessageLoop(&message_loop_)) 239 .WillOnce(QuitMainMessageLoop(&message_loop_))
238 .RetiresOnSaturation(); 240 .RetiresOnSaturation();
239 } 241 }
240 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 242 host_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
241 protocol::TransportRoute route1; 243 protocol::TransportRoute route1;
242 route1.type = protocol::TransportRoute::DIRECT; 244 route1.type = protocol::TransportRoute::DIRECT;
243 log_to_server_->OnClientRouteChange(kClientJid1, "video", route1); 245 host_status_logger_->OnClientRouteChange(kClientJid1, "video", route1);
244 log_to_server_->OnClientAuthenticated(kClientJid1); 246 host_status_logger_->OnClientAuthenticated(kClientJid1);
245 log_to_server_->OnClientConnected(kClientJid1); 247 host_status_logger_->OnClientConnected(kClientJid1);
246 protocol::TransportRoute route2; 248 protocol::TransportRoute route2;
247 route2.type = protocol::TransportRoute::STUN; 249 route2.type = protocol::TransportRoute::STUN;
248 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2); 250 host_status_logger_->OnClientRouteChange(kClientJid2, "video", route2);
249 log_to_server_->OnClientDisconnected(kClientJid1); 251 host_status_logger_->OnClientDisconnected(kClientJid1);
250 log_to_server_->OnClientAuthenticated(kClientJid2); 252 host_status_logger_->OnClientAuthenticated(kClientJid2);
251 log_to_server_->OnClientConnected(kClientJid2); 253 host_status_logger_->OnClientConnected(kClientJid2);
252 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 254 host_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
253 message_loop_.Run(); 255 message_loop_.Run();
254 } 256 }
255 257
256 } // namespace remoting 258 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_status_logger.cc ('k') | remoting/host/it2me/it2me_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698