X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/eca160ae5a2dbd5590e4bae22cddde488dbacf74..be51e7233294263e3c2866e101e1151dbc61ccbe:/src/tests/dolphinmainwindowtest.cpp diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 37e042219..c7d2f4b6d 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -9,6 +9,7 @@ #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" @@ -30,6 +31,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -49,6 +54,8 @@ private Q_SLOTS: void testOpenInNewTabTitle(); void testNewFileMenuEnabled_data(); void testNewFileMenuEnabled(); + void testCreateFileAction(); + void testCreateFileActionRequiresWritePermission(); void testWindowTitle_data(); void testWindowTitle(); void testFocusLocationBar(); @@ -69,6 +76,11 @@ 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() @@ -372,6 +384,74 @@ void DolphinMainWindowTest::testNewFileMenuEnabled() QTRY_COMPARE(newFileMenu->isEnabled(), expectedEnabled); } +void DolphinMainWindowTest::testCreateFileAction() +{ + QScopedPointer 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{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("activeViewUrl"); @@ -846,7 +926,7 @@ void DolphinMainWindowTest::testAccessibilityTree() // 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? }