From 3fda8376b6a38b222896b809786859c7956c73e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 17 May 2016 09:30:11 +0200 Subject: [PATCH] [client] Ensure PlasmaWindowModel removes deleted windows Summary: There is a possibility that a PlasmaWindow is unmapped when the PlasmaWindowModel gets created. In this situation the unmapped PlasmaWindow will be deleted in the next event cycle. So far PlasmaWindowModel didn't handle this situation and the model might hold deleted objects due to this. This change addresses this potential problem and ensures the model gets updated when a PlasmaWindow is deleted. Test Plan: Test case which exposes the problem is added Reviewers: #plasma, hein Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D1622 --- .../client/test_plasma_window_model.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/wayland/autotests/client/test_plasma_window_model.cpp b/src/wayland/autotests/client/test_plasma_window_model.cpp index 2e37469149..9b842b51ee 100644 --- a/src/wayland/autotests/client/test_plasma_window_model.cpp +++ b/src/wayland/autotests/client/test_plasma_window_model.cpp @@ -73,6 +73,7 @@ private Q_SLOTS: void testRequests(); // TODO: minimized geometry // TODO: model reset + void testCreateWithUnmappedWindow(); private: bool testBooleanData(PlasmaWindowModel::AdditionalRoles role, void (PlasmaWindowInterface::*function)(bool)); @@ -681,5 +682,38 @@ void PlasmaWindowModelTest::testRequests() QCOMPARE(shadeRequestedSpy.last().first().toBool(), false); } +void PlasmaWindowModelTest::testCreateWithUnmappedWindow() +{ + // this test verifies that creating the model just when an unmapped window exists doesn't cause problems + // that is the unmapped window should be added (as expected), but also be removed again + + // create a window in "normal way" + QSignalSpy windowCreatedSpy(m_pw, &PlasmaWindowManagement::windowCreated); + QVERIFY(windowCreatedSpy.isValid()); + auto w = m_pwInterface->createWindow(m_pwInterface); + QVERIFY(w); + QVERIFY(windowCreatedSpy.wait()); + PlasmaWindow *window = windowCreatedSpy.first().first().value(); + QVERIFY(window); + QSignalSpy unmappedSpy(window, &PlasmaWindow::unmapped); + QVERIFY(unmappedSpy.isValid()); + QSignalSpy destroyedSpy(window, &PlasmaWindow::destroyed); + QVERIFY(destroyedSpy.isValid()); + // unmap should be triggered, but not yet the destroyed + w->unmap(); + QVERIFY(unmappedSpy.wait()); + QVERIFY(destroyedSpy.isEmpty()); + + auto model = m_pw->createWindowModel(); + QVERIFY(model); + QCOMPARE(model->rowCount(), 1); + QSignalSpy rowRemovedSpy(model, &PlasmaWindowModel::rowsRemoved); + QVERIFY(rowRemovedSpy.isValid()); + QVERIFY(rowRemovedSpy.wait()); + QCOMPARE(rowRemovedSpy.count(), 1); + QCOMPARE(model->rowCount(), 0); + QCOMPARE(destroyedSpy.count(), 1); +} + QTEST_GUILESS_MAIN(PlasmaWindowModelTest) #include "test_plasma_window_model.moc"