File: dialogstatetest.cpp

package info (click to toggle)
plasma-framework 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,088 kB
  • sloc: cpp: 29,562; javascript: 637; sh: 517; python: 145; xml: 110; php: 27; makefile: 7
file content (97 lines) | stat: -rw-r--r-- 2,317 bytes parent folder | download | duplicates (3)
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
/*
    SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "dialogstatetest.h"
#include <KWindowInfo>
#include <KX11Extras>

#include <QSignalSpy>

void DialogStateTest::initTestCase()
{
    m_dialog = new PlasmaQuick::Dialog;
    m_dialog->setLocation(Plasma::Types::TopEdge);
    m_dialog->setGeometry(0, 0, 50, 50);

    qRegisterMetaType<WId>("WId");
}

void DialogStateTest::cleanupTestCase()
{
    delete m_dialog;
}

void DialogStateTest::windowState()
{
    if (QGuiApplication::platformName() == "wayland") {
        QEXPECT_FAIL("windowState", "KX11Extras::windowAdded doesn't work on wayland", Continue);
        return;
    }

    for (int i = 0; i <= 100; ++i) {
        m_dialog->show();

        QSignalSpy windowAddedSpy(KX11Extras::self(), &KX11Extras::windowAdded);
        QVERIFY(windowAddedSpy.isValid());
        QVERIFY(windowAddedSpy.wait());

        bool windowAdded = false;

        while (windowAddedSpy.count()) {
            const QVariantList &arguments = windowAddedSpy.takeFirst();

            if (arguments.at(0).value<WId>() == m_dialog->winId()) {
                windowAdded = true;
                break;
            }
            if (windowAddedSpy.isEmpty()) {
                QVERIFY(windowAddedSpy.wait());
            }
        }

        QVERIFY(windowAdded);

        QVERIFY(verifyState(m_dialog));

        m_dialog->hide();

        QSignalSpy windowRemovedSpy(KX11Extras::self(), &KX11Extras::windowRemoved);
        QVERIFY(windowRemovedSpy.isValid());
        QVERIFY(windowRemovedSpy.wait());

        bool windowRemoved = false;

        while (windowRemovedSpy.count()) {
            const QVariantList &arguments = windowRemovedSpy.takeFirst();

            if (arguments.at(0).value<WId>() == m_dialog->winId()) {
                windowRemoved = true;
                break;
            }
        }

        QVERIFY(windowRemoved);
    }
}

bool DialogStateTest::verifyState(PlasmaQuick::Dialog *dialog) const
{
    KWindowInfo info(dialog->winId(), NET::WMState);

    if (!(info.state() & NET::SkipTaskbar)) {
        return false;
    }

    if (!info.hasState(NET::SkipPager)) {
        return false;
    }

    return true;
}

QTEST_MAIN(DialogStateTest)

#include "moc_dialogstatetest.cpp"