From 40eafafe3dba989ca1f4dc4761676e04ae373bd2 Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 6 Oct 2026 19:11:12 +0200 Subject: [PATCH] chatgui: verify drag highlight cleanup and attachment file picker reuse --- tools/chatgui/tests/test_file_drop.cpp | 60 +++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/tools/chatgui/tests/test_file_drop.cpp b/tools/chatgui/tests/test_file_drop.cpp index 25b15c56..84c4854e 100644 --- a/tools/chatgui/tests/test_file_drop.cpp +++ b/tools/chatgui/tests/test_file_drop.cpp @@ -15,6 +15,8 @@ extern "C" { #include #include #include +#include +#include #include #include #include @@ -44,7 +46,10 @@ static bool dropUrls(QWidget* target, const QList& urls, bool process = tr class FileDropTest : public QObject { Q_OBJECT private slots: - void initTestCase() { debug_config_init(); debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_DEBUG); } + void initTestCase() { + debug_config_init(); debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_DEBUG); + QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); + } void previewBeforeExplicitSend_data() { QTest::addColumn("history"); @@ -144,6 +149,59 @@ private slots: QCOMPARE(editor->toPlainText(), QString()); } + void dragHighlightLeavesNoWidgetWhenComposerIsDestroyed() { + QTemporaryDir dir; QVERIFY(dir.isValid()); + QListView view; view.resize(600, 400); view.show(); + auto* bar = new InputBar(nullptr, nullptr); bar->show(); + bar->setRecordingContext(dir.filePath("media"), "123"); bar->installFileDropTarget(view.viewport()); + QMimeData mime; mime.setUrls({QUrl::fromLocalFile(makeFile(dir, "test.txt"))}); + QDragEnterEvent enter(QPoint(5, 5), Qt::CopyAction, &mime, Qt::LeftButton, Qt::NoModifier); + QApplication::sendEvent(view.viewport(), &enter); QVERIFY(enter.isAccepted()); + QPointer hint = view.viewport()->findChild(); + QVERIFY(hint); QVERIFY(!hint->isHidden()); QVERIFY(hint->testAttribute(Qt::WA_TransparentForMouseEvents)); + QDragLeaveEvent leave; QApplication::sendEvent(view.viewport(), &leave); QVERIFY(hint->isHidden()); + QApplication::sendEvent(view.viewport(), &enter); QVERIFY(!hint->isHidden()); + delete bar; QVERIFY(hint.isNull()); + } + + void queuedDropIsCancelledWhenComposerIsDestroyed() { + QTemporaryDir dir; QVERIFY(dir.isValid()); + auto* bar = new InputBar(nullptr, nullptr); bar->show(); bar->setRecordingContext(dir.filePath("media"), "123"); + auto* editor = bar->findChild(); QVERIFY(editor); + QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(makeFile(dir, "test.txt"))}, false)); + delete bar; QCoreApplication::processEvents(); + QVERIFY(!QDir(dir.filePath("media")).exists()); + } + + void filePickerUsesTheSamePreparationAndContextGuard_data() { + QTest::addColumn("mode"); + for (const char* mode : {"file", "cancel", "changed-chat"}) QTest::newRow(mode) << QString(mode); + } + void filePickerUsesTheSamePreparationAndContextGuard() { + QFETCH(QString, mode); + QTemporaryDir dir; QVERIFY(dir.isValid()); + const QString first = makeFile(dir, "first.txt"), second = makeFile(dir, "second.txt"); + InputBar bar(nullptr, nullptr); bar.show(); bar.setRecordingContext(dir.filePath("media"), "123"); + auto* editor = bar.findChild(); QVERIFY(editor); + QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(first)})); + QSignalSpy files(&bar, &InputBar::sendFileAttachment), rejected(&bar, &InputBar::attachmentRejected); + QTimer timer; timer.setInterval(1); + connect(&timer, &QTimer::timeout, &bar, [&] { + auto* dialog = qobject_cast(QApplication::activeModalWidget()); + if (!dialog) return; + timer.stop(); + if (mode == "cancel") { dialog->reject(); return; } + if (mode == "changed-chat") bar.setRecordingContext(dir.filePath("media"), "456"); + dialog->selectFile(second); + QMetaObject::invokeMethod(dialog, "accept", Qt::DirectConnection); + }); + timer.start(); QVERIFY(QMetaObject::invokeMethod(&bar, "onAttachClicked", Qt::DirectConnection)); + QTest::keyClick(editor, Qt::Key_Return); + QCOMPARE(files.count(), mode == "changed-chat" ? 0 : 1); + QCOMPARE(rejected.count(), mode == "changed-chat" ? 1 : 0); + if (!files.isEmpty()) QCOMPARE(files.at(0).at(1).toString(), mode == "cancel" ? first : second); + } + void imageKeepsTheExistingGroupAndPmBehaviour_data() { QTest::addColumn("dm"); QTest::newRow("group-image") << false; QTest::newRow("dm-file") << true;