From a31ade1054e571ab384cc80f9c609cb54104b94c Mon Sep 17 00:00:00 2001 From: evgeny Date: Sun, 18 Oct 2026 10:44:23 +0200 Subject: [PATCH] Exercise group encryption choice through real Qt input events --- tools/chatgui/tests/test_file_drop.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/chatgui/tests/test_file_drop.cpp b/tools/chatgui/tests/test_file_drop.cpp index 206587a1..c375c2da 100644 --- a/tools/chatgui/tests/test_file_drop.cpp +++ b/tools/chatgui/tests/test_file_drop.cpp @@ -21,6 +21,7 @@ extern "C" { #include #include #include +#include static QString makeFile(const QTemporaryDir& dir, const QString& name, const QByteArray& contents = "test") { const QString path = dir.filePath(name); @@ -46,6 +47,28 @@ static bool dropUrls(QWidget* target, const QList& urls, bool process = tr class FileDropTest : public QObject { Q_OBJECT private slots: + void encryptedAttachmentCapturesTargetAndResetsChoice() { + QTemporaryDir dir; QVERIFY(dir.isValid()); + const QString file = makeFile(dir, "private.txt", "private bytes"); + InputBar bar(nullptr, nullptr); bar.show(); bar.setRecordingContext(dir.filePath("media"), "123"); + auto* editor = bar.findChild(); QVERIFY(editor); + auto* encrypt = bar.findChild("encryptAttachmentButton"); QVERIFY(encrypt); + QSignalSpy ordinary(&bar, &InputBar::sendFileAttachment); + int encrypted = 0; + connect(&bar, &InputBar::submitAttachment, &bar, [&](const QString& target, attachment_send_req* request) { + QCOMPARE(target, QString("123")); QVERIFY(request->encrypted); QCOMPARE(request->info.kind, ATTACHMENT_FILE); + QCOMPARE(QString::fromUtf8(request->source), file); QCOMPARE(QString::fromUtf8(request->info.name), QString("private.txt")); + ++encrypted; u_free(request); + }); + QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(file)})); + QTest::mouseClick(encrypt, Qt::LeftButton); QVERIFY(encrypt->isChecked()); + QTest::keyClick(editor, Qt::Key_Return); + QCOMPARE(encrypted, 1); QCOMPARE(ordinary.size(), 0); QVERIFY(!encrypt->isChecked()); QVERIFY(QFile::exists(file)); + QTest::mouseClick(encrypt, Qt::LeftButton); QVERIFY(encrypt->isChecked()); + bar.setRecordingContext(dir.filePath("media"), "456"); QVERIFY(!encrypt->isChecked()); + bar.setDmMode(true); QVERIFY(encrypt->isHidden()); QVERIFY(!encrypt->isChecked()); + } + void replyDraftAndLateResults() { InputBar bar(nullptr, nullptr); bar.resize(600, 160); bar.show(); bar.setRecordingContext("/tmp", "123"); auto* editor = bar.findChild(); QVERIFY(editor);