X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/122fee5625f0285ec4ebda79162c72390989eb2a..14f17839ab2dc3ddca8af1c66eaeb40df5ab9f3f:/src/tests/dolphinmainwindowtest.cpp diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 2d90ae52f..94e6d5be4 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -45,6 +45,7 @@ private Q_SLOTS: void testNewFileMenuEnabled(); void testWindowTitle_data(); void testWindowTitle(); + void testFocusPlacesPanel(); void testPlacesPanelWidthResistance(); void testGoActions(); void testOpenFiles(); @@ -282,6 +283,44 @@ void DolphinMainWindowTest::testWindowTitle() QCOMPARE(m_mainWindow->windowTitle(), expectedWindowTitle); } +void DolphinMainWindowTest::testFocusPlacesPanel() +{ + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); + m_mainWindow->show(); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + + QWidget *placesPanel = reinterpret_cast(m_mainWindow->m_placesPanel); + QVERIFY2(QTest::qWaitFor( + [&]() { + return placesPanel && placesPanel->isVisible() && placesPanel->width() > 0 && placesPanel->height() > 0; + }, + 5000), + "The test couldn't be initialised properly. The places panel should be visible."); + + QAction *focusPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("focus_places_panel")); + QAction *showPlacesPanelAction = m_mainWindow->actionCollection()->action(QStringLiteral("show_places_panel")); + + focusPlacesPanelAction->trigger(); + QVERIFY(placesPanel->hasFocus()); + + focusPlacesPanelAction->trigger(); + QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()), + "Triggering focus_places_panel while the panel already has focus should return the focus to the view."); + + focusPlacesPanelAction->trigger(); + QVERIFY(placesPanel->hasFocus()); + + showPlacesPanelAction->trigger(); + QVERIFY(!placesPanel->isVisible()); + QVERIFY2(m_mainWindow->activeViewContainer()->isAncestorOf(QApplication::focusWidget()), + "Hiding the Places panel while it has focus should return the focus to the view."); + + showPlacesPanelAction->trigger(); + QVERIFY(placesPanel->isVisible()); + QVERIFY2(placesPanel->hasFocus(), "Enabling the Places panel should move keyboard focus there."); +} + /** * The places panel will resize itself if any of the other widgets requires too much horizontal space * but a user never wants the size of the places panel to change unless they resized it themselves explicitly.