3 * Copyright 2011, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "talk/xmllite/xmlelement.h"
32 #include "talk/xmpp/constants.h"
33 #include "talk/xmpp/fakexmppclient.h"
34 #include "talk/xmpp/mucroomconfigtask.h"
35 #include "webrtc/base/faketaskrunner.h"
36 #include "webrtc/base/gunit.h"
37 #include "webrtc/base/sigslot.h"
39 class MucRoomConfigListener : public sigslot::has_slots<> {
41 MucRoomConfigListener() : result_count(0), error_count(0) {}
43 void OnResult(buzz::MucRoomConfigTask*) {
47 void OnError(buzz::IqTask* task,
48 const buzz::XmlElement* error) {
56 class MucRoomConfigTaskTest : public testing::Test {
58 MucRoomConfigTaskTest() :
59 room_jid("muc-jid-ponies@domain.com"),
63 virtual void SetUp() {
64 runner = new rtc::FakeTaskRunner();
65 xmpp_client = new buzz::FakeXmppClient(runner);
66 listener = new MucRoomConfigListener();
69 virtual void TearDown() {
71 // delete xmpp_client; Deleted by deleting runner.
75 rtc::FakeTaskRunner* runner;
76 buzz::FakeXmppClient* xmpp_client;
77 MucRoomConfigListener* listener;
79 std::string room_name;
82 TEST_F(MucRoomConfigTaskTest, TestConfigEnterprise) {
83 ASSERT_EQ(0U, xmpp_client->sent_stanzas().size());
85 std::vector<std::string> room_features;
86 room_features.push_back("feature1");
87 room_features.push_back("feature2");
88 buzz::MucRoomConfigTask* task = new buzz::MucRoomConfigTask(
89 xmpp_client, room_jid, "ponies", room_features);
90 EXPECT_EQ(room_jid, task->room_jid());
92 task->SignalResult.connect(listener, &MucRoomConfigListener::OnResult);
95 std::string expected_iq =
96 "<cli:iq type=\"set\" to=\"muc-jid-ponies@domain.com\" id=\"0\" "
97 "xmlns:cli=\"jabber:client\">"
98 "<query xmlns=\"http://jabber.org/protocol/muc#owner\">"
99 "<x xmlns=\"jabber:x:data\" type=\"form\">"
100 "<field var=\"muc#roomconfig_roomname\" type=\"text-single\">"
101 "<value>ponies</value>"
103 "<field var=\"muc#roomconfig_features\" type=\"list-multi\">"
104 "<value>feature1</value>"
105 "<value>feature2</value>"
111 ASSERT_EQ(1U, xmpp_client->sent_stanzas().size());
112 EXPECT_EQ(expected_iq, xmpp_client->sent_stanzas()[0]->Str());
114 EXPECT_EQ(0, listener->result_count);
115 EXPECT_EQ(0, listener->error_count);
117 std::string response_iq =
118 "<iq xmlns='jabber:client' id='0' type='result'"
119 " from='muc-jid-ponies@domain.com'>"
122 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(response_iq));
124 EXPECT_EQ(1, listener->result_count);
125 EXPECT_EQ(0, listener->error_count);
128 TEST_F(MucRoomConfigTaskTest, TestError) {
129 std::vector<std::string> room_features;
130 buzz::MucRoomConfigTask* task = new buzz::MucRoomConfigTask(
131 xmpp_client, room_jid, "ponies", room_features);
132 task->SignalError.connect(listener, &MucRoomConfigListener::OnError);
135 std::string error_iq =
136 "<iq xmlns='jabber:client' id='0' type='error'"
137 " from='muc-jid-ponies@domain.com'>"
140 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(error_iq));
142 EXPECT_EQ(0, listener->result_count);
143 EXPECT_EQ(1, listener->error_count);