summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 22:50:13 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 22:50:13 +0000
commit19d963f72826c669179b9fa2c9c11ad40465a701 (patch)
tree798c0b13524d1fa331e427fd3b64a7e0d3d2798f /remoting
parent05932300479fbf56b492155d581c37cd7abea3f0 (diff)
downloadchromium_src-19d963f72826c669179b9fa2c9c11ad40465a701.zip
chromium_src-19d963f72826c669179b9fa2c9c11ad40465a701.tar.gz
chromium_src-19d963f72826c669179b9fa2c9c11ad40465a701.tar.bz2
Simplify IqRequest interface.
This is neccessary to make the interface usable with stanzas generated by JingleMessage::ToXml(). BUG=None TEST=Unittests Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=99801 Review URL: http://codereview.chromium.org/7809003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/heartbeat_sender.cc3
-rw-r--r--remoting/host/heartbeat_sender_unittest.cc15
-rw-r--r--remoting/host/register_support_host_request.cc4
-rw-r--r--remoting/host/register_support_host_request_unittest.cc12
-rw-r--r--remoting/jingle_glue/iq_request.cc4
-rw-r--r--remoting/jingle_glue/iq_request.h16
-rw-r--r--remoting/jingle_glue/iq_request_unittest.cc3
-rw-r--r--remoting/jingle_glue/javascript_iq_request.cc7
-rw-r--r--remoting/jingle_glue/javascript_iq_request.h3
-rw-r--r--remoting/jingle_glue/jingle_info_request.cc5
-rw-r--r--remoting/jingle_glue/mock_objects.h4
-rw-r--r--remoting/jingle_glue/xmpp_iq_request.cc12
-rw-r--r--remoting/jingle_glue/xmpp_iq_request.h3
13 files changed, 45 insertions, 46 deletions
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index 182c06e..32ddd49 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -101,7 +101,8 @@ void HeartbeatSender::DoSendStanza() {
DCHECK_EQ(state_, STARTED);
VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid;
- request_->SendIq(buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage());
+ request_->SendIq(IqRequest::MakeIqStanza(
+ buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage()));
}
void HeartbeatSender::ProcessResponse(const XmlElement* response) {
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index 8818c156..49933c2 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -27,6 +27,7 @@ using testing::DoAll;
using testing::Invoke;
using testing::NotNull;
using testing::Return;
+using testing::SaveArg;
namespace remoting {
@@ -50,7 +51,7 @@ class HeartbeatSenderTest : public testing::Test {
};
// Call Start() followed by Stop(), and makes sure an Iq stanza is
-// being send.
+// being sent.
TEST_F(HeartbeatSenderTest, DoSendStanza) {
// |iq_request| is freed by HeartbeatSender.
MockIqRequest* iq_request = new MockIqRequest();
@@ -66,12 +67,20 @@ TEST_F(HeartbeatSenderTest, DoSendStanza) {
EXPECT_CALL(signal_strategy_, CreateIqRequest())
.WillOnce(Return(iq_request));
- EXPECT_CALL(*iq_request, SendIq(buzz::STR_SET, kChromotingBotJid, NotNull()))
- .WillOnce(DoAll(DeleteArg<2>(), Return()));
+ XmlElement* sent_iq = NULL;
+ EXPECT_CALL(*iq_request, SendIq(NotNull()))
+ .WillOnce(SaveArg<0>(&sent_iq));
heartbeat_sender->OnSignallingConnected(&signal_strategy_, kTestJid);
message_loop_.RunAllPending();
+ scoped_ptr<XmlElement> stanza(sent_iq);
+ ASSERT_TRUE(stanza != NULL);
+
+ EXPECT_EQ(stanza->Attr(buzz::QName("", "to")),
+ std::string(kChromotingBotJid));
+ EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set");
+
heartbeat_sender->OnSignallingDisconnected();
message_loop_.RunAllPending();
}
diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc
index 3c47dab..38d3c4a 100644
--- a/remoting/host/register_support_host_request.cc
+++ b/remoting/host/register_support_host_request.cc
@@ -63,8 +63,8 @@ void RegisterSupportHostRequest::OnSignallingConnected(
request_->set_callback(base::Bind(
&RegisterSupportHostRequest::ProcessResponse, base::Unretained(this)));
- request_->SendIq(buzz::STR_SET, kChromotingBotJid,
- CreateRegistrationRequest(jid));
+ request_->SendIq(IqRequest::MakeIqStanza(
+ buzz::STR_SET, kChromotingBotJid, CreateRegistrationRequest(jid)));
}
void RegisterSupportHostRequest::OnSignallingDisconnected() {
diff --git a/remoting/host/register_support_host_request_unittest.cc b/remoting/host/register_support_host_request_unittest.cc
index 50c305a..57c83b2 100644
--- a/remoting/host/register_support_host_request_unittest.cc
+++ b/remoting/host/register_support_host_request_unittest.cc
@@ -76,8 +76,8 @@ TEST_F(RegisterSupportHostRequestTest, Send) {
.WillOnce(Return(iq_request));
XmlElement* sent_iq = NULL;
- EXPECT_CALL(*iq_request, SendIq(buzz::STR_SET, kChromotingBotJid, NotNull()))
- .WillOnce(SaveArg<2>(&sent_iq));
+ EXPECT_CALL(*iq_request, SendIq(NotNull()))
+ .WillOnce(SaveArg<0>(&sent_iq));
request->OnSignallingConnected(&signal_strategy_, kTestJid);
message_loop_.RunAllPending();
@@ -86,11 +86,15 @@ TEST_F(RegisterSupportHostRequestTest, Send) {
scoped_ptr<XmlElement> stanza(sent_iq);
ASSERT_TRUE(stanza != NULL);
+ EXPECT_EQ(stanza->Attr(buzz::QName("", "to")),
+ std::string(kChromotingBotJid));
+ EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set");
+
EXPECT_EQ(QName(kChromotingXmlNamespace, "register-support-host"),
- stanza->Name());
+ stanza->FirstElement()->Name());
QName signature_tag(kChromotingXmlNamespace, "signature");
- XmlElement* signature = stanza->FirstNamed(signature_tag);
+ XmlElement* signature = stanza->FirstElement()->FirstNamed(signature_tag);
ASSERT_TRUE(signature != NULL);
EXPECT_TRUE(stanza->NextNamed(signature_tag) == NULL);
diff --git a/remoting/jingle_glue/iq_request.cc b/remoting/jingle_glue/iq_request.cc
index 0e93c56..5de2e33 100644
--- a/remoting/jingle_glue/iq_request.cc
+++ b/remoting/jingle_glue/iq_request.cc
@@ -12,13 +12,11 @@ namespace remoting {
// static
buzz::XmlElement* IqRequest::MakeIqStanza(const std::string& type,
const std::string& addressee,
- buzz::XmlElement* iq_body,
- const std::string& id) {
+ buzz::XmlElement* iq_body) {
buzz::XmlElement* stanza = new buzz::XmlElement(buzz::QN_IQ);
stanza->AddAttr(buzz::QN_TYPE, type);
if (!addressee.empty())
stanza->AddAttr(buzz::QN_TO, addressee);
- stanza->AddAttr(buzz::QN_ID, id);
stanza->AddElement(iq_body);
return stanza;
}
diff --git a/remoting/jingle_glue/iq_request.h b/remoting/jingle_glue/iq_request.h
index 015d2db..6fbef97 100644
--- a/remoting/jingle_glue/iq_request.h
+++ b/remoting/jingle_glue/iq_request.h
@@ -25,23 +25,19 @@ class IqRequest {
public:
typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback;
+ static buzz::XmlElement* MakeIqStanza(const std::string& type,
+ const std::string& addressee,
+ buzz::XmlElement* iq_body);
+
IqRequest() {}
virtual ~IqRequest() {}
- // Sends stanza of type |type| to |addressee|. |iq_body| contains body of
- // the stanza. Takes pwnership of |iq_body|.
- virtual void SendIq(const std::string& type, const std::string& addressee,
- buzz::XmlElement* iq_body) = 0;
+ // Sends Iq stanza. Takes ownership of |stanza|.
+ virtual void SendIq(buzz::XmlElement* stanza) = 0;
// Sets callback that is called when reply stanza is received.
virtual void set_callback(const ReplyCallback& callback) = 0;
- protected:
- static buzz::XmlElement* MakeIqStanza(const std::string& type,
- const std::string& addressee,
- buzz::XmlElement* iq_body,
- const std::string& id);
-
private:
FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza);
diff --git a/remoting/jingle_glue/iq_request_unittest.cc b/remoting/jingle_glue/iq_request_unittest.cc
index 4b323fb..d7eeda6 100644
--- a/remoting/jingle_glue/iq_request_unittest.cc
+++ b/remoting/jingle_glue/iq_request_unittest.cc
@@ -31,7 +31,8 @@ TEST(IqRequestTest, MakeIqStanza) {
buzz::XmlElement* iq_body =
new buzz::XmlElement(buzz::QName(kNamespace, kBodyTag));
scoped_ptr<buzz::XmlElement> stanza(
- IqRequest::MakeIqStanza(kType, kTo, iq_body, kMessageId));
+ IqRequest::MakeIqStanza(kType, kTo, iq_body));
+ stanza->AddAttr(buzz::QName("", "id"), kMessageId);
EXPECT_EQ(expected_xml_string, stanza->Str());
}
diff --git a/remoting/jingle_glue/javascript_iq_request.cc b/remoting/jingle_glue/javascript_iq_request.cc
index b08ffe9..62366cf 100644
--- a/remoting/jingle_glue/javascript_iq_request.cc
+++ b/remoting/jingle_glue/javascript_iq_request.cc
@@ -83,12 +83,11 @@ JavascriptIqRequest::~JavascriptIqRequest() {
registry_->RemoveAllRequests(this);
}
-void JavascriptIqRequest::SendIq(const std::string& type,
- const std::string& addressee,
- buzz::XmlElement* iq_body) {
+void JavascriptIqRequest::SendIq(buzz::XmlElement* stanza) {
std::string id = signal_strategy_->GetNextId();
+ stanza->AddAttr(buzz::QN_ID, id);
registry_->RegisterRequest(this, id);
- signal_strategy_->SendStanza(MakeIqStanza(type, addressee, iq_body, id));
+ signal_strategy_->SendStanza(stanza);
}
void JavascriptIqRequest::set_callback(const ReplyCallback& callback) {
diff --git a/remoting/jingle_glue/javascript_iq_request.h b/remoting/jingle_glue/javascript_iq_request.h
index d2ff5d9..f94fc33 100644
--- a/remoting/jingle_glue/javascript_iq_request.h
+++ b/remoting/jingle_glue/javascript_iq_request.h
@@ -55,8 +55,7 @@ class JavascriptIqRequest : public IqRequest {
virtual ~JavascriptIqRequest();
// IqRequest interface.
- virtual void SendIq(const std::string& type, const std::string& addressee,
- buzz::XmlElement* iq_body) OVERRIDE;
+ virtual void SendIq(buzz::XmlElement* iq_body) OVERRIDE;
virtual void set_callback(const ReplyCallback& callback) OVERRIDE;
private:
diff --git a/remoting/jingle_glue/jingle_info_request.cc b/remoting/jingle_glue/jingle_info_request.cc
index 888c768..9a5d16d 100644
--- a/remoting/jingle_glue/jingle_info_request.cc
+++ b/remoting/jingle_glue/jingle_info_request.cc
@@ -34,8 +34,9 @@ JingleInfoRequest::~JingleInfoRequest() {
void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) {
on_jingle_info_cb_ = callback;
- request_->SendIq(buzz::STR_GET, buzz::STR_EMPTY,
- new buzz::XmlElement(buzz::QN_JINGLE_INFO_QUERY, true));
+ request_->SendIq(IqRequest::MakeIqStanza(
+ buzz::STR_GET, buzz::STR_EMPTY,
+ new buzz::XmlElement(buzz::QN_JINGLE_INFO_QUERY, true)));
}
void JingleInfoRequest::OnResponse(const buzz::XmlElement* stanza) {
diff --git a/remoting/jingle_glue/mock_objects.h b/remoting/jingle_glue/mock_objects.h
index 6c93b0a..5563e22 100644
--- a/remoting/jingle_glue/mock_objects.h
+++ b/remoting/jingle_glue/mock_objects.h
@@ -27,9 +27,7 @@ class MockIqRequest : public IqRequest {
MockIqRequest();
virtual ~MockIqRequest();
- MOCK_METHOD3(SendIq, void(const std::string& type,
- const std::string& addressee,
- buzz::XmlElement* iq_body));
+ MOCK_METHOD1(SendIq, void(buzz::XmlElement* stanza));
MOCK_METHOD1(set_callback, void(const IqRequest::ReplyCallback&));
// Ensure this takes ownership of the pointer, as the real IqRequest object
diff --git a/remoting/jingle_glue/xmpp_iq_request.cc b/remoting/jingle_glue/xmpp_iq_request.cc
index b8057c3..7e07665 100644
--- a/remoting/jingle_glue/xmpp_iq_request.cc
+++ b/remoting/jingle_glue/xmpp_iq_request.cc
@@ -25,20 +25,14 @@ XmppIqRequest::~XmppIqRequest() {
Unregister();
}
-void XmppIqRequest::SendIq(const std::string& type,
- const std::string& addressee,
- buzz::XmlElement* iq_body) {
+void XmppIqRequest::SendIq(buzz::XmlElement* stanza) {
DCHECK_EQ(MessageLoop::current(), message_loop_);
// Unregister the handler if it is already registered.
Unregister();
- DCHECK_GT(type.length(), 0U);
-
- scoped_ptr<buzz::XmlElement> stanza(MakeIqStanza(type, addressee, iq_body,
- xmpp_client_->NextId()));
-
- xmpp_client_->engine()->SendIq(stanza.get(), this, &cookie_);
+ stanza->AddAttr(buzz::QN_ID, xmpp_client_->NextId());
+ xmpp_client_->engine()->SendIq(stanza, this, &cookie_);
}
void XmppIqRequest::set_callback(const ReplyCallback& callback) {
diff --git a/remoting/jingle_glue/xmpp_iq_request.h b/remoting/jingle_glue/xmpp_iq_request.h
index ce8d61b..8732c49 100644
--- a/remoting/jingle_glue/xmpp_iq_request.h
+++ b/remoting/jingle_glue/xmpp_iq_request.h
@@ -24,8 +24,7 @@ class XmppIqRequest : public IqRequest, public buzz::XmppIqHandler {
virtual ~XmppIqRequest();
// IqRequest interface.
- virtual void SendIq(const std::string& type, const std::string& addressee,
- buzz::XmlElement* iq_body) OVERRIDE;
+ virtual void SendIq(buzz::XmlElement* stanza) OVERRIDE;
virtual void set_callback(const ReplyCallback& callback) OVERRIDE;
// buzz::XmppIqHandler interface.