From 4c305cba0bf7cc021fd355af574b431f0d5a057d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 9 May 2016 09:26:27 +0200 Subject: Disabled WebEngine views should not receive focus. Currently if a QWebEngineView or a QQuickWebEngineView is disabled using setEnabled(false), after loading a web page, the views are automatically focused, and a user might see a blinking caret in an html input for example, even though the user can't interact with it. Fix consists in not calling the Focus() method whenever a view is disabled. Change-Id: I1014fb5898a5ddf01a4e9b14c3eaf5d4006e5131 Task-number: QTBUG-53159 Reviewed-by: Michal Klocek --- .../tst_qquickwebengineview.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp') diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 60e495137..d39a6df54 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -61,6 +61,8 @@ private Q_SLOTS: void inputMethodHints(); void basicRenderingSanity(); void setZoomFactor(); + void stopSettingFocusWhenDisabled(); + void stopSettingFocusWhenDisabled_data(); private: inline QQuickWebEngineView *newWebEngineView(); @@ -481,5 +483,33 @@ void tst_QQuickWebEngineView::setZoomFactor() QVERIFY(qFuzzyCompare(view->zoomFactor(), 2.5)); } +void tst_QQuickWebEngineView::stopSettingFocusWhenDisabled() +{ + QFETCH(bool, viewEnabled); + QFETCH(bool, activeFocusResult); + + QQuickWebEngineView *view = webEngineView(); + m_window->show(); + view->setSize(QSizeF(640, 480)); + view->setEnabled(viewEnabled); + view->loadHtml("TitleHello" + ""); + QVERIFY(waitForLoadSucceeded(view)); + + // When enabled, the view should get active focus after the page is loaded. + QTRY_COMPARE_WITH_TIMEOUT(view->hasActiveFocus(), activeFocusResult, 1000); + view->runJavaScript("document.getElementById(\"input\").focus()"); + QTRY_COMPARE_WITH_TIMEOUT(view->hasActiveFocus(), activeFocusResult, 1000); +} + +void tst_QQuickWebEngineView::stopSettingFocusWhenDisabled_data() +{ + QTest::addColumn("viewEnabled"); + QTest::addColumn("activeFocusResult"); + + QTest::newRow("enabled view gets active focus") << true << true; + QTest::newRow("disabled view does not get active focus") << false << false; +} + QTEST_MAIN(tst_QQuickWebEngineView) #include "tst_qquickwebengineview.moc" -- cgit v1.2.3