*/
#include "dolphinmainwindow.h"
+#include "dolphin_generalsettings.h"
#include "dolphinnewfilemenu.h"
#include "dolphintabpage.h"
#include "dolphintabwidget.h"
#include "kitemviews/kitemlistwidget.h"
#include "testdir.h"
#include "views/dolphinitemlistview.h"
+#include "views/viewproperties.h"
#include <KActionCollection>
#include <KConfig>
void testAutoSaveSession();
void testInlineRename();
void testThumbnailAfterRename();
+ void testViewModeAfterDynamicView();
void cleanupTestCase();
private:
void DolphinMainWindowTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
+ // Use fullWidth statusbar during testing, to test out most of the features.
+ GeneralSettings *settings = GeneralSettings::self();
+ settings->setShowStatusBar(GeneralSettings::EnumShowStatusBar::FullWidth);
+ settings->setShowZoomSlider(true);
+ settings->save();
}
void DolphinMainWindowTest::init()
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;
}
}
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);
QVERIFY(tabWidget);
// Show search box on first tab.
- tabWidget->currentTabPage()->activeViewContainer()->setSearchModeEnabled(true);
+ tabWidget->currentTabPage()->activeViewContainer()->setSearchBarVisible(true);
tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::homePath()));
QCOMPARE(tabWidget->count(), 2);
QCOMPARE(view->m_model->count(), 1);
}
+void DolphinMainWindowTest::testViewModeAfterDynamicView()
+{
+ GeneralSettings *settings = GeneralSettings::self();
+ settings->setDynamicView(true);
+ settings->save();
+
+ // prepare test data
+ QScopedPointer<TestDir> 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();