#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"
#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistselectionmanager.h"
#include <QStandardPaths>
#include <QTest>
+#include <kfileitem.h>
+#include <qapplication.h>
+#include <qkeysequence.h>
+#include <qnamespace.h>
#include <set>
#include <unordered_set>
void testOpenInNewTabTitle();
void testNewFileMenuEnabled_data();
void testNewFileMenuEnabled();
+ void testCreateFileAction();
+ void testCreateFileActionRequiresWritePermission();
void testWindowTitle_data();
void testWindowTitle();
void testFocusLocationBar();
void testAccessibilityTree();
void testAutoSaveSession();
void testInlineRename();
+ void testThumbnailAfterRename();
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);
QTRY_COMPARE(newFileMenu->isEnabled(), expectedEnabled);
}
+void DolphinMainWindowTest::testCreateFileAction()
+{
+ QScopedPointer<TestDir> testDir{new TestDir()};
+ QString testDirUrl(QDir::cleanPath(testDir->url().toString()));
+ m_mainWindow->openDirectories({testDirUrl}, false);
+ m_mainWindow->show();
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+ QVERIFY(m_mainWindow->isVisible());
+
+ QCOMPARE(m_mainWindow->m_activeViewContainer->view()->items().count(), 0);
+
+ auto createFileAction = m_mainWindow->actionCollection()->action(QStringLiteral("create_file"));
+ QTRY_COMPARE(createFileAction->isEnabled(), true);
+
+ createFileAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_N));
+
+ QSignalSpy createFileActionSpy(createFileAction, &QAction::triggered);
+
+ QTest::keyClick(QApplication::activeWindow(), Qt::Key_N, Qt::ControlModifier | Qt::AltModifier);
+
+ QTRY_COMPARE(createFileActionSpy.count(), 1);
+
+ QTRY_VERIFY(QApplication::activeModalWidget() != nullptr);
+
+ auto newFileDialog = QApplication::activeModalWidget()->focusWidget();
+ QTest::keyClick(newFileDialog, Qt::Key_X);
+ QTest::keyClick(newFileDialog, Qt::Key_Y);
+ QTest::keyClick(newFileDialog, Qt::Key_Z);
+ QTest::keyClick(newFileDialog, Qt::Key_Enter);
+
+ QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->items().count(), 1);
+
+ QFile file(testDir->url().toLocalFile() + "/xyz.txt");
+ QVERIFY(file.exists());
+ QCOMPARE(file.size(), 0);
+}
+
+ void DolphinMainWindowTest::testCreateFileActionRequiresWritePermission()
+{
+ QScopedPointer<TestDir> testDir{new TestDir()};
+ QString testDirUrl(QDir::cleanPath(testDir->url().toString()));
+ auto testDirAsFile = QFile(testDir->url().toLocalFile());
+
+ // make test dir read only
+ QVERIFY(testDirAsFile.setPermissions(QFileDevice::ReadOwner));
+
+ m_mainWindow->openDirectories({testDirUrl}, false);
+ m_mainWindow->show();
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+ QVERIFY(m_mainWindow->isVisible());
+
+ QCOMPARE(m_mainWindow->m_activeViewContainer->view()->items().count(), 0);
+
+ auto createFileAction = m_mainWindow->actionCollection()->action(QStringLiteral("create_file"));
+ QTRY_COMPARE(createFileAction->isEnabled(), false);
+
+ createFileAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_N));
+ QTest::keyClick(QApplication::activeWindow(), Qt::Key_N, Qt::ControlModifier | Qt::AltModifier);
+
+ QTRY_COMPARE(QApplication::activeModalWidget(), nullptr);
+
+ QTRY_COMPARE(m_mainWindow->m_activeViewContainer->view()->items().count(), 0);
+
+ QTRY_COMPARE(createFileAction->isEnabled(), false);
+
+ QVERIFY(m_mainWindow->isVisible());
+}
+
void DolphinMainWindowTest::testWindowTitle_data()
{
QTest::addColumn<QUrl>("activeViewUrl");
// after going forwards which is probably not intended.
}
}
- QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 12); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the
+ QCOMPARE_GE(testedObjectsSizeAfterTraversingForwards, 11); // The test did not reach many objects while using the Tab key to move through Dolphin. Did the
// test run correctly?
}
QCOMPARE(view->m_model->count(), 4);
}
+void DolphinMainWindowTest::testThumbnailAfterRename()
+{
+ // Create testdir and red square jpg for testing
+ QScopedPointer<TestDir> testDir{new TestDir()};
+ 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.data()->path() + "/a.jpg");
+
+ // Open dir and show it
+ m_mainWindow->openDirectories({testDir->url()}, false);
+ DolphinView *view = m_mainWindow->activeViewContainer()->view();
+ // Prepare signal spies
+ QSignalSpy viewDirectoryLoadingCompletedSpy(view, &DolphinView::directoryLoadingCompleted);
+ QSignalSpy itemsChangedSpy(view->m_model, &KFileItemModel::itemsChanged);
+ QSignalSpy modelDirectoryLoadingCompletedSpy(view->m_model, &KFileItemModel::directoryLoadingCompleted);
+ QSignalSpy previewUpdatedSpy(view->m_view->m_modelRolesUpdater, &KFileItemModelRolesUpdater::previewJobFinished);
+ // Show window and check that our preview has been updated, then wait for it to appear
+ m_mainWindow->show();
+ QVERIFY(viewDirectoryLoadingCompletedSpy.wait());
+ QVERIFY(previewUpdatedSpy.wait());
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+ QVERIFY(m_mainWindow->isVisible());
+ QTest::qWait(500); // we need to wait for the file widgets to become visible
+
+ // Set image selected and rename it to b.jpg, make sure editing role is working
+ view->markUrlsAsSelected({QUrl(testDir->url().toString() + "/a.jpg")});
+ view->updateViewState();
+ view->renameSelectedItems();
+ QVERIFY(view->m_view->m_editingRole);
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_B);
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_Enter);
+ QVERIFY(itemsChangedSpy.wait()); // Make sure that rename worked
+
+ // Check that preview gets updated and filename is correct
+ QVERIFY(previewUpdatedSpy.wait());
+ QVERIFY(!view->m_view->m_editingRole);
+ QCOMPARE(view->m_model->fileItem(0).name(), "b.jpg");
+ QCOMPARE(view->m_model->count(), 1);
+}
+
void DolphinMainWindowTest::cleanupTestCase()
{
m_mainWindow->showNormal();