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

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

Issue 10413035: [Chromoting] LogToServer correctly handles multiple simultaneous connections. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the ConnectionInfo class. Created 8 years, 7 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/log_to_server.cc ('k') | no next file » | 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/message_loop_proxy.h" 6 #include "base/message_loop_proxy.h"
7 #include "remoting/jingle_glue/mock_objects.h" 7 #include "remoting/jingle_glue/mock_objects.h"
8 #include "remoting/host/log_to_server.h" 8 #include "remoting/host/log_to_server.h"
9 #include "testing/gmock_mutant.h" 9 #include "testing/gmock_mutant.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
13 13
14 using buzz::XmlElement;
15 using buzz::QName;
14 using testing::_; 16 using testing::_;
15 using testing::DeleteArg; 17 using testing::DeleteArg;
16 using testing::InSequence; 18 using testing::InSequence;
17 using testing::Return; 19 using testing::Return;
18 20
19 namespace remoting { 21 namespace remoting {
20 22
21 namespace { 23 namespace {
22 24
23 ACTION_P(QuitMainMessageLoop, message_loop) { 25 ACTION_P(QuitMainMessageLoop, message_loop) {
24 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 26 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
25 } 27 }
26 28
29 const char kJabberClientNamespace[] = "jabber:client";
30 const char kChromotingNamespace[] = "google:remoting";
31 const char kClientJid1[] = "client@domain.com/1234";
32 const char kClientJid2[] = "client@domain.com/5678";
33 const char kHostJid[] = "host@domain.com/1234";
34
35 bool IsLogEntryForConnection(XmlElement* node, const char* connection_type) {
36 return (node->Name() == QName(kChromotingNamespace, "entry") &&
37 node->Attr(QName("", "event-name")) == "session-state" &&
38 node->Attr(QName("", "session-state")) == "connected" &&
39 node->Attr(QName("", "role")) == "host" &&
40 node->Attr(QName("", "mode")) == "me2me" &&
41 node->Attr(QName("", "connection-type")) == connection_type);
42 }
43
44 MATCHER_P(IsClientConnected, connection_type, "") {
45 if (arg->Name() != QName(kJabberClientNamespace, "iq")) {
46 return false;
47 }
48 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement();
49 if (log_stanza->Name() !=QName(kChromotingNamespace, "log")) {
50 return false;
51 }
52 if (log_stanza->NextChild()) {
53 return false;
54 }
55 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement();
56 if (!IsLogEntryForConnection(log_entry, connection_type)) {
57 return false;
58 }
59 if (log_entry->NextChild()) {
60 return false;
61 }
62 return true;
63 }
64
65 MATCHER_P2(IsTwoClientsConnected, connection_type1, connection_type2, "") {
Wez 2012/05/21 22:47:31 nit: AreTwoClientsConnected.
simonmorris 2012/05/24 22:15:27 The matcher is a function of a single parameter, s
66 if (arg->Name() != QName(kJabberClientNamespace, "iq")) {
67 return false;
68 }
69 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement();
70 if (log_stanza->Name() !=QName(kChromotingNamespace, "log")) {
71 return false;
72 }
73 if (log_stanza->NextChild()) {
74 return false;
75 }
76 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement();
77 if (!IsLogEntryForConnection(log_entry, connection_type1)) {
78 return false;
79 }
80 log_entry = log_entry->NextChild()->AsElement();
81 if (!IsLogEntryForConnection(log_entry, connection_type2)) {
82 return false;
83 }
84 if (log_entry->NextChild()) {
85 return false;
86 }
87 return true;
88 }
89
90 bool IsLogEntryForDisconnection(XmlElement* node) {
91 return (node->Name() == QName(kChromotingNamespace, "entry") &&
92 node->Attr(QName("", "event-name")) == "session-state" &&
93 node->Attr(QName("", "session-state")) == "closed" &&
94 node->Attr(QName("", "role")) == "host" &&
95 node->Attr(QName("", "mode")) == "me2me");
96 }
97
98 MATCHER(IsClientDisconnected, "") {
99 if (arg->Name() != QName(kJabberClientNamespace, "iq")) {
100 return false;
101 }
102 buzz::XmlElement* log_stanza = arg->FirstChild()->AsElement();
103 if (log_stanza->Name() !=QName(kChromotingNamespace, "log")) {
104 return false;
105 }
106 if (log_stanza->NextChild()) {
107 return false;
108 }
109 buzz::XmlElement* log_entry = log_stanza->FirstChild()->AsElement();
110 if (!IsLogEntryForDisconnection(log_entry)) {
111 return false;
112 }
113 if (log_entry->NextChild()) {
114 return false;
115 }
116 return true;
117 }
118
27 } // namespace 119 } // namespace
28 120
29 class LogToServerTest : public testing::Test { 121 class LogToServerTest : public testing::Test {
30 public: 122 public:
31 LogToServerTest() {} 123 LogToServerTest() {}
32 virtual void SetUp() OVERRIDE { 124 virtual void SetUp() OVERRIDE {
33 message_loop_proxy_ = base::MessageLoopProxy::current(); 125 message_loop_proxy_ = base::MessageLoopProxy::current();
34 EXPECT_CALL(signal_strategy_, AddListener(_)); 126 EXPECT_CALL(signal_strategy_, AddListener(_));
35 log_to_server_.reset( 127 log_to_server_.reset(
36 new LogToServer(NULL, ServerLogEntry::ME2ME, &signal_strategy_)); 128 new LogToServer(NULL, ServerLogEntry::ME2ME, &signal_strategy_));
37 EXPECT_CALL(signal_strategy_, RemoveListener(_)); 129 EXPECT_CALL(signal_strategy_, RemoveListener(_));
38 } 130 }
39 131
40 protected: 132 protected:
41 MessageLoop message_loop_; 133 MessageLoop message_loop_;
42 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 134 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
43 MockSignalStrategy signal_strategy_; 135 MockSignalStrategy signal_strategy_;
44 scoped_ptr<LogToServer> log_to_server_; 136 scoped_ptr<LogToServer> log_to_server_;
45 }; 137 };
46 138
47 TEST_F(LogToServerTest, SendNow) { 139 TEST_F(LogToServerTest, SendNow) {
48 { 140 {
49 InSequence s; 141 InSequence s;
50 EXPECT_CALL(signal_strategy_, GetLocalJid()) 142 EXPECT_CALL(signal_strategy_, GetLocalJid())
51 .WillRepeatedly(Return("host@domain.com/1234")); 143 .WillRepeatedly(Return(kHostJid));
52 EXPECT_CALL(signal_strategy_, AddListener(_)); 144 EXPECT_CALL(signal_strategy_, AddListener(_));
53 EXPECT_CALL(signal_strategy_, GetNextId()); 145 EXPECT_CALL(signal_strategy_, GetNextId());
54 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)) 146 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct")))
55 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 147 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
56 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 148 EXPECT_CALL(signal_strategy_, RemoveListener(_))
57 .WillOnce(QuitMainMessageLoop(&message_loop_)) 149 .WillOnce(QuitMainMessageLoop(&message_loop_))
58 .RetiresOnSaturation(); 150 .RetiresOnSaturation();
59 } 151 }
60 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 152 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
61 protocol::TransportRoute route; 153 protocol::TransportRoute route;
62 route.type = protocol::TransportRoute::DIRECT; 154 route.type = protocol::TransportRoute::DIRECT;
63 log_to_server_->OnClientRouteChange("client@domain.com/5678", "video", route); 155 log_to_server_->OnClientRouteChange(kClientJid1, "video", route);
64 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); 156 log_to_server_->OnClientAuthenticated(kClientJid1);
65 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 157 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
66 message_loop_.Run(); 158 message_loop_.Run();
67 } 159 }
68 160
69 TEST_F(LogToServerTest, SendLater) { 161 TEST_F(LogToServerTest, SendLater) {
70 protocol::TransportRoute route; 162 protocol::TransportRoute route;
71 route.type = protocol::TransportRoute::DIRECT; 163 route.type = protocol::TransportRoute::DIRECT;
72 log_to_server_->OnClientRouteChange("client@domain.com/5678", "video", route); 164 log_to_server_->OnClientRouteChange(kClientJid1, "video", route);
73 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); 165 log_to_server_->OnClientAuthenticated(kClientJid1);
74 { 166 {
75 InSequence s; 167 InSequence s;
76 EXPECT_CALL(signal_strategy_, GetLocalJid()) 168 EXPECT_CALL(signal_strategy_, GetLocalJid())
77 .WillRepeatedly(Return("host@domain.com/1234")); 169 .WillRepeatedly(Return(kHostJid));
78 EXPECT_CALL(signal_strategy_, AddListener(_)); 170 EXPECT_CALL(signal_strategy_, AddListener(_));
79 EXPECT_CALL(signal_strategy_, GetNextId()); 171 EXPECT_CALL(signal_strategy_, GetNextId());
80 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)) 172 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct")))
81 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 173 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
82 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 174 EXPECT_CALL(signal_strategy_, RemoveListener(_))
83 .WillOnce(QuitMainMessageLoop(&message_loop_)) 175 .WillOnce(QuitMainMessageLoop(&message_loop_))
84 .RetiresOnSaturation(); 176 .RetiresOnSaturation();
85 } 177 }
86 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 178 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
87 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 179 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
88 message_loop_.Run(); 180 message_loop_.Run();
89 } 181 }
90 182
91 TEST_F(LogToServerTest, SendTwoEntriesLater) { 183 TEST_F(LogToServerTest, SendTwoEntriesLater) {
92 protocol::TransportRoute route; 184 protocol::TransportRoute route1;
93 route.type = protocol::TransportRoute::DIRECT; 185 route1.type = protocol::TransportRoute::DIRECT;
94 log_to_server_->OnClientRouteChange("client@domain.com/5678", "video", route); 186 log_to_server_->OnClientRouteChange(kClientJid1, "video", route1);
95 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); 187 log_to_server_->OnClientAuthenticated(kClientJid1);
96 log_to_server_->OnClientAuthenticated("client2@domain.com/6789"); 188 protocol::TransportRoute route2;
189 route2.type = protocol::TransportRoute::STUN;
190 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2);
191 log_to_server_->OnClientAuthenticated(kClientJid2);
97 { 192 {
98 InSequence s; 193 InSequence s;
99 EXPECT_CALL(signal_strategy_, GetLocalJid()) 194 EXPECT_CALL(signal_strategy_, GetLocalJid())
100 .WillRepeatedly(Return("host@domain.com/1234")); 195 .WillRepeatedly(Return(kHostJid));
101 EXPECT_CALL(signal_strategy_, AddListener(_)); 196 EXPECT_CALL(signal_strategy_, AddListener(_));
102 EXPECT_CALL(signal_strategy_, GetNextId()); 197 EXPECT_CALL(signal_strategy_, GetNextId());
103 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)) 198 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
199 IsTwoClientsConnected("direct", "stun")))
104 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 200 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
105 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 201 EXPECT_CALL(signal_strategy_, RemoveListener(_))
106 .WillOnce(QuitMainMessageLoop(&message_loop_)) 202 .WillOnce(QuitMainMessageLoop(&message_loop_))
107 .RetiresOnSaturation(); 203 .RetiresOnSaturation();
108 } 204 }
109 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 205 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
110 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); 206 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
111 message_loop_.Run(); 207 message_loop_.Run();
112 } 208 }
209
210 TEST_F(LogToServerTest, HandleRouteChangeInUnusualOrder) {
211 {
212 InSequence s;
213 EXPECT_CALL(signal_strategy_, GetLocalJid())
214 .WillRepeatedly(Return(kHostJid));
215 EXPECT_CALL(signal_strategy_, AddListener(_));
216 EXPECT_CALL(signal_strategy_, GetNextId());
217 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct")))
218 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
219 EXPECT_CALL(signal_strategy_, GetNextId());
220 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientDisconnected()))
221 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
222 EXPECT_CALL(signal_strategy_, GetNextId());
223 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("stun")))
224 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
225 EXPECT_CALL(signal_strategy_, RemoveListener(_))
226 .WillOnce(QuitMainMessageLoop(&message_loop_))
227 .RetiresOnSaturation();
228 }
229 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
230 protocol::TransportRoute route1;
231 route1.type = protocol::TransportRoute::DIRECT;
232 log_to_server_->OnClientRouteChange(kClientJid1, "video", route1);
233 log_to_server_->OnClientAuthenticated(kClientJid1);
234 protocol::TransportRoute route2;
235 route2.type = protocol::TransportRoute::STUN;
236 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2);
237 log_to_server_->OnClientDisconnected(kClientJid1);
238 log_to_server_->OnClientAuthenticated(kClientJid2);
239 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED);
240 message_loop_.Run();
241 }
113 242
114 } // namespace remoting 243 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/log_to_server.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698