OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signaling/iq_sender.h" |
| 6 |
| 7 #include <utility> |
| 8 |
5 #include "base/bind.h" | 9 #include "base/bind.h" |
6 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
7 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
10 #include "remoting/signaling/iq_sender.h" | |
11 #include "remoting/signaling/mock_signal_strategy.h" | 14 #include "remoting/signaling/mock_signal_strategy.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
15 #include "third_party/webrtc/libjingle/xmpp/constants.h" | 18 #include "third_party/webrtc/libjingle/xmpp/constants.h" |
16 | 19 |
17 using ::testing::_; | 20 using ::testing::_; |
18 using ::testing::DeleteArg; | 21 using ::testing::DeleteArg; |
19 using ::testing::InvokeWithoutArgs; | 22 using ::testing::InvokeWithoutArgs; |
20 using ::testing::NotNull; | 23 using ::testing::NotNull; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 60 |
58 protected: | 61 protected: |
59 void SendTestMessage() { | 62 void SendTestMessage() { |
60 scoped_ptr<XmlElement> iq_body( | 63 scoped_ptr<XmlElement> iq_body( |
61 new XmlElement(QName(kNamespace, kBodyTag))); | 64 new XmlElement(QName(kNamespace, kBodyTag))); |
62 XmlElement* sent_stanza; | 65 XmlElement* sent_stanza; |
63 EXPECT_CALL(signal_strategy_, GetNextId()) | 66 EXPECT_CALL(signal_strategy_, GetNextId()) |
64 .WillOnce(Return(kStanzaId)); | 67 .WillOnce(Return(kStanzaId)); |
65 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)) | 68 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)) |
66 .WillOnce(DoAll(SaveArg<0>(&sent_stanza), Return(true))); | 69 .WillOnce(DoAll(SaveArg<0>(&sent_stanza), Return(true))); |
67 request_ = sender_->SendIq(kType, kTo, iq_body.Pass(), base::Bind( | 70 request_ = sender_->SendIq(kType, kTo, std::move(iq_body), base::Bind( |
68 &MockCallback::OnReply, base::Unretained(&callback_))); | 71 &MockCallback::OnReply, base::Unretained(&callback_))); |
69 | 72 |
70 std::string expected_xml_string = | 73 std::string expected_xml_string = |
71 base::StringPrintf( | 74 base::StringPrintf( |
72 "<cli:iq type=\"%s\" to=\"%s\" id=\"%s\" " | 75 "<cli:iq type=\"%s\" to=\"%s\" id=\"%s\" " |
73 "xmlns:cli=\"jabber:client\">" | 76 "xmlns:cli=\"jabber:client\">" |
74 "<%s:%s xmlns:%s=\"%s\"/>" | 77 "<%s:%s xmlns:%s=\"%s\"/>" |
75 "</cli:iq>", | 78 "</cli:iq>", |
76 kType, kTo, kStanzaId, kNamespacePrefix, kBodyTag, | 79 kType, kTo, kStanzaId, kNamespacePrefix, kBodyTag, |
77 kNamespacePrefix, kNamespace); | 80 kNamespacePrefix, kNamespace); |
78 EXPECT_EQ(expected_xml_string, sent_stanza->Str()); | 81 EXPECT_EQ(expected_xml_string, sent_stanza->Str()); |
79 delete sent_stanza; | 82 delete sent_stanza; |
80 } | 83 } |
81 | 84 |
82 bool FormatAndDeliverResponse(const std::string& from, | 85 bool FormatAndDeliverResponse(const std::string& from, |
83 scoped_ptr<XmlElement>* response_out) { | 86 scoped_ptr<XmlElement>* response_out) { |
84 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); | 87 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); |
85 response->AddAttr(QName(std::string(), "type"), "result"); | 88 response->AddAttr(QName(std::string(), "type"), "result"); |
86 response->AddAttr(QName(std::string(), "id"), kStanzaId); | 89 response->AddAttr(QName(std::string(), "id"), kStanzaId); |
87 response->AddAttr(QName(std::string(), "from"), from); | 90 response->AddAttr(QName(std::string(), "from"), from); |
88 | 91 |
89 XmlElement* response_body = new XmlElement( | 92 XmlElement* response_body = new XmlElement( |
90 QName("test:namespace", "response-body")); | 93 QName("test:namespace", "response-body")); |
91 response->AddElement(response_body); | 94 response->AddElement(response_body); |
92 | 95 |
93 bool result = sender_->OnSignalStrategyIncomingStanza(response.get()); | 96 bool result = sender_->OnSignalStrategyIncomingStanza(response.get()); |
94 | 97 |
95 if (response_out) | 98 if (response_out) |
96 *response_out = response.Pass(); | 99 *response_out = std::move(response); |
97 | 100 |
98 return result; | 101 return result; |
99 } | 102 } |
100 | 103 |
101 base::MessageLoop message_loop_; | 104 base::MessageLoop message_loop_; |
102 MockSignalStrategy signal_strategy_; | 105 MockSignalStrategy signal_strategy_; |
103 scoped_ptr<IqSender> sender_; | 106 scoped_ptr<IqSender> sender_; |
104 MockCallback callback_; | 107 MockCallback callback_; |
105 scoped_ptr<IqRequest> request_; | 108 scoped_ptr<IqRequest> request_; |
106 }; | 109 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 SendTestMessage(); | 152 SendTestMessage(); |
150 }); | 153 }); |
151 | 154 |
152 EXPECT_FALSE(FormatAndDeliverResponse("different_user@domain.com", nullptr)); | 155 EXPECT_FALSE(FormatAndDeliverResponse("different_user@domain.com", nullptr)); |
153 | 156 |
154 EXPECT_CALL(callback_, OnReply(_, _)).Times(0); | 157 EXPECT_CALL(callback_, OnReply(_, _)).Times(0); |
155 base::RunLoop().RunUntilIdle(); | 158 base::RunLoop().RunUntilIdle(); |
156 } | 159 } |
157 | 160 |
158 } // namespace remoting | 161 } // namespace remoting |
OLD | NEW |