| 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/register_support_host_request.h" | 5 #include "remoting/host/register_support_host_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 13 #include "remoting/host/host_key_pair.h" | |
| 14 #include "remoting/host/in_memory_host_config.h" | 13 #include "remoting/host/in_memory_host_config.h" |
| 15 #include "remoting/host/test_key_pair.h" | 14 #include "remoting/host/test_key_pair.h" |
| 16 #include "remoting/jingle_glue/iq_sender.h" | 15 #include "remoting/jingle_glue/iq_sender.h" |
| 17 #include "remoting/jingle_glue/mock_objects.h" | 16 #include "remoting/jingle_glue/mock_objects.h" |
| 17 #include "remoting/protocol/key_pair.h" |
| 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::Invoke; | 27 using testing::Invoke; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 .WillRepeatedly(AddListener(&signal_strategy_listeners_)); | 64 .WillRepeatedly(AddListener(&signal_strategy_listeners_)); |
| 65 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull())) | 65 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull())) |
| 66 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); | 66 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); |
| 67 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 67 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 68 .WillRepeatedly(Return(kTestJid)); | 68 .WillRepeatedly(Return(kTestJid)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 MessageLoop message_loop_; | 71 MessageLoop message_loop_; |
| 72 MockSignalStrategy signal_strategy_; | 72 MockSignalStrategy signal_strategy_; |
| 73 ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; | 73 ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; |
| 74 HostKeyPair key_pair_; | 74 protocol::KeyPair key_pair_; |
| 75 MockCallback callback_; | 75 MockCallback callback_; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 TEST_F(RegisterSupportHostRequestTest, Send) { | 78 TEST_F(RegisterSupportHostRequestTest, Send) { |
| 79 // |iq_request| is freed by RegisterSupportHostRequest. | 79 // |iq_request| is freed by RegisterSupportHostRequest. |
| 80 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); | 80 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); |
| 81 | 81 |
| 82 scoped_ptr<RegisterSupportHostRequest> request( | 82 scoped_ptr<RegisterSupportHostRequest> request( |
| 83 new RegisterSupportHostRequest(&signal_strategy_, &key_pair_, | 83 new RegisterSupportHostRequest(&signal_strategy_, &key_pair_, |
| 84 kTestBotJid, | 84 kTestBotJid, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 111 EXPECT_TRUE(stanza->NextNamed(signature_tag) == NULL); | 111 EXPECT_TRUE(stanza->NextNamed(signature_tag) == NULL); |
| 112 | 112 |
| 113 std::string time_str = | 113 std::string time_str = |
| 114 signature->Attr(QName(kChromotingXmlNamespace, "time")); | 114 signature->Attr(QName(kChromotingXmlNamespace, "time")); |
| 115 int64 time; | 115 int64 time; |
| 116 EXPECT_TRUE(base::StringToInt64(time_str, &time)); | 116 EXPECT_TRUE(base::StringToInt64(time_str, &time)); |
| 117 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT()); | 117 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT()); |
| 118 EXPECT_LE(start_time, time); | 118 EXPECT_LE(start_time, time); |
| 119 EXPECT_GE(now, time); | 119 EXPECT_GE(now, time); |
| 120 | 120 |
| 121 HostKeyPair key_pair; | 121 protocol::KeyPair key_pair; |
| 122 key_pair.LoadFromString(kTestHostKeyPair); | 122 key_pair.LoadFromString(kTestHostKeyPair); |
| 123 std::string expected_signature = | 123 std::string expected_signature = |
| 124 key_pair.GetSignature(std::string(kTestJid) + ' ' + time_str); | 124 key_pair.GetSignature(std::string(kTestJid) + ' ' + time_str); |
| 125 EXPECT_EQ(expected_signature, signature->BodyText()); | 125 EXPECT_EQ(expected_signature, signature->BodyText()); |
| 126 | 126 |
| 127 // Generate response and verify that callback is called. | 127 // Generate response and verify that callback is called. |
| 128 EXPECT_CALL(callback_, OnResponse(true, kSupportId, | 128 EXPECT_CALL(callback_, OnResponse(true, kSupportId, |
| 129 base::TimeDelta::FromSeconds(300))); | 129 base::TimeDelta::FromSeconds(300))); |
| 130 | 130 |
| 131 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); | 131 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 154 while ((listener = it.GetNext()) != NULL) { | 154 while ((listener = it.GetNext()) != NULL) { |
| 155 if (listener->OnSignalStrategyIncomingStanza(response.get())) | 155 if (listener->OnSignalStrategyIncomingStanza(response.get())) |
| 156 consumed++; | 156 consumed++; |
| 157 } | 157 } |
| 158 EXPECT_EQ(1, consumed); | 158 EXPECT_EQ(1, consumed); |
| 159 | 159 |
| 160 message_loop_.RunUntilIdle(); | 160 message_loop_.RunUntilIdle(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace remoting | 163 } // namespace remoting |
| OLD | NEW |