Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: remoting/signaling/iq_sender_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/signaling/iq_sender.cc ('k') | remoting/signaling/log_to_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 5 #include "remoting/signaling/iq_sender.h"
6 6
7 #include <utility> 7 #include <utility>
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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 public: 53 public:
54 IqSenderTest() { 54 IqSenderTest() {
55 EXPECT_CALL(signal_strategy_, AddListener(NotNull())); 55 EXPECT_CALL(signal_strategy_, AddListener(NotNull()));
56 sender_.reset(new IqSender(&signal_strategy_)); 56 sender_.reset(new IqSender(&signal_strategy_));
57 EXPECT_CALL(signal_strategy_, RemoveListener( 57 EXPECT_CALL(signal_strategy_, RemoveListener(
58 static_cast<SignalStrategy::Listener*>(sender_.get()))); 58 static_cast<SignalStrategy::Listener*>(sender_.get())));
59 } 59 }
60 60
61 protected: 61 protected:
62 void SendTestMessage() { 62 void SendTestMessage() {
63 scoped_ptr<XmlElement> iq_body( 63 std::unique_ptr<XmlElement> iq_body(
64 new XmlElement(QName(kNamespace, kBodyTag))); 64 new XmlElement(QName(kNamespace, kBodyTag)));
65 XmlElement* sent_stanza; 65 XmlElement* sent_stanza;
66 EXPECT_CALL(signal_strategy_, GetNextId()) 66 EXPECT_CALL(signal_strategy_, GetNextId())
67 .WillOnce(Return(kStanzaId)); 67 .WillOnce(Return(kStanzaId));
68 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)) 68 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_))
69 .WillOnce(DoAll(SaveArg<0>(&sent_stanza), Return(true))); 69 .WillOnce(DoAll(SaveArg<0>(&sent_stanza), Return(true)));
70 request_ = sender_->SendIq(kType, kTo, std::move(iq_body), base::Bind( 70 request_ = sender_->SendIq(kType, kTo, std::move(iq_body), base::Bind(
71 &MockCallback::OnReply, base::Unretained(&callback_))); 71 &MockCallback::OnReply, base::Unretained(&callback_)));
72 72
73 std::string expected_xml_string = 73 std::string expected_xml_string =
74 base::StringPrintf( 74 base::StringPrintf(
75 "<cli:iq type=\"%s\" to=\"%s\" id=\"%s\" " 75 "<cli:iq type=\"%s\" to=\"%s\" id=\"%s\" "
76 "xmlns:cli=\"jabber:client\">" 76 "xmlns:cli=\"jabber:client\">"
77 "<%s:%s xmlns:%s=\"%s\"/>" 77 "<%s:%s xmlns:%s=\"%s\"/>"
78 "</cli:iq>", 78 "</cli:iq>",
79 kType, kTo, kStanzaId, kNamespacePrefix, kBodyTag, 79 kType, kTo, kStanzaId, kNamespacePrefix, kBodyTag,
80 kNamespacePrefix, kNamespace); 80 kNamespacePrefix, kNamespace);
81 EXPECT_EQ(expected_xml_string, sent_stanza->Str()); 81 EXPECT_EQ(expected_xml_string, sent_stanza->Str());
82 delete sent_stanza; 82 delete sent_stanza;
83 } 83 }
84 84
85 bool FormatAndDeliverResponse(const std::string& from, 85 bool FormatAndDeliverResponse(const std::string& from,
86 scoped_ptr<XmlElement>* response_out) { 86 std::unique_ptr<XmlElement>* response_out) {
87 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); 87 std::unique_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ));
88 response->AddAttr(QName(std::string(), "type"), "result"); 88 response->AddAttr(QName(std::string(), "type"), "result");
89 response->AddAttr(QName(std::string(), "id"), kStanzaId); 89 response->AddAttr(QName(std::string(), "id"), kStanzaId);
90 response->AddAttr(QName(std::string(), "from"), from); 90 response->AddAttr(QName(std::string(), "from"), from);
91 91
92 XmlElement* response_body = new XmlElement( 92 XmlElement* response_body = new XmlElement(
93 QName("test:namespace", "response-body")); 93 QName("test:namespace", "response-body"));
94 response->AddElement(response_body); 94 response->AddElement(response_body);
95 95
96 bool result = sender_->OnSignalStrategyIncomingStanza(response.get()); 96 bool result = sender_->OnSignalStrategyIncomingStanza(response.get());
97 97
98 if (response_out) 98 if (response_out)
99 *response_out = std::move(response); 99 *response_out = std::move(response);
100 100
101 return result; 101 return result;
102 } 102 }
103 103
104 base::MessageLoop message_loop_; 104 base::MessageLoop message_loop_;
105 MockSignalStrategy signal_strategy_; 105 MockSignalStrategy signal_strategy_;
106 scoped_ptr<IqSender> sender_; 106 std::unique_ptr<IqSender> sender_;
107 MockCallback callback_; 107 MockCallback callback_;
108 scoped_ptr<IqRequest> request_; 108 std::unique_ptr<IqRequest> request_;
109 }; 109 };
110 110
111 TEST_F(IqSenderTest, SendIq) { 111 TEST_F(IqSenderTest, SendIq) {
112 ASSERT_NO_FATAL_FAILURE({ 112 ASSERT_NO_FATAL_FAILURE({
113 SendTestMessage(); 113 SendTestMessage();
114 }); 114 });
115 115
116 scoped_ptr<XmlElement> response; 116 std::unique_ptr<XmlElement> response;
117 EXPECT_TRUE(FormatAndDeliverResponse(kTo, &response)); 117 EXPECT_TRUE(FormatAndDeliverResponse(kTo, &response));
118 118
119 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get()))); 119 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get())));
120 base::RunLoop().RunUntilIdle(); 120 base::RunLoop().RunUntilIdle();
121 } 121 }
122 122
123 TEST_F(IqSenderTest, Timeout) { 123 TEST_F(IqSenderTest, Timeout) {
124 ASSERT_NO_FATAL_FAILURE({ 124 ASSERT_NO_FATAL_FAILURE({
125 SendTestMessage(); 125 SendTestMessage();
126 }); 126 });
127 127
128 request_->SetTimeout(base::TimeDelta::FromMilliseconds(2)); 128 request_->SetTimeout(base::TimeDelta::FromMilliseconds(2));
129 129
130 EXPECT_CALL(callback_, OnReply(request_.get(), nullptr)) 130 EXPECT_CALL(callback_, OnReply(request_.get(), nullptr))
131 .WillOnce( 131 .WillOnce(
132 InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitWhenIdle)); 132 InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitWhenIdle));
133 message_loop_.Run(); 133 message_loop_.Run();
134 } 134 }
135 135
136 TEST_F(IqSenderTest, NotNormalizedJid) { 136 TEST_F(IqSenderTest, NotNormalizedJid) {
137 ASSERT_NO_FATAL_FAILURE({ 137 ASSERT_NO_FATAL_FAILURE({
138 SendTestMessage(); 138 SendTestMessage();
139 }); 139 });
140 140
141 // Set upper-case from value, which is equivalent to kTo in the original 141 // Set upper-case from value, which is equivalent to kTo in the original
142 // message. 142 // message.
143 scoped_ptr<XmlElement> response; 143 std::unique_ptr<XmlElement> response;
144 EXPECT_TRUE(FormatAndDeliverResponse("USER@domain.com", &response)); 144 EXPECT_TRUE(FormatAndDeliverResponse("USER@domain.com", &response));
145 145
146 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get()))); 146 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get())));
147 base::RunLoop().RunUntilIdle(); 147 base::RunLoop().RunUntilIdle();
148 } 148 }
149 149
150 TEST_F(IqSenderTest, InvalidFrom) { 150 TEST_F(IqSenderTest, InvalidFrom) {
151 ASSERT_NO_FATAL_FAILURE({ 151 ASSERT_NO_FATAL_FAILURE({
152 SendTestMessage(); 152 SendTestMessage();
153 }); 153 });
154 154
155 EXPECT_FALSE(FormatAndDeliverResponse("different_user@domain.com", nullptr)); 155 EXPECT_FALSE(FormatAndDeliverResponse("different_user@domain.com", nullptr));
156 156
157 EXPECT_CALL(callback_, OnReply(_, _)).Times(0); 157 EXPECT_CALL(callback_, OnReply(_, _)).Times(0);
158 base::RunLoop().RunUntilIdle(); 158 base::RunLoop().RunUntilIdle();
159 } 159 }
160 160
161 } // namespace remoting 161 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/signaling/iq_sender.cc ('k') | remoting/signaling/log_to_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698