68c675d00d
Occasionally, I see complaints about the file organization of kwin, which is fair enough. This change makes the source code more relocatable by removing relative paths from includes. CMAKE_CURRENT_SOURCE_DIR was added to the interface include directories of kwin library. This means that as long as you link against kwin target, the real location of the source code of the library doesn't matter. With autotests, things are not as convenient as with kwin target. Some tests use cpp files from kwin core. If we move all source code in a src/ directory, they will need to be adjusted, but mostly only in build scripts.
126 lines
4 KiB
C++
126 lines
4 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2016 Martin Graesslin <mgraesslin@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
#include "onscreennotificationtest.h"
|
|
|
|
#include "onscreennotification.h"
|
|
#include "input.h"
|
|
|
|
#include <KSharedConfig>
|
|
#include <KConfigGroup>
|
|
|
|
#include <QQmlEngine>
|
|
#include <QSignalSpy>
|
|
#include <QTest>
|
|
|
|
QTEST_MAIN(OnScreenNotificationTest);
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
void InputRedirection::installInputEventSpy(InputEventSpy *spy)
|
|
{
|
|
Q_UNUSED(spy);
|
|
}
|
|
|
|
void InputRedirection::uninstallInputEventSpy(InputEventSpy *spy)
|
|
{
|
|
Q_UNUSED(spy);
|
|
}
|
|
|
|
InputRedirection *InputRedirection::s_self = nullptr;
|
|
|
|
}
|
|
|
|
using KWin::OnScreenNotification;
|
|
|
|
void OnScreenNotificationTest::show()
|
|
{
|
|
OnScreenNotification notification;
|
|
auto config = KSharedConfig::openConfig(QString(), KSharedConfig::SimpleConfig);
|
|
KConfigGroup group = config->group("OnScreenNotification");
|
|
group.writeEntry(QStringLiteral("QmlPath"), QString("/does/not/exist.qml"));
|
|
group.sync();
|
|
notification.setConfig(config);
|
|
notification.setEngine(new QQmlEngine(¬ification));
|
|
notification.setMessage(QStringLiteral("Some text so that we see it in the test"));
|
|
|
|
QSignalSpy visibleChangedSpy(¬ification, &OnScreenNotification::visibleChanged);
|
|
QCOMPARE(notification.isVisible(), false);
|
|
notification.setVisible(true);
|
|
QCOMPARE(notification.isVisible(), true);
|
|
QCOMPARE(visibleChangedSpy.count(), 1);
|
|
|
|
// show again should not trigger
|
|
notification.setVisible(true);
|
|
QCOMPARE(visibleChangedSpy.count(), 1);
|
|
|
|
// timer should not have hidden
|
|
QTest::qWait(500);
|
|
QCOMPARE(notification.isVisible(), true);
|
|
|
|
// hide again
|
|
notification.setVisible(false);
|
|
QCOMPARE(notification.isVisible(), false);
|
|
QCOMPARE(visibleChangedSpy.count(), 2);
|
|
|
|
// now show with timer
|
|
notification.setTimeout(250);
|
|
notification.setVisible(true);
|
|
QCOMPARE(notification.isVisible(), true);
|
|
QCOMPARE(visibleChangedSpy.count(), 3);
|
|
QVERIFY(visibleChangedSpy.wait());
|
|
QCOMPARE(notification.isVisible(), false);
|
|
QCOMPARE(visibleChangedSpy.count(), 4);
|
|
}
|
|
|
|
void OnScreenNotificationTest::timeout()
|
|
{
|
|
OnScreenNotification notification;
|
|
QSignalSpy timeoutChangedSpy(¬ification, &OnScreenNotification::timeoutChanged);
|
|
QCOMPARE(notification.timeout(), 0);
|
|
notification.setTimeout(1000);
|
|
QCOMPARE(notification.timeout(), 1000);
|
|
QCOMPARE(timeoutChangedSpy.count(), 1);
|
|
notification.setTimeout(1000);
|
|
QCOMPARE(timeoutChangedSpy.count(), 1);
|
|
notification.setTimeout(0);
|
|
QCOMPARE(notification.timeout(), 0);
|
|
QCOMPARE(timeoutChangedSpy.count(), 2);
|
|
}
|
|
|
|
void OnScreenNotificationTest::iconName()
|
|
{
|
|
OnScreenNotification notification;
|
|
QSignalSpy iconNameChangedSpy(¬ification, &OnScreenNotification::iconNameChanged);
|
|
QVERIFY(iconNameChangedSpy.isValid());
|
|
QCOMPARE(notification.iconName(), QString());
|
|
notification.setIconName(QStringLiteral("foo"));
|
|
QCOMPARE(notification.iconName(), QStringLiteral("foo"));
|
|
QCOMPARE(iconNameChangedSpy.count(), 1);
|
|
notification.setIconName(QStringLiteral("foo"));
|
|
QCOMPARE(iconNameChangedSpy.count(), 1);
|
|
notification.setIconName(QStringLiteral("bar"));
|
|
QCOMPARE(notification.iconName(), QStringLiteral("bar"));
|
|
QCOMPARE(iconNameChangedSpy.count(), 2);
|
|
}
|
|
|
|
void OnScreenNotificationTest::message()
|
|
{
|
|
OnScreenNotification notification;
|
|
QSignalSpy messageChangedSpy(¬ification, &OnScreenNotification::messageChanged);
|
|
QVERIFY(messageChangedSpy.isValid());
|
|
QCOMPARE(notification.message(), QString());
|
|
notification.setMessage(QStringLiteral("foo"));
|
|
QCOMPARE(notification.message(), QStringLiteral("foo"));
|
|
QCOMPARE(messageChangedSpy.count(), 1);
|
|
notification.setMessage(QStringLiteral("foo"));
|
|
QCOMPARE(messageChangedSpy.count(), 1);
|
|
notification.setMessage(QStringLiteral("bar"));
|
|
QCOMPARE(notification.message(), QStringLiteral("bar"));
|
|
QCOMPARE(messageChangedSpy.count(), 2);
|
|
}
|