|
|
|
@ -21,6 +21,7 @@ extern "C" { |
|
|
|
#include <QUrl> |
|
|
|
#include <QUrl> |
|
|
|
#include <QMessageBox> |
|
|
|
#include <QMessageBox> |
|
|
|
#include <QAbstractButton> |
|
|
|
#include <QAbstractButton> |
|
|
|
|
|
|
|
#include <QPushButton> |
|
|
|
|
|
|
|
|
|
|
|
static QString makeFile(const QTemporaryDir& dir, const QString& name, const QByteArray& contents = "test") { |
|
|
|
static QString makeFile(const QTemporaryDir& dir, const QString& name, const QByteArray& contents = "test") { |
|
|
|
const QString path = dir.filePath(name); |
|
|
|
const QString path = dir.filePath(name); |
|
|
|
@ -46,6 +47,28 @@ static bool dropUrls(QWidget* target, const QList<QUrl>& urls, bool process = tr |
|
|
|
class FileDropTest : public QObject { |
|
|
|
class FileDropTest : public QObject { |
|
|
|
Q_OBJECT |
|
|
|
Q_OBJECT |
|
|
|
private slots: |
|
|
|
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<QTextEdit*>(); QVERIFY(editor); |
|
|
|
|
|
|
|
auto* encrypt = bar.findChild<QPushButton*>("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() { |
|
|
|
void replyDraftAndLateResults() { |
|
|
|
InputBar bar(nullptr, nullptr); bar.resize(600, 160); bar.show(); bar.setRecordingContext("/tmp", "123"); |
|
|
|
InputBar bar(nullptr, nullptr); bar.resize(600, 160); bar.show(); bar.setRecordingContext("/tmp", "123"); |
|
|
|
auto* editor = bar.findChild<QTextEdit*>(); QVERIFY(editor); |
|
|
|
auto* editor = bar.findChild<QTextEdit*>(); QVERIFY(editor); |
|
|
|
|