- add sources.
[platform/framework/web/crosswalk.git] / src / jingle / notifier / listener / push_notifications_subscribe_task_unittest.cc
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "jingle/notifier/listener/push_notifications_subscribe_task.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/stringprintf.h"
9 #include "jingle/notifier/listener/xml_element_util.h"
10 #include "talk/xmpp/jid.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace buzz {
14 class XmlElement;
15 }
16
17 namespace notifier {
18
19 class PushNotificationsSubscribeTaskTest : public testing::Test {
20  public:
21   PushNotificationsSubscribeTaskTest()
22       : jid_("to@jid.com/test123"), task_id_("taskid") {
23     EXPECT_NE(jid_.Str(), jid_.BareJid().Str());
24   }
25
26  protected:
27   const buzz::Jid jid_;
28   const std::string task_id_;
29
30  private:
31   DISALLOW_COPY_AND_ASSIGN(PushNotificationsSubscribeTaskTest);
32 };
33
34 TEST_F(PushNotificationsSubscribeTaskTest, MakeSubscriptionMessage) {
35   SubscriptionList subscriptions;
36
37   Subscription subscription;
38   subscription.channel = "test_channel1";
39   subscription.from = "from.test.com";
40   subscriptions.push_back(subscription);
41   subscription.channel = "test_channel2";
42   subscription.from = "from.test2.com";
43   subscriptions.push_back(subscription);
44   scoped_ptr<buzz::XmlElement> message(
45       PushNotificationsSubscribeTask::MakeSubscriptionMessage(
46           subscriptions, jid_, task_id_));
47   std::string expected_xml_string =
48       base::StringPrintf(
49           "<cli:iq type=\"set\" to=\"%s\" id=\"%s\" "
50                   "xmlns:cli=\"jabber:client\">"
51             "<subscribe xmlns=\"google:push\">"
52               "<item channel=\"test_channel1\" from=\"from.test.com\"/>"
53               "<item channel=\"test_channel2\" from=\"from.test2.com\"/>"
54             "</subscribe>"
55           "</cli:iq>",
56           jid_.BareJid().Str().c_str(), task_id_.c_str());
57
58   EXPECT_EQ(expected_xml_string, XmlElementToString(*message));
59 }
60
61 }  // namespace notifier
62