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.
5 #include "jingle/notifier/listener/push_notifications_send_update_task.h"
7 #include "base/base64.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/stringprintf.h"
10 #include "jingle/notifier/listener/xml_element_util.h"
11 #include "talk/xmpp/jid.h"
12 #include "testing/gtest/include/gtest/gtest.h"
20 class PushNotificationsSendUpdateTaskTest : public testing::Test {
22 PushNotificationsSendUpdateTaskTest() : to_jid_bare_("to@jid.com") {
23 EXPECT_EQ(to_jid_bare_.Str(), to_jid_bare_.BareJid().Str());
27 const buzz::Jid to_jid_bare_;
30 DISALLOW_COPY_AND_ASSIGN(PushNotificationsSendUpdateTaskTest);
33 TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) {
34 Notification notification;
35 notification.channel = "test_channel";
36 notification.data = "test_data";
38 std::string base64_data;
39 EXPECT_TRUE(base::Base64Encode(notification.data, &base64_data));
41 scoped_ptr<buzz::XmlElement> message(
42 PushNotificationsSendUpdateTask::MakeUpdateMessage(
43 notification, to_jid_bare_));
45 std::string expected_xml_string =
47 "<cli:message to=\"%s\" type=\"headline\" "
48 "xmlns:cli=\"jabber:client\">"
49 "<push xmlns=\"google:push\" channel=\"%s\">"
50 "<data xmlns=\"google:push\">%s</data>"
53 to_jid_bare_.Str().c_str(), notification.channel.c_str(),
55 EXPECT_EQ(expected_xml_string, XmlElementToString(*message));
58 } // namespace notifier