Chromium Code Reviews| 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 "remoting/host/heartbeat_sender.h" | 5 #include "remoting/host/heartbeat_sender.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
| 14 #include "remoting/host/host_key_pair.h" | |
| 15 #include "remoting/host/test_key_pair.h" | |
| 16 #include "remoting/jingle_glue/iq_sender.h" | 14 #include "remoting/jingle_glue/iq_sender.h" |
| 17 #include "remoting/jingle_glue/mock_objects.h" | 15 #include "remoting/jingle_glue/mock_objects.h" |
| 16 #include "remoting/protocol/key_pair.h" | |
| 17 #include "remoting/protocol/test_key_pair.h" | |
|
Sergey Ulanov
2013/02/26 00:14:13
Looks like you forgot to add this file in the CL.
rmsousa
2013/02/26 02:38:52
Done.
| |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 20 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 21 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 21 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
| 22 | 22 |
| 23 using buzz::QName; | 23 using buzz::QName; |
| 24 using buzz::XmlElement; | 24 using buzz::XmlElement; |
| 25 | 25 |
| 26 using testing::_; | 26 using testing::_; |
| 27 using testing::DeleteArg; | 27 using testing::DeleteArg; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 51 class HeartbeatSenderTest | 51 class HeartbeatSenderTest |
| 52 : public testing::Test, | 52 : public testing::Test, |
| 53 public HeartbeatSender::Listener { | 53 public HeartbeatSender::Listener { |
| 54 protected: | 54 protected: |
| 55 // Overridden from HeartbeatSender::Listener | 55 // Overridden from HeartbeatSender::Listener |
| 56 virtual void OnUnknownHostIdError() OVERRIDE { | 56 virtual void OnUnknownHostIdError() OVERRIDE { |
| 57 NOTREACHED(); | 57 NOTREACHED(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual void SetUp() OVERRIDE { | 60 virtual void SetUp() OVERRIDE { |
| 61 ASSERT_TRUE(key_pair_.LoadFromString(kTestHostKeyPair)); | 61 ASSERT_TRUE(key_pair_.LoadFromString(protocol::kTestHostKeyPair)); |
| 62 | 62 |
| 63 EXPECT_CALL(signal_strategy_, GetState()) | 63 EXPECT_CALL(signal_strategy_, GetState()) |
| 64 .WillOnce(Return(SignalStrategy::DISCONNECTED)); | 64 .WillOnce(Return(SignalStrategy::DISCONNECTED)); |
| 65 EXPECT_CALL(signal_strategy_, AddListener(NotNull())) | 65 EXPECT_CALL(signal_strategy_, AddListener(NotNull())) |
| 66 .WillRepeatedly(AddListener(&signal_strategy_listeners_)); | 66 .WillRepeatedly(AddListener(&signal_strategy_listeners_)); |
| 67 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull())) | 67 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull())) |
| 68 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); | 68 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); |
| 69 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 69 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 70 .WillRepeatedly(Return(kTestJid)); | 70 .WillRepeatedly(Return(kTestJid)); |
| 71 | 71 |
| 72 heartbeat_sender_.reset(new HeartbeatSender( | 72 heartbeat_sender_.reset(new HeartbeatSender( |
| 73 this, kHostId, &signal_strategy_, &key_pair_, kTestBotJid)); | 73 this, kHostId, &signal_strategy_, &key_pair_, kTestBotJid)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual void TearDown() OVERRIDE { | 76 virtual void TearDown() OVERRIDE { |
| 77 heartbeat_sender_.reset(); | 77 heartbeat_sender_.reset(); |
| 78 EXPECT_TRUE(signal_strategy_listeners_.empty()); | 78 EXPECT_TRUE(signal_strategy_listeners_.empty()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ValidateHeartbeatStanza(XmlElement* stanza, | 81 void ValidateHeartbeatStanza(XmlElement* stanza, |
| 82 const char* expectedSequenceId); | 82 const char* expectedSequenceId); |
| 83 | 83 |
| 84 MessageLoop message_loop_; | 84 MessageLoop message_loop_; |
| 85 MockSignalStrategy signal_strategy_; | 85 MockSignalStrategy signal_strategy_; |
| 86 std::set<SignalStrategy::Listener*> signal_strategy_listeners_; | 86 std::set<SignalStrategy::Listener*> signal_strategy_listeners_; |
| 87 HostKeyPair key_pair_; | 87 protocol::KeyPair key_pair_; |
| 88 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 88 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 // Call Start() followed by Stop(), and make sure a valid heartbeat is sent. | 91 // Call Start() followed by Stop(), and make sure a valid heartbeat is sent. |
| 92 TEST_F(HeartbeatSenderTest, DoSendStanza) { | 92 TEST_F(HeartbeatSenderTest, DoSendStanza) { |
| 93 XmlElement* sent_iq = NULL; | 93 XmlElement* sent_iq = NULL; |
| 94 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 94 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 95 .WillRepeatedly(Return(kTestJid)); | 95 .WillRepeatedly(Return(kTestJid)); |
| 96 EXPECT_CALL(signal_strategy_, GetNextId()) | 96 EXPECT_CALL(signal_strategy_, GetNextId()) |
| 97 .WillOnce(Return(kStanzaId)); | 97 .WillOnce(Return(kStanzaId)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 EXPECT_EQ(expectedSequenceId, heartbeat_stanza->Attr( | 229 EXPECT_EQ(expectedSequenceId, heartbeat_stanza->Attr( |
| 230 buzz::QName(kChromotingXmlNamespace, "sequence-id"))); | 230 buzz::QName(kChromotingXmlNamespace, "sequence-id"))); |
| 231 EXPECT_EQ(std::string(kHostId), | 231 EXPECT_EQ(std::string(kHostId), |
| 232 heartbeat_stanza->Attr(QName(kChromotingXmlNamespace, "hostid"))); | 232 heartbeat_stanza->Attr(QName(kChromotingXmlNamespace, "hostid"))); |
| 233 | 233 |
| 234 QName signature_tag(kChromotingXmlNamespace, "signature"); | 234 QName signature_tag(kChromotingXmlNamespace, "signature"); |
| 235 XmlElement* signature = heartbeat_stanza->FirstNamed(signature_tag); | 235 XmlElement* signature = heartbeat_stanza->FirstNamed(signature_tag); |
| 236 ASSERT_TRUE(signature != NULL); | 236 ASSERT_TRUE(signature != NULL); |
| 237 EXPECT_TRUE(heartbeat_stanza->NextNamed(signature_tag) == NULL); | 237 EXPECT_TRUE(heartbeat_stanza->NextNamed(signature_tag) == NULL); |
| 238 | 238 |
| 239 HostKeyPair key_pair; | 239 protocol::KeyPair key_pair; |
| 240 key_pair.LoadFromString(kTestHostKeyPair); | 240 key_pair.LoadFromString(protocol::kTestHostKeyPair); |
| 241 std::string expected_signature = | 241 std::string expected_signature = |
| 242 key_pair.GetSignature(std::string(kTestJid) + ' ' + expectedSequenceId); | 242 key_pair.GetSignature(std::string(kTestJid) + ' ' + expectedSequenceId); |
| 243 EXPECT_EQ(expected_signature, signature->BodyText()); | 243 EXPECT_EQ(expected_signature, signature->BodyText()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace remoting | 246 } // namespace remoting |
| OLD | NEW |