| OLD | NEW |
| 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/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
| 7 #include "remoting/host/host_status_monitor_fake.h" | 7 #include "remoting/host/host_status_monitor_fake.h" |
| 8 #include "remoting/host/log_to_server.h" | 8 #include "remoting/host/log_to_server_host.h" |
| 9 #include "remoting/jingle_glue/mock_objects.h" | 9 #include "remoting/jingle_glue/mock_objects.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gmock_mutant.h" | 11 #include "testing/gmock_mutant.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 14 | 14 |
| 15 using buzz::XmlElement; | 15 using buzz::XmlElement; |
| 16 using buzz::QName; | 16 using buzz::QName; |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::DeleteArg; | 18 using testing::DeleteArg; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return false; | 114 return false; |
| 115 } | 115 } |
| 116 if (log_entry->NextChild()) { | 116 if (log_entry->NextChild()) { |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace | 122 } // namespace |
| 123 | 123 |
| 124 class LogToServerTest : public testing::Test { | 124 class LogToServerHostTest : public testing::Test { |
| 125 public: | 125 public: |
| 126 LogToServerTest() {} | 126 LogToServerHostTest() {} |
| 127 virtual void SetUp() OVERRIDE { | 127 virtual void SetUp() OVERRIDE { |
| 128 message_loop_proxy_ = base::MessageLoopProxy::current(); | 128 message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 129 EXPECT_CALL(signal_strategy_, AddListener(_)); | 129 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 130 log_to_server_.reset( | 130 log_to_server_.reset( |
| 131 new LogToServer(host_status_monitor_.AsWeakPtr(), | 131 new LogToServerHost(host_status_monitor_.AsWeakPtr(), |
| 132 ServerLogEntry::ME2ME, | 132 ServerLogEntry::ME2ME, |
| 133 &signal_strategy_, | 133 &signal_strategy_, |
| 134 kTestBotJid)); | 134 kTestBotJid)); |
| 135 EXPECT_CALL(signal_strategy_, RemoveListener(_)); | 135 EXPECT_CALL(signal_strategy_, RemoveListener(_)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 protected: | 138 protected: |
| 139 base::MessageLoop message_loop_; | 139 base::MessageLoop message_loop_; |
| 140 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 140 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 141 MockSignalStrategy signal_strategy_; | 141 MockSignalStrategy signal_strategy_; |
| 142 scoped_ptr<LogToServer> log_to_server_; | 142 scoped_ptr<LogToServerHost> log_to_server_; |
| 143 HostStatusMonitorFake host_status_monitor_; | 143 HostStatusMonitorFake host_status_monitor_; |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 TEST_F(LogToServerTest, SendNow) { | 146 TEST_F(LogToServerHostTest, SendNow) { |
| 147 { | 147 { |
| 148 InSequence s; | 148 InSequence s; |
| 149 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 149 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 150 .WillRepeatedly(Return(kHostJid)); | 150 .WillRepeatedly(Return(kHostJid)); |
| 151 EXPECT_CALL(signal_strategy_, AddListener(_)); | 151 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 152 EXPECT_CALL(signal_strategy_, GetNextId()); | 152 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 153 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) | 153 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) |
| 154 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 154 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 155 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 155 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 156 .WillOnce(QuitMainMessageLoop(&message_loop_)) | 156 .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| 157 .RetiresOnSaturation(); | 157 .RetiresOnSaturation(); |
| 158 } | 158 } |
| 159 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); | 159 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 160 protocol::TransportRoute route; | 160 protocol::TransportRoute route; |
| 161 route.type = protocol::TransportRoute::DIRECT; | 161 route.type = protocol::TransportRoute::DIRECT; |
| 162 log_to_server_->OnClientRouteChange(kClientJid1, "video", route); | 162 log_to_server_->OnClientRouteChange(kClientJid1, "video", route); |
| 163 log_to_server_->OnClientAuthenticated(kClientJid1); | 163 log_to_server_->OnClientAuthenticated(kClientJid1); |
| 164 log_to_server_->OnClientConnected(kClientJid1); | 164 log_to_server_->OnClientConnected(kClientJid1); |
| 165 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); | 165 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
| 166 message_loop_.Run(); | 166 message_loop_.Run(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(LogToServerTest, SendLater) { | 169 TEST_F(LogToServerHostTest, SendLater) { |
| 170 protocol::TransportRoute route; | 170 protocol::TransportRoute route; |
| 171 route.type = protocol::TransportRoute::DIRECT; | 171 route.type = protocol::TransportRoute::DIRECT; |
| 172 log_to_server_->OnClientRouteChange(kClientJid1, "video", route); | 172 log_to_server_->OnClientRouteChange(kClientJid1, "video", route); |
| 173 log_to_server_->OnClientAuthenticated(kClientJid1); | 173 log_to_server_->OnClientAuthenticated(kClientJid1); |
| 174 log_to_server_->OnClientConnected(kClientJid1); | 174 log_to_server_->OnClientConnected(kClientJid1); |
| 175 { | 175 { |
| 176 InSequence s; | 176 InSequence s; |
| 177 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 177 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 178 .WillRepeatedly(Return(kHostJid)); | 178 .WillRepeatedly(Return(kHostJid)); |
| 179 EXPECT_CALL(signal_strategy_, AddListener(_)); | 179 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 180 EXPECT_CALL(signal_strategy_, GetNextId()); | 180 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 181 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) | 181 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) |
| 182 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 182 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 183 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 183 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 184 .WillOnce(QuitMainMessageLoop(&message_loop_)) | 184 .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| 185 .RetiresOnSaturation(); | 185 .RetiresOnSaturation(); |
| 186 } | 186 } |
| 187 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); | 187 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 188 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); | 188 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
| 189 message_loop_.Run(); | 189 message_loop_.Run(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(LogToServerTest, SendTwoEntriesLater) { | 192 TEST_F(LogToServerHostTest, SendTwoEntriesLater) { |
| 193 protocol::TransportRoute route1; | 193 protocol::TransportRoute route1; |
| 194 route1.type = protocol::TransportRoute::DIRECT; | 194 route1.type = protocol::TransportRoute::DIRECT; |
| 195 log_to_server_->OnClientRouteChange(kClientJid1, "video", route1); | 195 log_to_server_->OnClientRouteChange(kClientJid1, "video", route1); |
| 196 log_to_server_->OnClientAuthenticated(kClientJid1); | 196 log_to_server_->OnClientAuthenticated(kClientJid1); |
| 197 log_to_server_->OnClientConnected(kClientJid1); | 197 log_to_server_->OnClientConnected(kClientJid1); |
| 198 protocol::TransportRoute route2; | 198 protocol::TransportRoute route2; |
| 199 route2.type = protocol::TransportRoute::STUN; | 199 route2.type = protocol::TransportRoute::STUN; |
| 200 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2); | 200 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2); |
| 201 log_to_server_->OnClientAuthenticated(kClientJid2); | 201 log_to_server_->OnClientAuthenticated(kClientJid2); |
| 202 log_to_server_->OnClientConnected(kClientJid2); | 202 log_to_server_->OnClientConnected(kClientJid2); |
| 203 { | 203 { |
| 204 InSequence s; | 204 InSequence s; |
| 205 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 205 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 206 .WillRepeatedly(Return(kHostJid)); | 206 .WillRepeatedly(Return(kHostJid)); |
| 207 EXPECT_CALL(signal_strategy_, AddListener(_)); | 207 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 208 EXPECT_CALL(signal_strategy_, GetNextId()); | 208 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 209 EXPECT_CALL(signal_strategy_, SendStanzaPtr( | 209 EXPECT_CALL(signal_strategy_, SendStanzaPtr( |
| 210 IsTwoClientsConnected("direct", "stun"))) | 210 IsTwoClientsConnected("direct", "stun"))) |
| 211 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 211 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 212 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 212 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 213 .WillOnce(QuitMainMessageLoop(&message_loop_)) | 213 .WillOnce(QuitMainMessageLoop(&message_loop_)) |
| 214 .RetiresOnSaturation(); | 214 .RetiresOnSaturation(); |
| 215 } | 215 } |
| 216 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); | 216 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 217 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); | 217 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
| 218 message_loop_.Run(); | 218 message_loop_.Run(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST_F(LogToServerTest, HandleRouteChangeInUnusualOrder) { | 221 TEST_F(LogToServerHostTest, HandleRouteChangeInUnusualOrder) { |
| 222 { | 222 { |
| 223 InSequence s; | 223 InSequence s; |
| 224 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 224 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 225 .WillRepeatedly(Return(kHostJid)); | 225 .WillRepeatedly(Return(kHostJid)); |
| 226 EXPECT_CALL(signal_strategy_, AddListener(_)); | 226 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 227 EXPECT_CALL(signal_strategy_, GetNextId()); | 227 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 228 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) | 228 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientConnected("direct"))) |
| 229 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 229 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 230 EXPECT_CALL(signal_strategy_, GetNextId()); | 230 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 231 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientDisconnected())) | 231 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsClientDisconnected())) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 247 route2.type = protocol::TransportRoute::STUN; | 247 route2.type = protocol::TransportRoute::STUN; |
| 248 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2); | 248 log_to_server_->OnClientRouteChange(kClientJid2, "video", route2); |
| 249 log_to_server_->OnClientDisconnected(kClientJid1); | 249 log_to_server_->OnClientDisconnected(kClientJid1); |
| 250 log_to_server_->OnClientAuthenticated(kClientJid2); | 250 log_to_server_->OnClientAuthenticated(kClientJid2); |
| 251 log_to_server_->OnClientConnected(kClientJid2); | 251 log_to_server_->OnClientConnected(kClientJid2); |
| 252 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); | 252 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
| 253 message_loop_.Run(); | 253 message_loop_.Run(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace remoting | 256 } // namespace remoting |
| OLD | NEW |