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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Ted Gould <ted@canonical.com>
*/
#include <gtest/gtest.h>
#include <gio/gio.h>
#include "indicator-fixture.h"
#include "accounts-service-mock.h"
#include "messaging-menu-app.h"
#include "messaging-menu-message.h"
class IndicatorTest : public IndicatorFixture
{
protected:
IndicatorTest (void) :
IndicatorFixture(INDICATOR_MESSAGES_SERVICE_BINARY, "org.ayatana.indicator.messages")
{
}
std::shared_ptr<AccountsServiceMock> as;
virtual void SetUp() override
{
g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
g_setenv("GSETTINGS_BACKEND", "memory", TRUE);
g_setenv("XDG_DATA_DIRS", XDG_DATA_DIRS, TRUE);
as = std::make_shared<AccountsServiceMock>();
addMock(*as);
IndicatorFixture::SetUp();
}
virtual void TearDown() override
{
as.reset();
IndicatorFixture::TearDown();
}
};
TEST_F(IndicatorTest, RootAction) {
setActions("/org/ayatana/indicator/messages");
EXPECT_EVENTUALLY_ACTION_EXISTS("messages");
EXPECT_ACTION_STATE_TYPE("messages", G_VARIANT_TYPE("a{sv}"));
EXPECT_ACTION_STATE("messages", g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-offline', 'indicator-messages', 'indicator']>)>, 'title': <'Notifications'>, 'accessible-desc': <'Messages'>, 'visible': <false>}"));
}
TEST_F(IndicatorTest, SingleMessage) {
setActions("/org/ayatana/indicator/messages");
auto app = std::shared_ptr<MessagingMenuApp>(messaging_menu_app_new("test.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); });
ASSERT_NE(nullptr, app);
messaging_menu_app_register(app.get());
EXPECT_EVENTUALLY_ACTION_EXISTS("test.launch");
auto msg = std::shared_ptr<MessagingMenuMessage>(messaging_menu_message_new(
"testid",
nullptr, /* no icon */
"Test Title",
"A subtitle too",
"You only like me for my body",
0), [](MessagingMenuMessage * msg) { g_clear_object(&msg); });
messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE);
EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg.testid");
setMenu("/org/ayatana/indicator/messages/phone");
EXPECT_EVENTUALLY_MENU_ATTRIB(std::vector<int>({0, 0, 0}), "x-canonical-type", "org.ayatana.indicator.messages.messageitem");
EXPECT_MENU_ATTRIB(std::vector<int>({0, 0, 0}), "label", "Test Title");
EXPECT_MENU_ATTRIB(std::vector<int>({0, 0, 0}), "x-canonical-message-id", "testid");
EXPECT_MENU_ATTRIB(std::vector<int>({0, 0, 0}), "x-canonical-subtitle", "A subtitle too");
EXPECT_MENU_ATTRIB(std::vector<int>({0, 0, 0}), "x-canonical-text", "You only like me for my body");
}
static void
messageReplyActivate (GObject * obj, gchar * name, GVariant * value, gpointer user_data) {
auto res = reinterpret_cast<std::string *>(user_data);
*res = g_variant_get_string(value, nullptr);
}
TEST_F(IndicatorTest, MessageReply) {
setActions("/org/ayatana/indicator/messages");
auto app = std::shared_ptr<MessagingMenuApp>(messaging_menu_app_new("test.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); });
ASSERT_NE(nullptr, app);
messaging_menu_app_register(app.get());
EXPECT_EVENTUALLY_ACTION_EXISTS("test.launch");
auto msg = std::shared_ptr<MessagingMenuMessage>(messaging_menu_message_new(
"messageid",
nullptr, /* no icon */
"Reply Message",
"A message to reply to",
"In-app replies are for wimps, reply here to save yourself time and be cool.",
0), [](MessagingMenuMessage * msg) { g_clear_object(&msg); });
messaging_menu_message_add_action(msg.get(),
"replyid",
"Reply",
G_VARIANT_TYPE_STRING,
nullptr);
messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE);
EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg.messageid");
EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg-actions.messageid.replyid");
EXPECT_ACTION_ACTIVATION_TYPE("test.msg-actions.messageid.replyid", G_VARIANT_TYPE_STRING);
EXPECT_ACTION_ENABLED("remove-all", true);
setMenu("/org/ayatana/indicator/messages/phone");
EXPECT_EVENTUALLY_MENU_ATTRIB(std::vector<int>({0, 0, 0}), "x-canonical-type", "org.ayatana.indicator.messages.messageitem");
std::string activateResponse;
g_signal_connect(msg.get(), "activate", G_CALLBACK(messageReplyActivate), &activateResponse);
activateAction("test.msg-actions.messageid.replyid", g_variant_new_string("Reply to me"));
EXPECT_EVENTUALLY_EQ("Reply to me", activateResponse);
EXPECT_EVENTUALLY_ACTION_ENABLED("remove-all", false);
}
TEST_F(IndicatorTest, IconNotification) {
auto normalicon = std::shared_ptr<GVariant>(g_variant_ref_sink(g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-offline', 'indicator-messages', 'indicator']>)>, 'title': <'Notifications'>, 'accessible-desc': <'Messages'>, 'visible': <true>}")), [](GVariant *var) {if (var != nullptr) g_variant_unref(var); });
auto blueicon = std::shared_ptr<GVariant>(g_variant_ref_sink(g_variant_new_parsed("{'icon': <('themed', <['indicator-messages-new-offline', 'indicator-messages-new', 'indicator-messages', 'indicator']>)>, 'title': <'Notifications'>, 'accessible-desc': <'New Messages'>, 'visible': <true>}")), [](GVariant *var) {if (var != nullptr) g_variant_unref(var); });
setActions("/org/ayatana/indicator/messages");
auto app = std::shared_ptr<MessagingMenuApp>(messaging_menu_app_new("test.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); });
ASSERT_NE(nullptr, app);
messaging_menu_app_register(app.get());
EXPECT_EVENTUALLY_ACTION_EXISTS("test.launch");
EXPECT_ACTION_STATE("messages", normalicon);
auto app2 = std::shared_ptr<MessagingMenuApp>(messaging_menu_app_new("test2.desktop"), [](MessagingMenuApp * app) { g_clear_object(&app); });
ASSERT_NE(nullptr, app2);
messaging_menu_app_register(app2.get());
EXPECT_EVENTUALLY_ACTION_EXISTS("test2.launch");
messaging_menu_app_append_source_with_count(app2.get(),
"countsource",
nullptr,
"Count Source",
500);
messaging_menu_app_draw_attention(app2.get(), "countsource");
EXPECT_EVENTUALLY_ACTION_STATE("messages", blueicon);
auto msg = std::shared_ptr<MessagingMenuMessage>(messaging_menu_message_new(
"messageid",
nullptr, /* no icon */
"Message",
"A secret message",
"asdfa;lkweraoweprijas;dvlknasvdoiewur;aslkd",
0), [](MessagingMenuMessage * msg) { g_clear_object(&msg); });
messaging_menu_message_set_draws_attention(msg.get(), true);
messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE);
EXPECT_EVENTUALLY_ACTION_EXISTS("test.msg.messageid");
EXPECT_ACTION_STATE("messages", blueicon);
messaging_menu_app_unregister(app2.get());
app2.reset();
EXPECT_EVENTUALLY_ACTION_DOES_NOT_EXIST("test2.msg.countsource");
EXPECT_ACTION_STATE("messages", blueicon);
messaging_menu_app_remove_message(app.get(), msg.get());
EXPECT_EVENTUALLY_ACTION_STATE("messages", normalicon);
EXPECT_ACTION_ENABLED("remove-all", false);
messaging_menu_app_append_message(app.get(), msg.get(), nullptr, FALSE);
EXPECT_EVENTUALLY_ACTION_STATE("messages", blueicon);
EXPECT_ACTION_ENABLED("remove-all", true);
activateAction("remove-all");
EXPECT_EVENTUALLY_ACTION_STATE("messages", normalicon);
}
|