summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebengineview
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@theqtcompany.com>2016-05-09 09:26:27 +0200
committerAlexandru Croitor <alexandru.croitor@theqtcompany.com>2016-05-26 09:05:08 +0000
commit4c305cba0bf7cc021fd355af574b431f0d5a057d (patch)
tree1dd294e4405179efc3a154badccfc8a891a82a05 /tests/auto/widgets/qwebengineview
parentaeea8816a7228e9e89fff15b26005eaaa38fce2d (diff)
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 <michal.klocek@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets/qwebengineview')
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index d496362f9..e66bf18cd 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -70,6 +70,8 @@ private Q_SLOTS:
#endif
void doNotSendMouseKeyboardEventsWhenDisabled();
void doNotSendMouseKeyboardEventsWhenDisabled_data();
+ void stopSettingFocusWhenDisabled();
+ void stopSettingFocusWhenDisabled_data();
};
// This will be called before the first test function is executed.
@@ -709,5 +711,35 @@ void tst_QWebEngineView::doNotSendMouseKeyboardEventsWhenDisabled_data()
QTest::newRow("disabled view does not receive events") << false << 4;
}
+void tst_QWebEngineView::stopSettingFocusWhenDisabled()
+{
+ QFETCH(bool, viewEnabled);
+ QFETCH(bool, focusResult);
+
+ QWebEngineView webView;
+ webView.resize(640, 480);
+ webView.show();
+ webView.setEnabled(viewEnabled);
+ QTest::qWaitForWindowExposed(&webView);
+
+ QSignalSpy loadSpy(&webView, SIGNAL(loadFinished(bool)));
+ webView.setHtml("<html><head><title>Title</title></head><body>Hello"
+ "<input id=\"input\" type=\"text\"></body></html>");
+ QTRY_COMPARE(loadSpy.count(), 1);
+
+ QTRY_COMPARE_WITH_TIMEOUT(webView.hasFocus(), focusResult, 1000);
+ evaluateJavaScriptSync(webView.page(), "document.getElementById(\"input\").focus()");
+ QTRY_COMPARE_WITH_TIMEOUT(webView.hasFocus(), focusResult, 1000);
+}
+
+void tst_QWebEngineView::stopSettingFocusWhenDisabled_data()
+{
+ QTest::addColumn<bool>("viewEnabled");
+ QTest::addColumn<bool>("focusResult");
+
+ QTest::newRow("enabled view gets focus") << true << true;
+ QTest::newRow("disabled view does not get focus") << false << false;
+}
+
QTEST_MAIN(tst_QWebEngineView)
#include "tst_qwebengineview.moc"