Add test for drag and drop database files into main window

This commit is contained in:
frostasm 2017-12-22 20:05:33 +02:00
parent 165d664524
commit 3720c5ef79
3 changed files with 41 additions and 0 deletions

View File

@ -1035,6 +1035,9 @@ void MainWindow::dropEvent(QDropEvent* event)
const QMimeData* mimeData = event->mimeData(); const QMimeData* mimeData = event->mimeData();
if (mimeData->hasUrls()) { if (mimeData->hasUrls()) {
const QStringList kdbxFiles = kdbxFilesFromUrls(mimeData->urls()); const QStringList kdbxFiles = kdbxFilesFromUrls(mimeData->urls());
if (!kdbxFiles.isEmpty()) {
event->acceptProposedAction();
}
for (const QString& kdbxFile: kdbxFiles) { for (const QString& kdbxFile: kdbxFiles) {
openDatabase(kdbxFile); openDatabase(kdbxFile);
} }

View File

@ -952,6 +952,43 @@ void TestGui::testDatabaseLocking()
QCOMPARE(m_tabWidget->tabText(0).remove('&'), origDbName); QCOMPARE(m_tabWidget->tabText(0).remove('&'), origDbName);
} }
void TestGui::testDragAndDropKdbxFiles()
{
const int openedDatabasesCount = m_tabWidget->count();
const QString badDatabaseFilePath(QString(KEEPASSX_TEST_DATA_DIR).append("/NotDatabase.notkdbx"));
QMimeData badMimeData;
badMimeData.setUrls({QUrl::fromLocalFile(badDatabaseFilePath)});
QDragEnterEvent badDragEvent(QPoint(1, 1), Qt::LinkAction, &badMimeData, Qt::LeftButton, Qt::NoModifier);
qApp->notify(m_mainWindow, &badDragEvent);
QCOMPARE(badDragEvent.isAccepted(), false);
QDropEvent badDropEvent(QPoint(1, 1), Qt::LinkAction, &badMimeData, Qt::LeftButton, Qt::NoModifier);
qApp->notify(m_mainWindow, &badDropEvent);
QCOMPARE(badDropEvent.isAccepted(), false);
QCOMPARE(m_tabWidget->count(), openedDatabasesCount);
const QString goodDatabaseFilePath(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.kdbx"));
QMimeData goodMimeData;
goodMimeData.setUrls({QUrl::fromLocalFile(goodDatabaseFilePath)});
QDragEnterEvent goodDragEvent(QPoint(1, 1), Qt::LinkAction, &goodMimeData, Qt::LeftButton, Qt::NoModifier);
qApp->notify(m_mainWindow, &goodDragEvent);
QCOMPARE(goodDragEvent.isAccepted(), true);
QDropEvent goodDropEvent(QPoint(1, 1), Qt::LinkAction, &goodMimeData, Qt::LeftButton, Qt::NoModifier);
qApp->notify(m_mainWindow, &goodDropEvent);
QCOMPARE(goodDropEvent.isAccepted(), true);
QCOMPARE(m_tabWidget->count(), openedDatabasesCount + 1);
MessageBox::setNextAnswer(QMessageBox::No);
triggerAction("actionDatabaseClose");
Tools::wait(100);
QCOMPARE(m_tabWidget->count(), openedDatabasesCount);
}
void TestGui::cleanupTestCase() void TestGui::cleanupTestCase()
{ {
delete m_mainWindow; delete m_mainWindow;

View File

@ -60,6 +60,7 @@ private slots:
void testDatabaseSettings(); void testDatabaseSettings();
void testKeePass1Import(); void testKeePass1Import();
void testDatabaseLocking(); void testDatabaseLocking();
void testDragAndDropKdbxFiles();
private: private:
int addCannedEntries(); int addCannedEntries();