diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-11-08 10:34:31 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2016-11-29 15:02:02 +0000 |
commit | 01c029fd90162bdbbcf9534537f26138a333c570 (patch) | |
tree | 4edc0a8e4fd557f68baf31cf16e1e1fd5a7c5771 /tests/auto/widgets/qwebengineview | |
parent | a79fd91391c489ea1cd7baf717778b75e4847b92 (diff) |
Fix keyboard focus of RWHVQDW after popup
Task-number: QTBUG-56652
Change-Id: I1a6655587a9104dd817332e2eb5f886c057d8f64
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebengineview')
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 9966ad9ee..829f11586 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -31,8 +31,11 @@ #include <qdiriterator.h> #include <qstackedlayout.h> #include <qtemporarydir.h> +#include <QCompleter> #include <QLineEdit> #include <QHBoxLayout> +#include <QQuickItem> +#include <QQuickWidget> #define VERIFY_INPUTMETHOD_HINTS(actual, expect) \ QVERIFY(actual == expect); @@ -83,6 +86,7 @@ private Q_SLOTS: void inputMethodsTextFormat_data(); void inputMethodsTextFormat(); void keyboardEvents(); + void keyboardFocusAfterPopup(); }; // This will be called before the first test function is executed. @@ -1014,5 +1018,60 @@ void tst_QWebEngineView::keyboardEvents() QVERIFY(loadFinishedSpy.wait()); } +void tst_QWebEngineView::keyboardFocusAfterPopup() +{ + QScopedPointer<QWidget> containerWidget(new QWidget); + + QLineEdit *urlLine = new QLineEdit(containerWidget.data()); + QStringList urlList; + urlList << "test"; + QCompleter *completer = new QCompleter(urlList, urlLine); + completer->setCompletionMode(QCompleter::PopupCompletion); + urlLine->setCompleter(completer); + urlLine->setFocus(); + + QWebEngineView *webView = new QWebEngineView(containerWidget.data()); + QSignalSpy loadFinishedSpy(webView, SIGNAL(loadFinished(bool))); + + connect(urlLine, &QLineEdit::editingFinished, [=] { + webView->setHtml("<html><body onload=\"document.getElementById('input1').focus()\">" + " <input type='text' id='input1' />" + "</body></html>"); + + // Check whether the RenderWidgetHostView has the keyboard focus + QQuickWidget *rwhv = qobject_cast<QQuickWidget *>(webView->focusProxy()); + QVERIFY(rwhv); + QVERIFY(rwhv->hasFocus()); + QVERIFY(rwhv->rootObject()->hasFocus()); + QVERIFY(rwhv->window()->windowHandle()->isActive()); + QVERIFY(rwhv->rootObject()->hasActiveFocus()); + }); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(urlLine); + layout->addWidget(webView); + + containerWidget->setLayout(layout); + containerWidget->show(); + QTest::qWaitForWindowExposed(containerWidget.data()); + + // Trigger completer's popup and select the first suggestion + QTest::keyClick(urlLine, Qt::Key_T); + qApp->processEvents(); + QTRY_VERIFY(qApp->activePopupWidget()); + QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Down); + qApp->processEvents(); + QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Enter); + qApp->processEvents(); + + // After the load the focused window should forward the keyboard events to the webView + QVERIFY(loadFinishedSpy.wait()); + // Wait for active focus on the input field + QTRY_COMPARE(evaluateJavaScriptSync(webView->page(), "document.activeElement.id").toString(), QStringLiteral("input1")); + QTest::keyClick(qApp->focusWindow(), Qt::Key_X); + qApp->processEvents(); + QTRY_COMPARE(evaluateJavaScriptSync(webView->page(), "document.getElementById('input1').value").toString(), QStringLiteral("x")); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" |