diff options
Diffstat (limited to 'src/tests/dolphinmainwindowtest.cpp')
| -rw-r--r-- | src/tests/dolphinmainwindowtest.cpp | 110 |
1 files changed, 109 insertions, 1 deletions
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index f68f07cbc..21e48f246 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -16,9 +16,11 @@ #include "kitemviews/kitemlistcontroller.h" #include "kitemviews/kitemlistselectionmanager.h" #include "kitemviews/kitemlistwidget.h" +#include "settings/viewmodes/viewmodesettings.h" #include "testdir.h" #include "views/dolphinitemlistview.h" #include "views/viewproperties.h" +#include "views/zoomlevelinfo.h" #include <KActionCollection> #include <KConfig> @@ -69,6 +71,7 @@ private Q_SLOTS: void testThumbnailAfterRename(); void testViewModeAfterDynamicView(); void testActivationAndTabTitleAfterRenameOpeningFolder(); + void testActiveViewAfterTabSwitchWithSplitView(); void cleanupTestCase(); private: @@ -935,7 +938,7 @@ void DolphinMainWindowTest::testAccessibilityTree() // after going forwards which is probably not intended. } } - QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 11); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the + QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 10); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the // test run correctly? } @@ -1077,6 +1080,7 @@ void DolphinMainWindowTest::testThumbnailAfterRename() void DolphinMainWindowTest::testViewModeAfterDynamicView() { GeneralSettings *settings = GeneralSettings::self(); + settings->setGlobalViewProps(true); settings->setDynamicView(true); settings->save(); @@ -1144,6 +1148,9 @@ void DolphinMainWindowTest::testViewModeAfterDynamicView() QCOMPARE(view->m_mode, DolphinView::DetailsView); QVERIFY(!ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + // store parent current zoom level + const int parentZoomLevel = view->zoomLevel(); + // go to child folder and make sure view mode change to "Details" is permanent m_mainWindow->openFiles({testDirUrl + "/a"}, false); view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); @@ -1151,6 +1158,60 @@ void DolphinMainWindowTest::testViewModeAfterDynamicView() QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); QCOMPARE(view->m_mode, DolphinView::DetailsView); QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // still on child, change view zoom level + const int childZoomLevel = view->zoomLevel() + 2; + view->setZoomLevel(childZoomLevel); + + // go back to parent folder and check for zoom level + m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger(); + view->m_model->loadDirectory(testDir->url()); + view->setUrl(testDir->url()); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->zoomLevel(), parentZoomLevel); + QVERIFY(!ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // go to child and check if zoom level is permanent + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->zoomLevel(), childZoomLevel); + QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // test for global views + settings->setGlobalViewProps(true); + settings->save(); + QVERIFY(GeneralSettings::globalViewProps()); + + // go back to parent folder and set zoom level + m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger(); + view->m_model->loadDirectory(testDir->url()); + view->setUrl(testDir->url()); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + + // zoom isn't changed + QCOMPARE(view->zoomLevel(), childZoomLevel); + + // change the zoom + view->setZoomLevel(parentZoomLevel + 1); + QCOMPARE(view->zoomLevel(), parentZoomLevel + 1); + QVERIFY(!ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // go to child and check if zoom level remains the same + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + + ViewModeSettings modeDefaultSettings{DolphinView::IconsView}; + auto defaultPreviewIconSize = modeDefaultSettings.previewSize(); + auto defaultPreviewZoom = ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultPreviewIconSize, defaultPreviewIconSize)); + // dynamic view works + QCOMPARE(view->m_mode, DolphinView::IconsView); + QCOMPARE(view->zoomLevel(), defaultPreviewZoom); + // that's the global settings, no dynamicViewPassed saved + QVERIFY(!ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); } void DolphinMainWindowTest::testActivationAndTabTitleAfterRenameOpeningFolder() @@ -1232,6 +1293,53 @@ void DolphinMainWindowTest::testActivationAndTabTitleAfterRenameOpeningFolder() QCOMPARE(tabWidget->tabText(1), expectedNewTab1Title); } +// Test that switching tabs does not spuriously toggle which split-view pane is active. +// Regression test for the bug where DolphinTabPage::setActive(true) during tab switch +// caused DolphinView::activated() to reach slotViewActivated(), which toggled +// m_primaryViewActive and connected MainWindow signals to the wrong view container. +void DolphinMainWindowTest::testActiveViewAfterTabSwitchWithSplitView() +{ + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); + m_mainWindow->show(); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + + auto tabWidget = m_mainWindow->findChild<DolphinTabWidget *>("tabWidget"); + QVERIFY(tabWidget); + + // Enable split view on the first tab. After this, the secondary (right) pane + // becomes active via slotViewActivated(), so primaryViewActive() is false. + m_mainWindow->actionCollection()->action(QStringLiteral("split_view"))->trigger(); + QVERIFY(tabWidget->currentTabPage()->splitViewEnabled()); + QVERIFY(!tabWidget->currentTabPage()->primaryViewActive()); + auto firstTabPage = tabWidget->currentTabPage(); + auto firstTabSecondary = firstTabPage->secondaryViewContainer(); + QVERIFY(firstTabSecondary->isActive()); + + // Open a second tab and switch to it. + tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::homePath())); + QCOMPARE(tabWidget->count(), 2); + QCOMPARE(tabWidget->currentIndex(), 1); + + // Spy on activeViewChanged to count emissions during the tab switch back. + QSignalSpy activeViewChangedSpy(tabWidget, &DolphinTabWidget::activeViewChanged); + + // Switch back to the first tab. + tabWidget->setCurrentIndex(0); + QCOMPARE(tabWidget->currentTabPage(), firstTabPage); + + // activeViewChanged must be emitted exactly once — by currentTabChanged itself. + // A spurious second emission would indicate slotViewActivated() fired during + // the programmatic setActive(true) and toggled m_primaryViewActive. + QCOMPARE(activeViewChangedSpy.count(), 1); + + // The secondary pane must still be the designated active one. + QVERIFY(!firstTabPage->primaryViewActive()); + QCOMPARE(firstTabPage->activeViewContainer(), firstTabSecondary); + QVERIFY(firstTabSecondary->isActive()); + QVERIFY(!firstTabPage->primaryViewContainer()->isActive()); +} + void DolphinMainWindowTest::cleanupTestCase() { m_mainWindow->showNormal(); |
