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 "webrtc/libjingle/xmllite/xmlelement.h"
32 #include "talk/xmpp/constants.h"
33 #include "talk/xmpp/fakexmppclient.h"
34 #include "talk/xmpp/mucroomuniquehangoutidtask.h"
35 #include "webrtc/base/faketaskrunner.h"
36 #include "webrtc/base/gunit.h"
37 #include "webrtc/base/sigslot.h"
39 class MucRoomUniqueHangoutIdListener : public sigslot::has_slots<> {
41 MucRoomUniqueHangoutIdListener() : error_count(0) {}
43 void OnResult(buzz::MucRoomUniqueHangoutIdTask* task,
44 const std::string& hangout_id) {
45 last_hangout_id = hangout_id;
48 void OnError(buzz::IqTask* task,
49 const buzz::XmlElement* error) {
53 std::string last_hangout_id;
57 class MucRoomUniqueHangoutIdTaskTest : public testing::Test {
59 MucRoomUniqueHangoutIdTaskTest() :
60 lookup_server_jid("lookup@domain.com"),
61 hangout_id("some_hangout_id") {
64 virtual void SetUp() {
65 runner = new rtc::FakeTaskRunner();
66 xmpp_client = new buzz::FakeXmppClient(runner);
67 listener = new MucRoomUniqueHangoutIdListener();
70 virtual void TearDown() {
72 // delete xmpp_client; Deleted by deleting runner.
76 rtc::FakeTaskRunner* runner;
77 buzz::FakeXmppClient* xmpp_client;
78 MucRoomUniqueHangoutIdListener* listener;
79 buzz::Jid lookup_server_jid;
80 std::string hangout_id;
83 TEST_F(MucRoomUniqueHangoutIdTaskTest, Test) {
84 ASSERT_EQ(0U, xmpp_client->sent_stanzas().size());
86 buzz::MucRoomUniqueHangoutIdTask* task = new buzz::MucRoomUniqueHangoutIdTask(
87 xmpp_client, lookup_server_jid);
88 task->SignalResult.connect(listener, &MucRoomUniqueHangoutIdListener::OnResult);
91 std::string expected_iq =
92 "<cli:iq type=\"get\" to=\"lookup@domain.com\" id=\"0\" "
93 "xmlns:cli=\"jabber:client\">"
94 "<uni:unique hangout-id=\"true\" "
95 "xmlns:uni=\"http://jabber.org/protocol/muc#unique\"/>"
98 ASSERT_EQ(1U, xmpp_client->sent_stanzas().size());
99 EXPECT_EQ(expected_iq, xmpp_client->sent_stanzas()[0]->Str());
101 EXPECT_EQ("", listener->last_hangout_id);
103 std::string response_iq =
104 "<iq xmlns='jabber:client' from='lookup@domain.com' id='0' type='result'>"
105 "<unique hangout-id=\"some_hangout_id\" "
106 "xmlns=\"http://jabber.org/protocol/muc#unique\">"
107 "muvc-private-chat-00001234-5678-9abc-def0-123456789abc"
111 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(response_iq));
113 EXPECT_EQ(hangout_id, listener->last_hangout_id);
114 EXPECT_EQ(0, listener->error_count);