OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/host_status_sender.h" | 5 #include "remoting/host/host_status_sender.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/base/logging.h" | |
10 #include "remoting/base/rsa_key_pair.h" | 11 #include "remoting/base/rsa_key_pair.h" |
11 #include "remoting/base/test_rsa_key_pair.h" | 12 #include "remoting/base/test_rsa_key_pair.h" |
12 #include "remoting/host/host_exit_codes.h" | 13 #include "remoting/host/host_exit_codes.h" |
13 #include "remoting/jingle_glue/mock_objects.h" | 14 #include "remoting/jingle_glue/mock_objects.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
17 | 18 |
18 using buzz::QName; | 19 using buzz::QName; |
19 using buzz::XmlElement; | 20 using buzz::XmlElement; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 // So we expect SendStanza to be called only once. | 81 // So we expect SendStanza to be called only once. |
81 host_status_sender_->SendOnlineStatus(); | 82 host_status_sender_->SendOnlineStatus(); |
82 | 83 |
83 host_status_sender_->OnSignalStrategyStateChange( | 84 host_status_sender_->OnSignalStrategyStateChange( |
84 SignalStrategy::CONNECTED); | 85 SignalStrategy::CONNECTED); |
85 host_status_sender_->SendOnlineStatus(); | 86 host_status_sender_->SendOnlineStatus(); |
86 | 87 |
87 scoped_ptr<XmlElement> stanza(sent_iq); | 88 scoped_ptr<XmlElement> stanza(sent_iq); |
88 | 89 |
89 ASSERT_TRUE(stanza != NULL); | 90 ASSERT_TRUE(stanza != NULL); |
90 LOG(INFO) << stanza->Str(); | 91 HOST_LOG << stanza->Str(); |
Sergey Ulanov
2013/11/26 19:56:28
I don't think we need this. It spams console from
weitao
2013/11/26 20:03:06
Done.
| |
91 | 92 |
92 ValidateHostStatusStanza(stanza.get(), HostStatusSender::ONLINE); | 93 ValidateHostStatusStanza(stanza.get(), HostStatusSender::ONLINE); |
93 } | 94 } |
94 | 95 |
95 TEST_F(HostStatusSenderTest, SendOfflineStatus) { | 96 TEST_F(HostStatusSenderTest, SendOfflineStatus) { |
96 XmlElement* sent_iq = NULL; | 97 XmlElement* sent_iq = NULL; |
97 EXPECT_CALL(signal_strategy_, GetState()) | 98 EXPECT_CALL(signal_strategy_, GetState()) |
98 .WillOnce(Return(SignalStrategy::DISCONNECTED)) | 99 .WillOnce(Return(SignalStrategy::DISCONNECTED)) |
99 .WillRepeatedly(Return(SignalStrategy::CONNECTED)); | 100 .WillRepeatedly(Return(SignalStrategy::CONNECTED)); |
100 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 101 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
101 .WillRepeatedly(Return(kTestJid)); | 102 .WillRepeatedly(Return(kTestJid)); |
102 EXPECT_CALL(signal_strategy_, GetNextId()) | 103 EXPECT_CALL(signal_strategy_, GetNextId()) |
103 .WillOnce(Return(kStanzaId)); | 104 .WillOnce(Return(kStanzaId)); |
104 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull())) | 105 EXPECT_CALL(signal_strategy_, SendStanzaPtr(NotNull())) |
105 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); | 106 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); |
106 | 107 |
107 // Call SendOfflineStatus twice. The first call should be a | 108 // Call SendOfflineStatus twice. The first call should be a |
108 // no-op because |signal_strategy_| is diconnected. | 109 // no-op because |signal_strategy_| is diconnected. |
109 // So we expect SendStanza to be called only once. | 110 // So we expect SendStanza to be called only once. |
110 host_status_sender_->SendOfflineStatus(kTestExitCode); | 111 host_status_sender_->SendOfflineStatus(kTestExitCode); |
111 | 112 |
112 host_status_sender_->OnSignalStrategyStateChange( | 113 host_status_sender_->OnSignalStrategyStateChange( |
113 SignalStrategy::CONNECTED); | 114 SignalStrategy::CONNECTED); |
114 host_status_sender_->SendOfflineStatus(kTestExitCode); | 115 host_status_sender_->SendOfflineStatus(kTestExitCode); |
115 | 116 |
116 scoped_ptr<XmlElement> stanza(sent_iq); | 117 scoped_ptr<XmlElement> stanza(sent_iq); |
117 | 118 |
118 ASSERT_TRUE(stanza != NULL); | 119 ASSERT_TRUE(stanza != NULL); |
119 LOG(INFO) << stanza->Str(); | 120 HOST_LOG << stanza->Str(); |
120 | 121 |
121 ValidateHostStatusStanza(stanza.get(), HostStatusSender::OFFLINE); | 122 ValidateHostStatusStanza(stanza.get(), HostStatusSender::OFFLINE); |
122 } | 123 } |
123 | 124 |
124 // Validate a host status stanza. | 125 // Validate a host status stanza. |
125 void HostStatusSenderTest::ValidateHostStatusStanza( | 126 void HostStatusSenderTest::ValidateHostStatusStanza( |
126 XmlElement* stanza, HostStatusSender::HostStatus status) { | 127 XmlElement* stanza, HostStatusSender::HostStatus status) { |
127 EXPECT_EQ(stanza->Attr(QName(std::string(), "to")), | 128 EXPECT_EQ(stanza->Attr(QName(std::string(), "to")), |
128 std::string(kTestBotJid)); | 129 std::string(kTestBotJid)); |
129 EXPECT_EQ(stanza->Attr(QName(std::string(), "type")), "set"); | 130 EXPECT_EQ(stanza->Attr(QName(std::string(), "type")), "set"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 } | 188 } |
188 | 189 |
189 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); | 190 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); |
190 ASSERT_TRUE(key_pair.get()); | 191 ASSERT_TRUE(key_pair.get()); |
191 | 192 |
192 std::string expected_signature = | 193 std::string expected_signature = |
193 key_pair->SignMessage(message); | 194 key_pair->SignMessage(message); |
194 EXPECT_EQ(expected_signature, signature->BodyText()); | 195 EXPECT_EQ(expected_signature, signature->BodyText()); |
195 | 196 |
196 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT()); | 197 int64 now = static_cast<int64>(base::Time::Now().ToDoubleT()); |
197 LOG(INFO) << "SendHostStatus took " << now - time << " seconds."; | 198 HOST_LOG << "SendHostStatus took " << now - time << " seconds."; |
198 } | 199 } |
199 | 200 |
200 } // namespace remoting | 201 } // namespace remoting |
OLD | NEW |