D15347: Modify CloseDialogHelper in parttest

Tobias Deiminger noreply at phabricator.kde.org
Mon Jul 15 19:00:30 BST 2019


tobiasdeiminger added a comment.


  In D15347#495392 <https://phabricator.kde.org/D15347#495392>, @sander wrote:
  
  > Agreed.  I think the first step should be to write a unit test that triggers https://bugs.kde.org/show_bug.cgi?id=409638. That way we get a reproducible way to trigger the problem even for people without a stylus.
  
  
  How about this test? We can reproduce a second QInputDialog by using a simple mouse click event. In bug 409638 it's probably a `TabletEnterProximity` event instead. We could change the test accordingly to be closer to the bug report.
  
    void PartTest::testInlineNoteInputDialog()
    {
        QInputDialog *goodInputDialog { nullptr };
        QInputDialog *spuriousInputDialog { nullptr };
        QScopedPointer<CloseDialogHelper> closeDialogHelper;
        Okular::Part part { nullptr, nullptr, QVariantList() };
        part.openUrl(QUrl::fromLocalFile(QStringLiteral(KDESRCDIR "data/file1.pdf")));
        part.widget()->show();
        QVERIFY( QTest::qWaitForWindowExposed(part.widget()) );
        const int width = part.m_pageView->horizontalScrollBar()->maximum() +
                          part.m_pageView->viewport()->width();
        const int height = part.m_pageView->verticalScrollBar()->maximum() +
                           part.m_pageView->viewport()->height();
        part.m_document->setViewportPage( 0 );
    
        // Open annotation toolbar and get the inline note tool button.
        QMetaObject::invokeMethod(part.m_pageView, "slotToggleAnnotator", Q_ARG( bool, true ));
        QList<QToolButton*> toolbuttonList = part.m_pageView->findChildren<QToolButton *>();
        QList<QToolButton*>::iterator it = std::find_if( toolbuttonList.begin(), toolbuttonList.end(), [](const QToolButton * x) -> bool {
            if (x->toolTip().contains("Inline Note") )
                return true;
            return false;
        } );
        QVERIFY(it != toolbuttonList.end());
    
        // Clicking the tool button constructs a PickPointEngine in PageViewAnnotator,
        // but doesn't use it yet.
        QToolButton* inlineNoteButton = *it;
        inlineNoteButton->click();
        QTest::mouseMove( part.m_pageView->viewport(), QPoint(width * 0.5, height * 0.2) );
    
        // Before we click into the viewport to finally open the input dialog,
        // we schedule a function to immediately close the dialog again.
        QTimer::singleShot( 0, this, [this, &goodInputDialog, &spuriousInputDialog]() {
            // this lambda gets processed by the local event loop of the upcoming QInputDialog
            goodInputDialog = dynamic_cast<QInputDialog*>( QApplication::activeModalWidget() );
            QVERIFY( goodInputDialog );
            QDialogButtonBox *buttonBox = goodInputDialog->findChild<QDialogButtonBox*>();
            buttonBox->button( QDialogButtonBox::Ok )->click();
    
            QTimer::singleShot( 0, this, [&goodInputDialog, &spuriousInputDialog]() {
                // This nested lambda is called by the local event loop of the spurious input dialog (I guess?).
                // But we shouldn't find another QInputDialog at all. If we do, it's a bug.
                spuriousInputDialog = dynamic_cast<QInputDialog*>( QApplication::activeModalWidget() );
                QVERIFY2( !spuriousInputDialog, QString("New spurious QInputDialog (0x%1) found after closing the previous QInputDialog (0x%2)")
                    .arg((quintptr)spuriousInputDialog, QT_POINTER_SIZE * 2, 16, QChar('0'))
                    .arg((quintptr)goodInputDialog, QT_POINTER_SIZE * 2, 16, QChar('0')).toUtf8().constData() );
                // the test hangs here, how to close gracefully?
            } );
        } );
    
        // Now actually cause the event to spawn the input dialog. We could also try tablet events here.
        QTest::mouseClick( part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.5, height * 0.2) );
    
        QVERIFY( goodInputDialog );
        QVERIFY( !spuriousInputDialog );
    }

REPOSITORY
  R223 Okular

REVISION DETAIL
  https://phabricator.kde.org/D15347

To: tobiasdeiminger
Cc: sander, aacid, okular-devel, maguirre, fbampaloukas, joaonetto, kezik, tfella, ngraham, darcyshen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/okular-devel/attachments/20190715/e47c15a6/attachment-0001.html>


More information about the Okular-devel mailing list