Test typed desktop images in channels and PM and reject corrupted attachments
This commit is contained in:
1 parent
3c74fc89fe
commit
206abcae10
1 file changed
+32
-8
@@ -31,6 +31,7 @@ extern "C" {
|
||||
#include <QScrollBar>
|
||||
#include <QPointer>
|
||||
#include <QScopeGuard>
|
||||
#include <QImage>
|
||||
|
||||
static QString makeFile(const QTemporaryDir& dir, const QString& name, const QByteArray& contents = "test") {
|
||||
const QString path = dir.filePath(name);
|
||||
@@ -521,20 +522,43 @@ private slots:
|
||||
if (!files.isEmpty()) QCOMPARE(files.at(0).at(1).toString(), mode == "cancel" ? first : second);
|
||||
}
|
||||
|
||||
void imageKeepsTheExistingGroupAndPmBehaviour_data() {
|
||||
void imageHasTypedMetadataInGroupAndPm_data() {
|
||||
QTest::addColumn<bool>("dm");
|
||||
QTest::newRow("group-image") << false; QTest::newRow("dm-file") << true;
|
||||
QTest::addColumn<QString>("format");
|
||||
for (bool dm : {false, true}) for (const QString& format : {QString("PNG"), QString("JPEG")})
|
||||
QTest::newRow(qPrintable(QString("%1-%2").arg(dm ? "pm" : "group", format))) << dm << format;
|
||||
}
|
||||
void imageKeepsTheExistingGroupAndPmBehaviour() {
|
||||
QFETCH(bool, dm);
|
||||
void imageHasTypedMetadataInGroupAndPm() {
|
||||
QFETCH(bool, dm); QFETCH(QString, format);
|
||||
QTemporaryDir dir; QVERIFY(dir.isValid());
|
||||
InputBar bar(nullptr, nullptr); bar.show();
|
||||
bar.setRecordingContext(dir.filePath("media"), dm ? "dm:abcd" : "123"); bar.setDmMode(dm);
|
||||
bar.setRecordingContext(dir.filePath("media"), dm ? "dm:456" : "123"); bar.setDmMode(dm); bar.setDmGeneration(7);
|
||||
auto* editor = bar.findChild<QTextEdit*>(); QVERIFY(editor);
|
||||
QSignalSpy files(&bar, &InputBar::sendFileAttachment), images(&bar, &InputBar::sendImageAttachment);
|
||||
QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(makeFile(dir, "фото.PNG"))}));
|
||||
const QString path = dir.filePath("фото.PNG"); // Фактический JPEG должен победить расширение PNG.
|
||||
QImage image(120, 80, QImage::Format_ARGB32); image.fill(Qt::red); QVERIFY(image.save(path, qPrintable(format)));
|
||||
int sends = 0;
|
||||
connect(&bar, &InputBar::submitAttachment, &bar, [&](const QString& target, attachment_send_req* request) {
|
||||
++sends; QCOMPARE(target, dm ? QString("dm:456") : QString("123"));
|
||||
QCOMPARE(request->info.kind, format == "PNG" ? ATTACHMENT_PNG : ATTACHMENT_JPEG);
|
||||
QCOMPARE(request->info.width, 120); QCOMPARE(request->info.height, 80); QCOMPARE(request->dm_generation, UINT64_C(7));
|
||||
QCOMPARE(QString::fromUtf8(request->source), path); QVERIFY(!request->temporary_source);
|
||||
const auto id = request->request_id; attachment_send_discard(request); bar.submissionResult(id, true);
|
||||
});
|
||||
QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(path)}));
|
||||
QTest::keyClick(editor, Qt::Key_Return);
|
||||
QCOMPARE(files.count(), dm ? 1 : 0); QCOMPARE(images.count(), dm ? 0 : 1);
|
||||
QCOMPARE(sends, 1); QVERIFY(QFile::exists(path));
|
||||
}
|
||||
|
||||
void corruptImageIsRejectedAndPreservesSelection() {
|
||||
QTemporaryDir dir; InputBar bar(nullptr, nullptr); bar.show(); bar.setRecordingContext(dir.path(), "123");
|
||||
auto* editor = bar.findChild<QTextEdit*>(); QVERIFY(editor);
|
||||
QSignalSpy errors(&bar, &InputBar::attachmentRejected);
|
||||
int sends = 0; connect(&bar, &InputBar::submitAttachment, &bar, [&](const QString&, attachment_send_req* req) {
|
||||
++sends; attachment_send_discard(req);
|
||||
});
|
||||
const QString path = makeFile(dir, "broken.jpg");
|
||||
QVERIFY(dropUrls(editor->viewport(), {QUrl::fromLocalFile(path)})); QTest::keyClick(editor, Qt::Key_Return);
|
||||
QCOMPARE(sends, 0); QVERIFY(!errors.isEmpty()); QVERIFY(QFile::exists(path));
|
||||
}
|
||||
|
||||
void videoModeSelectionAndCancellation_data() {
|
||||
|
||||
Reference in new issue
Block a user