Warning, file /plasma/plasma-workspace/libtaskmanager/autotests/tasksmodeltest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include <QQmlApplicationEngine> 0008 #include <QtTest> 0009 0010 #include "abstracttasksmodel.h" // For enums 0011 #include "tasksmodel.h" 0012 0013 using namespace TaskManager; 0014 0015 class TasksModelTest : public QObject 0016 { 0017 Q_OBJECT 0018 0019 private Q_SLOTS: 0020 void initTestCase(); 0021 0022 /** 0023 * Test moving a launcher in the 'Task Manager' with "Keep launchers separate", 0024 * "Group by program name", "Launch in place" and Manual sorting 0025 * @see https://bugs.kde.org/472524 0026 */ 0027 void test_moveLauncherBug472524(); 0028 0029 /** 0030 * Task manager open entries jump around when pinned apps are moved 0031 * in the 'Task Manager' with "Keep launchers separate" option 0032 * unchecked 0033 * @see https://bugs.kde.org/444816 0034 */ 0035 void test_moveBug444816(); 0036 0037 /** 0038 * Pinned apps with a preferred://[something] URI that resolves to nothing should be hidden 0039 * 0040 * @see https://bugs.kde.org/436667 0041 */ 0042 void test_filterOutInvalidPreferredLaunchers(); 0043 }; 0044 0045 void TasksModelTest::initTestCase() 0046 { 0047 QGuiApplication::setQuitOnLastWindowClosed(false); 0048 } 0049 0050 void TasksModelTest::test_moveLauncherBug472524() 0051 { 0052 // Prepare two launchers and swap them 0053 TasksModel model; 0054 0055 // Follow required settings in BUG 472524 0056 model.setSeparateLaunchers(true); 0057 model.setGroupMode(TasksModel::GroupApplications); 0058 model.setLaunchInPlace(true); 0059 model.setSortMode(TasksModel::SortManual); 0060 0061 QSignalSpy rowInsertedSpy(&model, &TasksModel::rowsInserted); 0062 0063 int rowCount = model.rowCount(); 0064 QVERIFY(model.launcherList().empty()); 0065 const QUrl launcherUrl = QUrl::fromLocalFile(QFINDTESTDATA("data/applications/GammaRay.desktop")); 0066 const QUrl launcherUrl2 = QUrl::fromLocalFile(QFINDTESTDATA("data/applications/org.kde.gwenview_importer.desktop")); 0067 model.setLauncherList(QStringList{launcherUrl.toString(), launcherUrl2.toString()}); 0068 0069 // Both launchers are added as expected 0070 QCOMPARE(model.launcherList().size(), 2); 0071 QCOMPARE(model.rowCount(), rowCount + 2); 0072 0073 // The launchers are in the expected positions 0074 QCOMPARE(model.index(0, 0).data(Qt::DisplayRole).toString(), QStringLiteral("GammaRay")); 0075 QCOMPARE(model.index(1, 0).data(Qt::DisplayRole).toString(), QStringLiteral("Gwenview Importer")); 0076 0077 // Swap the first and second launcher 0078 QVERIFY(model.move(0, 1)); 0079 QCoreApplication::processEvents(); 0080 0081 // The launchers are swapped 0082 QCOMPARE(model.index(0, 0).data(Qt::DisplayRole).toString(), QStringLiteral("Gwenview Importer")); 0083 QCOMPARE(model.index(1, 0).data(Qt::DisplayRole).toString(), QStringLiteral("GammaRay")); 0084 } 0085 0086 void TasksModelTest::test_moveBug444816() 0087 { 0088 // Prepare launchers and running tasks 0089 TasksModel model; 0090 0091 // Follow required settings in BUG 444816 0092 model.setGroupMode(TasksModel::GroupDisabled); 0093 model.setSeparateLaunchers(false); 0094 model.setSortMode(TasksModel::SortManual); 0095 0096 QSignalSpy rowInsertedSpy(&model, &TasksModel::rowsInserted); 0097 0098 int rowCount = model.rowCount(); 0099 QVERIFY(model.launcherList().empty()); 0100 const QUrl launcherUrl = QUrl::fromLocalFile(QFINDTESTDATA("data/applications/GammaRay.desktop")); 0101 model.setLauncherList(QStringList{launcherUrl.toString()}); 0102 // A launcher is added as expected 0103 QCOMPARE(model.launcherList().size(), 1); 0104 QCOMPARE(++rowCount, model.rowCount()); 0105 0106 // Create two new windows 0107 QVariantMap firstWindowProperties; 0108 firstWindowProperties.insert(QStringLiteral("title"), QStringLiteral("__testwindow__firstwindow__")); 0109 QVariantMap secondWindowProperties; 0110 secondWindowProperties.insert(QStringLiteral("title"), QStringLiteral("__testwindow__secondwindow__")); 0111 QVariantMap initialProperties; 0112 initialProperties.insert(QStringLiteral("windowInitialProperties"), QVariantList{firstWindowProperties, secondWindowProperties}); 0113 0114 QQmlApplicationEngine engine; 0115 engine.setInitialProperties(initialProperties); 0116 const QString qmlFileName = QFINDTESTDATA("data/windows/ManyWindows.qml"); 0117 engine.load(qmlFileName); 0118 0119 // Make sure two new windows have been created 0120 for (int i = 0; i < initialProperties[QStringLiteral("windowInitialProperties")].toList().size(); ++i) { 0121 rowInsertedSpy.wait(1000); 0122 } 0123 QCOMPARE(++ ++rowCount, model.rowCount()); 0124 0125 // TasksModel now looks like: [Launcher] [...] [__testwindow__firstwindow__] [__testwindow__secondwindow__] 0126 // This test tries to move [Launcher] to the position between the two tasks 0127 int launcherRow = -1; 0128 for (int i = 0; i < model.rowCount(); ++i) { 0129 if (model.index(i, 0).data(AbstractTasksModel::IsLauncher).toBool()) { 0130 launcherRow = i; 0131 break; 0132 } 0133 } 0134 QVERIFY(launcherRow >= 0); 0135 0136 int firstWindowRow = -1; 0137 for (int i = 0; i < model.rowCount(); ++i) { 0138 if (model.index(i, 0).data(Qt::DisplayRole).toString() == firstWindowProperties[QStringLiteral("title")]) { 0139 firstWindowRow = i; 0140 break; 0141 } 0142 } 0143 QVERIFY(firstWindowRow >= 0); 0144 0145 qDebug() << "********* BEGIN Before *********"; 0146 for (int i = 0; i < model.rowCount(); ++i) { 0147 qDebug() << i << model.index(i, 0).data(Qt::DisplayRole).toString(); 0148 } 0149 qDebug() << "********* End Before *********"; 0150 0151 QVERIFY(model.move(launcherRow, firstWindowRow)); 0152 QCoreApplication::processEvents(); 0153 0154 // Verify the order 0155 for (int i = 0; i < model.rowCount(); ++i) { 0156 if (model.index(i, 0).data(AbstractTasksModel::IsLauncher).toBool()) { 0157 launcherRow = i; 0158 break; 0159 } 0160 } 0161 for (int i = 0; i < model.rowCount(); ++i) { 0162 if (model.index(i, 0).data(Qt::DisplayRole).toString() == firstWindowProperties[QStringLiteral("title")]) { 0163 firstWindowRow = i; 0164 break; 0165 } 0166 } 0167 0168 qDebug() << "********* BEGIN After *********"; 0169 for (int i = 0; i < model.rowCount(); ++i) { 0170 qDebug() << i << model.index(i, 0).data(Qt::DisplayRole).toString(); 0171 } 0172 qDebug() << "********* END After *********"; 0173 0174 QCOMPARE(firstWindowRow + 1, launcherRow); 0175 } 0176 0177 void TasksModelTest::test_filterOutInvalidPreferredLaunchers() 0178 { 0179 // Prepare launchers and running tasks 0180 TasksModel model; 0181 0182 model.setLauncherList(QStringList{ 0183 "preferred://nonexistent", 0184 }); 0185 QCOMPARE(model.launcherList().size(), 0); 0186 0187 const QUrl launcherUrl = QUrl::fromLocalFile(QFINDTESTDATA("data/applications/GammaRay.desktop")); 0188 model.setLauncherList(QStringList{ 0189 "preferred://nonexistent", 0190 launcherUrl.toString(), 0191 }); 0192 QCOMPARE(model.launcherList().size(), 1); 0193 } 0194 0195 QTEST_MAIN(TasksModelTest) 0196 0197 #include "tasksmodeltest.moc"