Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1578)

Side by Side Diff: chrome/browser/notifications/notification_template_builder_unittest.cc

Issue 2920303002: Add a NotificationTemplateBuilder for Action Center toasts (Closed)
Patch Set: remove libxml usage from the test Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/notifications/notification_template_builder.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "chrome/browser/notifications/notification_template_builder.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/message_center/notification.h"
15
16 using message_center::Notification;
17 using message_center::NotifierId;
18 using message_center::RichNotificationData;
19
20 namespace {
21
22 const char kNotificationId[] = "notification_id";
23 const char kNotificationTitle[] = "My Title";
24 const char kNotificationMessage[] = "My Message";
25 const char kNotificationOrigin[] = "https://example.com";
26
27 // Intermediary format for the options available when creating a notification,
28 // with default values specific to this test suite to avoid endless repetition.
29 struct NotificationData {
30 NotificationData()
31 : id(kNotificationId),
32 title(kNotificationTitle),
33 message(kNotificationMessage),
34 origin(kNotificationOrigin) {}
35
36 std::string id;
37 std::string title;
38 std::string message;
39 GURL origin;
40 };
41
42 } // namespace
43
44 class NotificationTemplateBuilderTest : public ::testing::Test {
45 public:
46 NotificationTemplateBuilderTest() = default;
47 ~NotificationTemplateBuilderTest() override = default;
48
49 protected:
50 // Builds the message_center::Notification object and then the template for
51 // the given |notification_data|, and writes that to |*xml_template|. Calls
52 // must be wrapped in ASSERT_NO_FATAL_FAILURE().
53 void BuildTemplate(const NotificationData& notification_data,
54 std::string* xml_template) {
55 GURL origin_url(notification_data.origin);
56
57 Notification notification(
58 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.id,
59 base::UTF8ToUTF16(notification_data.title),
60 base::UTF8ToUTF16(notification_data.message), gfx::Image() /* icon */,
61 base::string16() /* display_source */, origin_url,
62 NotifierId(origin_url), RichNotificationData(), nullptr /* delegate */);
63
64 template_ =
65 NotificationTemplateBuilder::Build(notification_data.id, notification);
66 ASSERT_TRUE(template_);
67
68 *xml_template = template_->GetNotificationTemplate();
69 }
70
71 protected:
72 std::unique_ptr<NotificationTemplateBuilder> template_;
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(NotificationTemplateBuilderTest);
76 };
77
78 TEST_F(NotificationTemplateBuilderTest, SimpleToast) {
79 NotificationData notification_data;
80 std::string xml_template;
81
82 ASSERT_NO_FATAL_FAILURE(BuildTemplate(notification_data, &xml_template));
83
84 const char kExpectedXml[] = R"(<toast launch="notification_id">
85 <visual>
86 <binding template="ToastText04">
87 <text id="1">My Title</text>
88 <text id="2">My Message</text>
89 <text id="3">example.com</text>
90 </binding>
91 </visual>
92 </toast>
93 )";
94
95 EXPECT_EQ(xml_template, kExpectedXml);
96 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_template_builder.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698