KWin
Loading...
Searching...
No Matches
onscreennotificationtest.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2016 Martin Graesslin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5
6*/
7
9
10#include "input.h"
12
13#include <KConfigGroup>
14#include <KSharedConfig>
15
16#include <QQmlEngine>
17#include <QSignalSpy>
18#include <QTest>
19
21
22namespace KWin
23{
24
28
32
33InputRedirection *InputRedirection::s_self = nullptr;
34
35}
36
38
39void OnScreenNotificationTest::show()
40{
41 OnScreenNotification notification;
42 auto config = KSharedConfig::openConfig(QString(), KSharedConfig::SimpleConfig);
43 KConfigGroup group = config->group(QStringLiteral("OnScreenNotification"));
44 group.writeEntry(QStringLiteral("QmlPath"), QString("/does/not/exist.qml"));
45 group.sync();
46 notification.setConfig(config);
47 notification.setEngine(new QQmlEngine(&notification));
48 notification.setMessage(QStringLiteral("Some text so that we see it in the test"));
49
50 QSignalSpy visibleChangedSpy(&notification, &OnScreenNotification::visibleChanged);
51 QCOMPARE(notification.isVisible(), false);
52 notification.setVisible(true);
53 QCOMPARE(notification.isVisible(), true);
54 QCOMPARE(visibleChangedSpy.count(), 1);
55
56 // show again should not trigger
57 notification.setVisible(true);
58 QCOMPARE(visibleChangedSpy.count(), 1);
59
60 // timer should not have hidden
61 QTest::qWait(500);
62 QCOMPARE(notification.isVisible(), true);
63
64 // hide again
65 notification.setVisible(false);
66 QCOMPARE(notification.isVisible(), false);
67 QCOMPARE(visibleChangedSpy.count(), 2);
68
69 // now show with timer
70 notification.setTimeout(250);
71 notification.setVisible(true);
72 QCOMPARE(notification.isVisible(), true);
73 QCOMPARE(visibleChangedSpy.count(), 3);
74 QVERIFY(visibleChangedSpy.wait());
75 QCOMPARE(notification.isVisible(), false);
76 QCOMPARE(visibleChangedSpy.count(), 4);
77}
78
79void OnScreenNotificationTest::timeout()
80{
81 OnScreenNotification notification;
82 QSignalSpy timeoutChangedSpy(&notification, &OnScreenNotification::timeoutChanged);
83 QCOMPARE(notification.timeout(), 0);
84 notification.setTimeout(1000);
85 QCOMPARE(notification.timeout(), 1000);
86 QCOMPARE(timeoutChangedSpy.count(), 1);
87 notification.setTimeout(1000);
88 QCOMPARE(timeoutChangedSpy.count(), 1);
89 notification.setTimeout(0);
90 QCOMPARE(notification.timeout(), 0);
91 QCOMPARE(timeoutChangedSpy.count(), 2);
92}
93
94void OnScreenNotificationTest::iconName()
95{
96 OnScreenNotification notification;
97 QSignalSpy iconNameChangedSpy(&notification, &OnScreenNotification::iconNameChanged);
98 QCOMPARE(notification.iconName(), QString());
99 notification.setIconName(QStringLiteral("foo"));
100 QCOMPARE(notification.iconName(), QStringLiteral("foo"));
101 QCOMPARE(iconNameChangedSpy.count(), 1);
102 notification.setIconName(QStringLiteral("foo"));
103 QCOMPARE(iconNameChangedSpy.count(), 1);
104 notification.setIconName(QStringLiteral("bar"));
105 QCOMPARE(notification.iconName(), QStringLiteral("bar"));
106 QCOMPARE(iconNameChangedSpy.count(), 2);
107}
108
109void OnScreenNotificationTest::message()
110{
111 OnScreenNotification notification;
112 QSignalSpy messageChangedSpy(&notification, &OnScreenNotification::messageChanged);
113 QCOMPARE(notification.message(), QString());
114 notification.setMessage(QStringLiteral("foo"));
115 QCOMPARE(notification.message(), QStringLiteral("foo"));
116 QCOMPARE(messageChangedSpy.count(), 1);
117 notification.setMessage(QStringLiteral("foo"));
118 QCOMPARE(messageChangedSpy.count(), 1);
119 notification.setMessage(QStringLiteral("bar"));
120 QCOMPARE(notification.message(), QStringLiteral("bar"));
121 QCOMPARE(messageChangedSpy.count(), 2);
122}
123
124#include "moc_onscreennotificationtest.cpp"
This class is responsible for redirecting incoming input to the surface which currently has input or ...
Definition input.h:70
void installInputEventSpy(InputEventSpy *spy)
void uninstallInputEventSpy(InputEventSpy *spy)
void setConfig(KSharedConfigPtr config)
void setEngine(QQmlEngine *engine)
void setIconName(const QString &iconName)
void setMessage(const QString &message)
QTEST_MAIN(OnScreenNotificationTest)