Warning, file /plasma/kwin/autotests/tabbox/test_tabbox_clientmodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "test_tabbox_clientmodel.h"
0010 #include "../testutils.h"
0011 #include "clientmodel.h"
0012 #include "mock_tabboxhandler.h"
0013 
0014 #include <QtTest>
0015 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0016 #include <private/qtx11extras_p.h>
0017 #else
0018 #include <QX11Info>
0019 #endif
0020 using namespace KWin;
0021 
0022 void TestTabBoxClientModel::initTestCase()
0023 {
0024     qApp->setProperty("x11Connection", QVariant::fromValue<void *>(QX11Info::connection()));
0025 }
0026 
0027 void TestTabBoxClientModel::testLongestCaptionWithNullClient()
0028 {
0029     MockTabBoxHandler tabboxhandler;
0030     TabBox::ClientModel *clientModel = new TabBox::ClientModel(&tabboxhandler);
0031     clientModel->createClientList();
0032     QCOMPARE(clientModel->longestCaption(), QString());
0033     // add a window to the mock
0034     tabboxhandler.createMockWindow(QString("test"));
0035     clientModel->createClientList();
0036     QCOMPARE(clientModel->longestCaption(), QString("test"));
0037     // delete the one client in the list
0038     QModelIndex index = clientModel->index(0, 0);
0039     QVERIFY(index.isValid());
0040     TabBox::TabBoxClient *client = static_cast<TabBox::TabBoxClient *>(clientModel->data(index, TabBox::ClientModel::ClientRole).value<void *>());
0041     client->close();
0042     // internal model of ClientModel now contains a deleted pointer
0043     // longestCaption should behave just as if the window were not in the list
0044     QCOMPARE(clientModel->longestCaption(), QString());
0045 }
0046 
0047 void TestTabBoxClientModel::testCreateClientListNoActiveClient()
0048 {
0049     MockTabBoxHandler tabboxhandler;
0050     tabboxhandler.setConfig(TabBox::TabBoxConfig());
0051     TabBox::ClientModel *clientModel = new TabBox::ClientModel(&tabboxhandler);
0052     clientModel->createClientList();
0053     QCOMPARE(clientModel->rowCount(), 0);
0054     // create two windows, rowCount() should go to two
0055     QWeakPointer<TabBox::TabBoxClient> client = tabboxhandler.createMockWindow(QString("test"));
0056     tabboxhandler.createMockWindow(QString("test2"));
0057     clientModel->createClientList();
0058     QCOMPARE(clientModel->rowCount(), 2);
0059     // let's ensure there is no active client
0060     tabboxhandler.setActiveClient(QWeakPointer<TabBox::TabBoxClient>());
0061     // now it should still have two members in the list
0062     clientModel->createClientList();
0063     QCOMPARE(clientModel->rowCount(), 2);
0064 }
0065 
0066 void TestTabBoxClientModel::testCreateClientListActiveClientNotInFocusChain()
0067 {
0068     MockTabBoxHandler tabboxhandler;
0069     tabboxhandler.setConfig(TabBox::TabBoxConfig());
0070     TabBox::ClientModel *clientModel = new TabBox::ClientModel(&tabboxhandler);
0071     // create two windows, rowCount() should go to two
0072     QWeakPointer<TabBox::TabBoxClient> client = tabboxhandler.createMockWindow(QString("test"));
0073     client = tabboxhandler.createMockWindow(QString("test2"));
0074     clientModel->createClientList();
0075     QCOMPARE(clientModel->rowCount(), 2);
0076 
0077     // simulate that the active client is not in the focus chain
0078     // for that we use the closeWindow of the MockTabBoxHandler which
0079     // removes the Client from the Focus Chain but leaves the active window as it is
0080     QSharedPointer<TabBox::TabBoxClient> clientOwner = client.toStrongRef();
0081     tabboxhandler.closeWindow(clientOwner.get());
0082     clientModel->createClientList();
0083     QCOMPARE(clientModel->rowCount(), 1);
0084 }
0085 
0086 Q_CONSTRUCTOR_FUNCTION(forceXcb)
0087 QTEST_MAIN(TestTabBoxClientModel)