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/register_support_host_request.h" | 5 #include "remoting/host/register_support_host_request.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/run_loop.h" | |
| 14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringize_macros.h" | 14 #include "base/strings/stringize_macros.h" |
| 16 #include "base/test/mock_callback.h" | 15 #include "base/test/mock_callback.h" |
| 16 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | |
| 17 #include "remoting/base/constants.h" | 17 #include "remoting/base/constants.h" |
| 18 #include "remoting/base/rsa_key_pair.h" | 18 #include "remoting/base/rsa_key_pair.h" |
| 19 #include "remoting/base/test_rsa_key_pair.h" | 19 #include "remoting/base/test_rsa_key_pair.h" |
| 20 #include "remoting/host/host_details.h" | 20 #include "remoting/host/host_details.h" |
| 21 #include "remoting/protocol/errors.h" | |
| 21 #include "remoting/signaling/iq_sender.h" | 22 #include "remoting/signaling/iq_sender.h" |
| 22 #include "remoting/signaling/mock_signal_strategy.h" | 23 #include "remoting/signaling/mock_signal_strategy.h" |
| 23 #include "remoting/signaling/signaling_address.h" | 24 #include "remoting/signaling/signaling_address.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" | 27 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" |
| 27 #include "third_party/libjingle_xmpp/xmpp/constants.h" | 28 #include "third_party/libjingle_xmpp/xmpp/constants.h" |
| 28 | 29 |
| 29 using buzz::QName; | 30 using buzz::QName; |
| 30 using buzz::XmlElement; | 31 using buzz::XmlElement; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); | 71 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); |
| 71 } | 72 } |
| 72 | 73 |
| 73 base::MessageLoop message_loop_; | 74 base::MessageLoop message_loop_; |
| 74 MockSignalStrategy signal_strategy_; | 75 MockSignalStrategy signal_strategy_; |
| 75 base::ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; | 76 base::ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; |
| 76 scoped_refptr<RsaKeyPair> key_pair_; | 77 scoped_refptr<RsaKeyPair> key_pair_; |
| 77 base::MockCallback<RegisterSupportHostRequest::RegisterCallback> callback_; | 78 base::MockCallback<RegisterSupportHostRequest::RegisterCallback> callback_; |
| 78 }; | 79 }; |
| 79 | 80 |
| 81 TEST_F(RegisterSupportHostRequestTest, Timeout) { | |
| 82 std::unique_ptr<RegisterSupportHostRequest> request( | |
| 83 new RegisterSupportHostRequest(&signal_strategy_, key_pair_, kTestBotJid, | |
| 84 callback_.Get())); | |
| 85 EXPECT_CALL(signal_strategy_, GetNextId()).WillOnce(Return(kStanzaId)); | |
| 86 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull())) | |
| 87 .WillOnce(Return(true)); | |
| 88 | |
| 89 request->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); | |
| 90 | |
| 91 // Generate response and verify that callback is called. | |
| 92 EXPECT_CALL( | |
| 93 callback_, | |
| 94 Run("", base::TimeDelta::FromSeconds(0), | |
| 95 protocol::ErrorCodeToString(protocol::ErrorCode::SIGNALING_TIMEOUT))); | |
| 96 | |
| 97 mock_time_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(15)); | |
|
Sergey Ulanov
2017/06/07 06:41:30
Where is mock_time_task_runner_ defined?
kelvinp
2017/06/12 21:31:26
Good catch. It is a bad merge =(
| |
| 98 } | |
| 99 | |
| 80 TEST_F(RegisterSupportHostRequestTest, Send) { | 100 TEST_F(RegisterSupportHostRequestTest, Send) { |
| 81 // |iq_request| is freed by RegisterSupportHostRequest. | 101 // |iq_request| is freed by RegisterSupportHostRequest. |
| 82 int64_t start_time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); | 102 int64_t start_time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); |
| 83 | 103 |
| 84 std::unique_ptr<RegisterSupportHostRequest> request( | 104 std::unique_ptr<RegisterSupportHostRequest> request( |
| 85 new RegisterSupportHostRequest(&signal_strategy_, key_pair_, kTestBotJid, | 105 new RegisterSupportHostRequest(&signal_strategy_, key_pair_, kTestBotJid, |
| 86 callback_.Get())); | 106 callback_.Get())); |
| 87 | 107 |
| 88 XmlElement* sent_iq = nullptr; | 108 XmlElement* sent_iq = nullptr; |
| 89 EXPECT_CALL(signal_strategy_, GetNextId()) | 109 EXPECT_CALL(signal_strategy_, GetNextId()) |
| 90 .WillOnce(Return(kStanzaId)); | 110 .WillOnce(Return(kStanzaId)); |
| 91 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull())) | 111 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull())) |
| 92 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); | 112 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); |
| 93 | 113 |
| 94 request->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); | 114 request->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 95 base::RunLoop().RunUntilIdle(); | 115 mock_time_task_runner_->RunUntilIdle(); |
| 96 | 116 |
| 97 // Verify format of the query. | 117 // Verify format of the query. |
| 98 std::unique_ptr<XmlElement> stanza(sent_iq); | 118 std::unique_ptr<XmlElement> stanza(sent_iq); |
| 99 ASSERT_TRUE(stanza != nullptr); | 119 ASSERT_TRUE(stanza != nullptr); |
| 100 | 120 |
| 101 EXPECT_EQ(stanza->Attr(buzz::QName(std::string(), "to")), | 121 EXPECT_EQ(stanza->Attr(buzz::QName(std::string(), "to")), |
| 102 std::string(kTestBotJid)); | 122 std::string(kTestBotJid)); |
| 103 EXPECT_EQ(stanza->Attr(buzz::QName(std::string(), "type")), "set"); | 123 EXPECT_EQ(stanza->Attr(buzz::QName(std::string(), "type")), "set"); |
| 104 | 124 |
| 105 EXPECT_EQ(QName(kChromotingXmlNamespace, "register-support-host"), | 125 EXPECT_EQ(QName(kChromotingXmlNamespace, "register-support-host"), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 support_id_lifetime->AddText(kSupportIdLifetime); | 180 support_id_lifetime->AddText(kSupportIdLifetime); |
| 161 result->AddElement(support_id_lifetime); | 181 result->AddElement(support_id_lifetime); |
| 162 | 182 |
| 163 int consumed = 0; | 183 int consumed = 0; |
| 164 for (auto& listener : signal_strategy_listeners_) { | 184 for (auto& listener : signal_strategy_listeners_) { |
| 165 if (listener.OnSignalStrategyIncomingStanza(response.get())) | 185 if (listener.OnSignalStrategyIncomingStanza(response.get())) |
| 166 consumed++; | 186 consumed++; |
| 167 } | 187 } |
| 168 EXPECT_EQ(1, consumed); | 188 EXPECT_EQ(1, consumed); |
| 169 | 189 |
| 170 base::RunLoop().RunUntilIdle(); | 190 mock_time_task_runner_->RunUntilIdle(); |
| 171 } | 191 } |
| 172 | 192 |
| 173 } // namespace remoting | 193 } // namespace remoting |
| OLD | NEW |