Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfilewidgettest.cpp
Show All 18 Lines | 3 | Copyright (c) 2016 Albert Astals Cid <aacid@kde.org> | |||
---|---|---|---|---|---|
19 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "kfilewidget.h" | 22 | #include "kfilewidget.h" | ||
23 | 23 | | |||
24 | #include <QLabel> | 24 | #include <QLabel> | ||
25 | #include <QTest> | 25 | #include <QTest> | ||
26 | #include <QStandardPaths> | 26 | #include <QStandardPaths> | ||
27 | #include <QSignalSpy> | ||||
27 | 28 | | |||
28 | #include <kdiroperator.h> | 29 | #include <kdiroperator.h> | ||
29 | #include <KFileFilterCombo> | 30 | #include <KFileFilterCombo> | ||
30 | #include <klocalizedstring.h> | 31 | #include <klocalizedstring.h> | ||
31 | #include <kurlnavigator.h> | 32 | #include <kurlnavigator.h> | ||
32 | #include <KUrlComboBox> | 33 | #include <KUrlComboBox> | ||
33 | #include <KFileFilterCombo> | 34 | #include <KFileFilterCombo> | ||
34 | #include "kiotesthelper.h" // createTestFile | 35 | #include "kiotesthelper.h" // createTestFile | ||
▲ Show 20 Lines • Show All 436 Lines • ▼ Show 20 Line(s) | 454 | { | |||
471 | fileWidget.setMode(KFile::File); | 472 | fileWidget.setMode(KFile::File); | ||
472 | fileWidget.show(); | 473 | fileWidget.show(); | ||
473 | fileWidget.activateWindow(); | 474 | fileWidget.activateWindow(); | ||
474 | QVERIFY(QTest::qWaitForWindowActive(&fileWidget)); | 475 | QVERIFY(QTest::qWaitForWindowActive(&fileWidget)); | ||
475 | 476 | | |||
476 | QMimeData *mimeData = new QMimeData(); | 477 | QMimeData *mimeData = new QMimeData(); | ||
477 | mimeData->setUrls(QList<QUrl>() << fileUrl); | 478 | mimeData->setUrls(QList<QUrl>() << fileUrl); | ||
478 | 479 | | |||
480 | KDirLister *dirLister = fileWidget.dirOperator()->dirLister(); | ||||
481 | QSignalSpy spy(dirLister, SIGNAL(completed(const QUrl &_url))); | ||||
dfaure: For the record, this is broken, it should have been `completed(QUrl)`. Specifying argument… | |||||
meven: Let me know if I should relay you. | |||||
dfaure: I thought I did that in commit eb18397fe525d2e4bd9 ? | |||||
482 | | ||||
479 | QDragEnterEvent event1(QPoint(), Qt::DropAction::MoveAction, mimeData, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier); | 483 | QDragEnterEvent event1(QPoint(), Qt::DropAction::MoveAction, mimeData, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier); | ||
480 | 484 | | |||
481 | QVERIFY(qApp->sendEvent(fileWidget.dirOperator()->view()->viewport(), &event1)); | 485 | QVERIFY(qApp->sendEvent(fileWidget.dirOperator()->view()->viewport(), &event1)); | ||
482 | 486 | | |||
483 | // Fake drop | 487 | // Fake drop | ||
484 | QDropEvent event(QPoint(), Qt::DropAction::MoveAction, mimeData, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier); | 488 | QDropEvent event(QPoint(), Qt::DropAction::MoveAction, mimeData, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier); | ||
485 | 489 | | |||
486 | QVERIFY(qApp->sendEvent(fileWidget.dirOperator()->view()->viewport(), &event)); | 490 | QVERIFY(qApp->sendEvent(fileWidget.dirOperator()->view()->viewport(), &event)); | ||
487 | 491 | | |||
488 | // QVERIFY(QTest::qWaitForWindowActive(&fileWidget)); | 492 | // QVERIFY(QTest::qWaitForWindowActive(&fileWidget)); | ||
489 | 493 | | |||
490 | // once we drop a file the dirlister scans the dir | 494 | // once we drop a file the dirlister scans the dir | ||
491 | // wait a bit to the dirlister time to finish | 495 | // wait for the completed signal from the dirlister | ||
492 | QTest::qWait(100); | 496 | spy.wait(); | ||
493 | 497 | | |||
494 | // Verify the expected populated name. | 498 | // Verify the expected populated name. | ||
495 | QCOMPARE(fileWidget.baseUrl().adjusted(QUrl::StripTrailingSlash), dirUrl); | 499 | QCOMPARE(fileWidget.baseUrl().adjusted(QUrl::StripTrailingSlash), dirUrl); | ||
496 | QCOMPARE(fileWidget.locationEdit()->currentText(), expectedCurrentText); | 500 | QCOMPARE(fileWidget.locationEdit()->currentText(), expectedCurrentText); | ||
497 | 501 | | |||
498 | // QFileDialog ends up calling KDEPlatformFileDialog::selectedFiles() | 502 | // QFileDialog ends up calling KDEPlatformFileDialog::selectedFiles() | ||
499 | // which calls KFileWidget::selectedUrls(). | 503 | // which calls KFileWidget::selectedUrls(). | ||
500 | // Accept the filename to ensure that a filename is selected. | 504 | // Accept the filename to ensure that a filename is selected. | ||
Show All 11 Lines |
For the record, this is broken, it should have been completed(QUrl). Specifying argument names is incorrect in SIGNAL() and SLOT() macros.
It makes the wait() below fail every time, but after 5s, so the 100ms became 5s :-)
I'm working on fixing this.