X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/4102ccb80457eea44ea280f0ace2a419602bc34b..04e493d78cdf46e64562fe8a302426b1fd8c47df:/src/tests/dolphinmainwindowtest.cpp diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 4ae36e7e6..345a56504 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -5,11 +5,11 @@ */ #include "dolphinmainwindow.h" +#include "dolphin_generalsettings.h" #include "dolphinnewfilemenu.h" #include "dolphintabpage.h" #include "dolphintabwidget.h" #include "dolphinviewcontainer.h" -#include "dolphin_generalsettings.h" #include "kitemviews/kfileitemmodel.h" #include "kitemviews/kfileitemmodelrolesupdater.h" #include "kitemviews/kitemlistcontainer.h" @@ -18,6 +18,7 @@ #include "kitemviews/kitemlistwidget.h" #include "testdir.h" #include "views/dolphinitemlistview.h" +#include "views/viewproperties.h" #include #include @@ -67,6 +68,7 @@ private Q_SLOTS: void testAutoSaveSession(); void testInlineRename(); void testThumbnailAfterRename(); + void testViewModeAfterDynamicView(); void cleanupTestCase(); private: @@ -154,20 +156,20 @@ void DolphinMainWindowTest::testSyncDesktopAndPhoneUi() do { QVERIFY2(desktopUiElement.tagName() == phoneUiElement.tagName(), qPrintable(QStringLiteral("Node mismatch: dolphinui.rc/%1::%2 and dolphinuiforphones.rc/%3::%4") - .arg(desktopUiElement.parentNode().toElement().tagName()) - .arg(desktopUiElement.tagName()) - .arg(phoneUiElement.parentNode().toElement().tagName()) - .arg(phoneUiElement.tagName()))); + .arg(desktopUiElement.parentNode().toElement().tagName(), + desktopUiElement.tagName(), + phoneUiElement.parentNode().toElement().tagName(), + phoneUiElement.tagName()))); QCOMPARE(desktopUiElement.text(), phoneUiElement.text()); const auto desktopUiElementAttributes = desktopUiElement.attributes(); const auto phoneUiElementAttributes = phoneUiElement.attributes(); for (int i = 0; i < desktopUiElementAttributes.count(); i++) { QVERIFY2(phoneUiElementAttributes.count() >= i, qPrintable(QStringLiteral("Attribute mismatch: dolphinui.rc/%1::%2 has more attributes than dolphinuiforphones.rc/%3::%4") - .arg(desktopUiElement.parentNode().toElement().tagName()) - .arg(desktopUiElement.tagName()) - .arg(phoneUiElement.parentNode().toElement().tagName()) - .arg(phoneUiElement.tagName()))); + .arg(desktopUiElement.parentNode().toElement().tagName(), + desktopUiElement.tagName(), + phoneUiElement.parentNode().toElement().tagName(), + phoneUiElement.tagName()))); if (exceptions.count(desktopUiElementAttributes.item(i).nodeName())) { continue; } @@ -177,12 +179,11 @@ void DolphinMainWindowTest::testSyncDesktopAndPhoneUi() } QVERIFY2(desktopUiElementAttributes.count() == phoneUiElementAttributes.count(), qPrintable(QStringLiteral("Attribute mismatch: dolphinui.rc/%1::%2 has fewer attributes than dolphinuiforphones.rc/%3::%4. %5 < %6") - .arg(desktopUiElement.parentNode().toElement().tagName()) - .arg(desktopUiElement.tagName()) - .arg(phoneUiElement.parentNode().toElement().tagName()) - .arg(phoneUiElement.tagName()) - .arg(phoneUiElementAttributes.count()) - .arg(desktopUiElementAttributes.count()))); + .arg(desktopUiElement.parentNode().toElement().tagName(), + desktopUiElement.tagName(), + phoneUiElement.parentNode().toElement().tagName(), + phoneUiElement.tagName()) + .arg(phoneUiElementAttributes.count(), desktopUiElementAttributes.count()))); desktopUiElement = nextUiElement(desktopUiElement); phoneUiElement = nextUiElement(phoneUiElement); @@ -1065,6 +1066,86 @@ void DolphinMainWindowTest::testThumbnailAfterRename() QCOMPARE(view->m_model->count(), 1); } +void DolphinMainWindowTest::testViewModeAfterDynamicView() +{ + GeneralSettings *settings = GeneralSettings::self(); + settings->setDynamicView(true); + settings->save(); + + // prepare test data + QScopedPointer testDir{new TestDir()}; + QString testDirUrl(QDir::cleanPath(testDir->url().toString())); + testDir->createDir("a"); + QImage testImage(256, 256, QImage::Format_Mono); + testImage.setColorCount(1); + testImage.setColor(0, qRgba(255, 0, 0, 255)); // Index #0 = Red + for (short x = 0; x < 256; ++x) { + for (short y = 0; y < 256; ++y) { + testImage.setPixel(x, y, 0); + } + } + testImage.save(testDir->url().path() + "/a/1.jpg"); + + // open test dir and set default view mode to "Details" + m_mainWindow->openDirectories({testDirUrl}, false); + DolphinView *view = m_mainWindow->activeViewContainer()->view(); + QSignalSpy viewDirectoryLoadingCompletedSpy(view, &DolphinView::directoryLoadingCompleted); + QSignalSpy modelDirectoryLoadingCompletedSpy(view->m_model, &KFileItemModel::directoryLoadingCompleted); + m_mainWindow->show(); + QVERIFY(viewDirectoryLoadingCompletedSpy.wait()); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + m_mainWindow->actionCollection()->action(QStringLiteral("details"))->trigger(); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + + // move to child folder and check that dynamic view changed view mode to icons + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::IconsView); + + // go back to parent folder and check that view mode reverted to details + m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger(); + view->m_model->loadDirectory(testDir->url()); + view->setUrl(testDir->url()); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + + // test for local views + settings->setGlobalViewProps(false); + settings->save(); + + // go to child folder and check DynamicViewPassed key in view properties as well as view mode + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::IconsView); + QTest::qWait(100); + QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // change view mode of child folder to "Details" + m_mainWindow->actionCollection()->action(QStringLiteral("details"))->trigger(); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + + // go back to parent folder + m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger(); + view->m_model->loadDirectory(testDir->url()); + view->setUrl(testDir->url()); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + QVERIFY(!ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // 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")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); +} + void DolphinMainWindowTest::cleanupTestCase() { m_mainWindow->showNormal();