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> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
10 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
11 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "remoting/base/constants.h" | 15 #include "remoting/base/constants.h" |
14 #include "remoting/base/rsa_key_pair.h" | 16 #include "remoting/base/rsa_key_pair.h" |
15 #include "remoting/base/test_rsa_key_pair.h" | 17 #include "remoting/base/test_rsa_key_pair.h" |
16 #include "remoting/signaling/iq_sender.h" | 18 #include "remoting/signaling/iq_sender.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 74 |
73 base::MessageLoop message_loop_; | 75 base::MessageLoop message_loop_; |
74 MockSignalStrategy signal_strategy_; | 76 MockSignalStrategy signal_strategy_; |
75 base::ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; | 77 base::ObserverList<SignalStrategy::Listener, true> signal_strategy_listeners_; |
76 scoped_refptr<RsaKeyPair> key_pair_; | 78 scoped_refptr<RsaKeyPair> key_pair_; |
77 MockCallback callback_; | 79 MockCallback callback_; |
78 }; | 80 }; |
79 | 81 |
80 TEST_F(RegisterSupportHostRequestTest, Send) { | 82 TEST_F(RegisterSupportHostRequestTest, Send) { |
81 // |iq_request| is freed by RegisterSupportHostRequest. | 83 // |iq_request| is freed by RegisterSupportHostRequest. |
82 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); | 84 int64_t start_time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); |
83 | 85 |
84 scoped_ptr<RegisterSupportHostRequest> request( | 86 scoped_ptr<RegisterSupportHostRequest> request( |
85 new RegisterSupportHostRequest(&signal_strategy_, key_pair_, | 87 new RegisterSupportHostRequest(&signal_strategy_, key_pair_, |
86 kTestBotJid, | 88 kTestBotJid, |
87 base::Bind(&MockCallback::OnResponse, | 89 base::Bind(&MockCallback::OnResponse, |
88 base::Unretained(&callback_)))); | 90 base::Unretained(&callback_)))); |
89 | 91 |
90 XmlElement* sent_iq = nullptr; | 92 XmlElement* sent_iq = nullptr; |
91 EXPECT_CALL(signal_strategy_, GetNextId()) | 93 EXPECT_CALL(signal_strategy_, GetNextId()) |
92 .WillOnce(Return(kStanzaId)); | 94 .WillOnce(Return(kStanzaId)); |
(...skipping 14 matching lines...) Expand all Loading... |
107 EXPECT_EQ(QName(kChromotingXmlNamespace, "register-support-host"), | 109 EXPECT_EQ(QName(kChromotingXmlNamespace, "register-support-host"), |
108 stanza->FirstElement()->Name()); | 110 stanza->FirstElement()->Name()); |
109 | 111 |
110 QName signature_tag(kChromotingXmlNamespace, "signature"); | 112 QName signature_tag(kChromotingXmlNamespace, "signature"); |
111 XmlElement* signature = stanza->FirstElement()->FirstNamed(signature_tag); | 113 XmlElement* signature = stanza->FirstElement()->FirstNamed(signature_tag); |
112 ASSERT_TRUE(signature != nullptr); | 114 ASSERT_TRUE(signature != nullptr); |
113 EXPECT_TRUE(stanza->NextNamed(signature_tag) == nullptr); | 115 EXPECT_TRUE(stanza->NextNamed(signature_tag) == nullptr); |
114 | 116 |
115 std::string time_str = | 117 std::string time_str = |
116 signature->Attr(QName(kChromotingXmlNamespace, "time")); | 118 signature->Attr(QName(kChromotingXmlNamespace, "time")); |
117 int64 time; | 119 int64_t time; |
118 EXPECT_TRUE(base::StringToInt64(time_str, &time)); | 120 EXPECT_TRUE(base::StringToInt64(time_str, &time)); |
119 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT()); | 121 int64_t now = static_cast<int64_t>(base::Time::Now().ToDoubleT()); |
120 EXPECT_LE(start_time, time); | 122 EXPECT_LE(start_time, time); |
121 EXPECT_GE(now, time); | 123 EXPECT_GE(now, time); |
122 | 124 |
123 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); | 125 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); |
124 ASSERT_TRUE(key_pair.get()); | 126 ASSERT_TRUE(key_pair.get()); |
125 | 127 |
126 std::string expected_signature = | 128 std::string expected_signature = |
127 key_pair->SignMessage(std::string(kTestJidNormalized) + ' ' + time_str); | 129 key_pair->SignMessage(std::string(kTestJidNormalized) + ' ' + time_str); |
128 EXPECT_EQ(expected_signature, signature->BodyText()); | 130 EXPECT_EQ(expected_signature, signature->BodyText()); |
129 | 131 |
(...skipping 28 matching lines...) Expand all Loading... |
158 while ((listener = it.GetNext()) != nullptr) { | 160 while ((listener = it.GetNext()) != nullptr) { |
159 if (listener->OnSignalStrategyIncomingStanza(response.get())) | 161 if (listener->OnSignalStrategyIncomingStanza(response.get())) |
160 consumed++; | 162 consumed++; |
161 } | 163 } |
162 EXPECT_EQ(1, consumed); | 164 EXPECT_EQ(1, consumed); |
163 | 165 |
164 base::RunLoop().RunUntilIdle(); | 166 base::RunLoop().RunUntilIdle(); |
165 } | 167 } |
166 | 168 |
167 } // namespace remoting | 169 } // namespace remoting |
OLD | NEW |