Home | History | Annotate | Download | only in listener
      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_send_update_task.h"
      6 
      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"
     13 
     14 namespace buzz {
     15 class XmlElement;
     16 }
     17 
     18 namespace notifier {
     19 
     20 class PushNotificationsSendUpdateTaskTest : public testing::Test {
     21  public:
     22   PushNotificationsSendUpdateTaskTest() : to_jid_bare_("to (at) jid.com") {
     23     EXPECT_EQ(to_jid_bare_.Str(), to_jid_bare_.BareJid().Str());
     24   }
     25 
     26  protected:
     27   const buzz::Jid to_jid_bare_;
     28 
     29  private:
     30   DISALLOW_COPY_AND_ASSIGN(PushNotificationsSendUpdateTaskTest);
     31 };
     32 
     33 TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) {
     34   Notification notification;
     35   notification.channel = "test_channel";
     36   notification.data = "test_data";
     37 
     38   std::string base64_data;
     39   base::Base64Encode(notification.data, &base64_data);
     40 
     41   scoped_ptr<buzz::XmlElement> message(
     42       PushNotificationsSendUpdateTask::MakeUpdateMessage(
     43           notification, to_jid_bare_));
     44 
     45   std::string expected_xml_string =
     46       base::StringPrintf(
     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>"
     51             "</push>"
     52           "</cli:message>",
     53           to_jid_bare_.Str().c_str(), notification.channel.c_str(),
     54           base64_data.c_str());
     55   EXPECT_EQ(expected_xml_string, XmlElementToString(*message));
     56 }
     57 
     58 }  // namespace notifier
     59