summaryrefslogtreecommitdiff
path: root/chromium/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc
blob: c57bd93c2dae8ee15a84dac88e916ed8a6d9a398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "jingle/notifier/listener/push_notifications_send_update_task.h"

#include "base/base64.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "jingle/notifier/listener/xml_element_util.h"
#include "talk/xmpp/jid.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace buzz {
class XmlElement;
}

namespace notifier {

class PushNotificationsSendUpdateTaskTest : public testing::Test {
 public:
  PushNotificationsSendUpdateTaskTest() : to_jid_bare_("to@jid.com") {
    EXPECT_EQ(to_jid_bare_.Str(), to_jid_bare_.BareJid().Str());
  }

 protected:
  const buzz::Jid to_jid_bare_;

 private:
  DISALLOW_COPY_AND_ASSIGN(PushNotificationsSendUpdateTaskTest);
};

TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) {
  Notification notification;
  notification.channel = "test_channel";
  notification.data = "test_data";

  std::string base64_data;
  EXPECT_TRUE(base::Base64Encode(notification.data, &base64_data));

  scoped_ptr<buzz::XmlElement> message(
      PushNotificationsSendUpdateTask::MakeUpdateMessage(
          notification, to_jid_bare_));

  std::string expected_xml_string =
      base::StringPrintf(
          "<cli:message to=\"%s\" type=\"headline\" "
              "xmlns:cli=\"jabber:client\">"
            "<push xmlns=\"google:push\" channel=\"%s\">"
              "<data xmlns=\"google:push\">%s</data>"
            "</push>"
          "</cli:message>",
          to_jid_bare_.Str().c_str(), notification.channel.c_str(),
          base64_data.c_str());
  EXPECT_EQ(expected_xml_string, XmlElementToString(*message));
}

}  // namespace notifier