|
|
|
|
@ -15,6 +15,8 @@ extern "C" {
|
|
|
|
|
#include <QTemporaryDir> |
|
|
|
|
#include <QFile> |
|
|
|
|
#include <QFileInfo> |
|
|
|
|
#include <QFileDialog> |
|
|
|
|
#include <QLabel> |
|
|
|
|
#include <QTimer> |
|
|
|
|
#include <QUrl> |
|
|
|
|
#include <QMessageBox> |
|
|
|
|
@ -44,7 +46,10 @@ static bool dropUrls(QWidget* target, const QList<QUrl>& 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<bool>("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<QLabel> hint = view.viewport()->findChild<QLabel*>(); |
|
|
|
|
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<QTextEdit*>(); 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<QString>("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<QTextEdit*>(); 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<QFileDialog*>(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<bool>("dm"); |
|
|
|
|
QTest::newRow("group-image") << false; QTest::newRow("dm-file") << true; |
|
|
|
|
|