From 423b399a3336ed5832ac12fe0bb9c4c3eebc1c82 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Wed, 13 Aug 2014 11:13:28 +0200 Subject: Fix uncalled callbacks with findText Calling findText successively might prevent the previous pending FindReply to be sent, which would leak the callback on the application side. This would cause a crash in qupzilla since we empty all pending callbacks in the QWebEnginePage's destructor to catch this kind of issue. This also renames lastRequestId to nextRequestId to make it clear that this is the ID generator for everything, including findText, and that lastFindRequestId is only a tracker. Change-Id: Ia78d553a58ed31af7237aad8772fa9828560c6d4 Reviewed-by: Andras Becsi --- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index ca3740715..70fbba128 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -175,6 +175,7 @@ private Q_SLOTS: void testStopScheduledPageRefresh(); void findText(); void findTextResult(); + void findTextSuccessiveShouldCallAllCallbacks(); void supportedContentType(); // [Qt] tst_QWebEnginePage::infiniteLoopJS() timeouts with DFG JIT // https://bugs.webkit.org/show_bug.cgi?id=79040 @@ -3254,6 +3255,29 @@ void tst_QWebEnginePage::findTextResult() QCOMPARE(findTextSync(m_page, ""), false); } +void tst_QWebEnginePage::findTextSuccessiveShouldCallAllCallbacks() +{ + CallbackSpy spy1; + CallbackSpy spy2; + CallbackSpy spy3; + CallbackSpy spy4; + CallbackSpy spy5; + QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool))); + m_view->setHtml(QString("
abcdefg abcdefg abcdefg abcdefg abcdefg
")); + QTRY_COMPARE(loadSpy.count(), 1); + m_page->findText("abcde", 0, spy1.ref()); + m_page->findText("abcd", 0, spy2.ref()); + m_page->findText("abc", 0, spy3.ref()); + m_page->findText("ab", 0, spy4.ref()); + m_page->findText("a", 0, spy5.ref()); + spy5.waitForResult(); + QVERIFY(spy1.wasCalled()); + QVERIFY(spy2.wasCalled()); + QVERIFY(spy3.wasCalled()); + QVERIFY(spy4.wasCalled()); + QVERIFY(spy5.wasCalled()); +} + static QString getMimeTypeForExtension(const QString &ext) { QMimeType mimeType = QMimeDatabase().mimeTypeForFile(QStringLiteral("filename.") + ext.toLower(), QMimeDatabase::MatchExtension); -- cgit v1.2.3