summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-05-31 11:33:19 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-05-31 11:33:53 +0200
commitd2d5d24f86f12a2d1b0a6bc46c0d48306d7d2130 (patch)
treed67555a6c699c49a89ea10863b6c0e4c0c3f5cae /tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
parentf9e951d0946fe0fcd51e9015108f92c46ecc8138 (diff)
parent42d864c86d8c85db7b2d42f8505d962a642e4c77 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Diffstat (limited to 'tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp')
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index 0def76d6f..1c5461fa7 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -31,6 +31,7 @@
#include <QScopedPointer>
#include <QtCore/qelapsedtimer.h>
+#include <QtGui/qpa/qwindowsysteminterface.h>
#include <QtQml/QQmlEngine>
#include <QtTest/QtTest>
#include <private/qquickwebengineview_p.h>
@@ -71,6 +72,9 @@ private Q_SLOTS:
void basicRenderingSanity();
void setZoomFactor();
void printToPdf();
+ void stopSettingFocusWhenDisabled();
+ void stopSettingFocusWhenDisabled_data();
+ void inputEventForwardingDisabledWhenActiveFocusOnPressDisabled();
private:
inline QQuickWebEngineView *newWebEngineView();
@@ -514,5 +518,139 @@ void tst_QQuickWebEngineView::printToPdf()
QVERIFY(!QFile::exists(path));
}
+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("<html><head><title>Title</title></head><body>Hello"
+ "<input id=\"input\" type=\"text\"></body></html>");
+ 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<bool>("viewEnabled");
+ QTest::addColumn<bool>("activeFocusResult");
+
+ QTest::newRow("enabled view gets active focus") << true << true;
+ QTest::newRow("disabled view does not get active focus") << false << false;
+}
+
+class MouseTouchEventRecordingItem : public QQuickItem {
+public:
+ explicit MouseTouchEventRecordingItem(QQuickItem *parent = 0) :
+ QQuickItem(parent), m_eventCounter(0) {
+ setFlag(ItemHasContents);
+ setAcceptedMouseButtons(Qt::AllButtons);
+ setAcceptHoverEvents(true);
+ }
+
+ bool event(QEvent *event) Q_DECL_OVERRIDE
+ {
+ switch (event->type()) {
+ case QEvent::TabletPress:
+ case QEvent::TabletRelease:
+ case QEvent::TabletMove:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseButtonDblClick:
+ case QEvent::MouseMove:
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ case QEvent::TouchCancel:
+ case QEvent::HoverEnter:
+ case QEvent::HoverMove:
+ case QEvent::HoverLeave:
+ ++m_eventCounter;
+ event->accept();
+ return true;
+ default:
+ break;
+ }
+ return QQuickItem::event(event);
+ }
+
+ void clearEventCount()
+ {
+ m_eventCounter = 0;
+ }
+
+ int eventCount()
+ {
+ return m_eventCounter;
+ }
+
+private:
+ int m_eventCounter;
+};
+
+void tst_QQuickWebEngineView::inputEventForwardingDisabledWhenActiveFocusOnPressDisabled()
+{
+ QQuickWebEngineView *view = webEngineView();
+ MouseTouchEventRecordingItem item;
+ item.setParentItem(m_window->contentItem());
+ item.setSize(QSizeF(640, 480));
+ view->setParentItem(&item);
+ view->setSize(QSizeF(640, 480));
+ m_window->show();
+
+ // Simulate click and move of mouse, so that last known position in the application
+ // is updated, thus a mouse move event is not generated when we don't expect it.
+ QTest::mouseClick(view->window(), Qt::LeftButton);
+ item.clearEventCount();
+
+ // First disable view, so it does not receive focus on page load.
+ view->setEnabled(false);
+ view->setActiveFocusOnPress(false);
+ view->loadHtml("<html><head>"
+ "<script>"
+ "window.onload = function() { document.getElementById(\"input\").focus(); }"
+ "</script>"
+ "<title>Title</title></head><body>Hello"
+ "<input id=\"input\" type=\"text\"></body></html>");
+ QVERIFY(waitForLoadSucceeded(view));
+ QTRY_COMPARE_WITH_TIMEOUT(view->hasActiveFocus(), false, 1000);
+
+ // Enable the view back so we can try to interact with it.
+ view->setEnabled(true);
+
+ // Click on the view, to try and set focus.
+ QTest::mouseClick(view->window(), Qt::LeftButton);
+
+ // View should not have focus after click, because setActiveFocusOnPress is false.
+ QTRY_COMPARE_WITH_TIMEOUT(view->hasActiveFocus(), false, 1000);
+
+ // Now test sending various input events, to check that indeed all the input events are not
+ // forwarded to Chromium, but rather processed and accepted by the view's parent item.
+ QTest::mousePress(view->window(), Qt::LeftButton);
+ QTest::mouseRelease(view->window(), Qt::LeftButton);
+
+ QTouchDevice *device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+
+ QTest::touchEvent(view->window(), device).press(0, QPoint(0,0), view->window());
+ QTest::touchEvent(view->window(), device).move(0, QPoint(1, 1), view->window());
+ QTest::touchEvent(view->window(), device).release(0, QPoint(1, 1), view->window());
+
+ // We expect to catch 7 events - click = 2, press + release = 2, touches = 3.
+ QCOMPARE(item.eventCount(), 7);
+
+ // Manually forcing focus should still be possible.
+ view->forceActiveFocus();
+ QTRY_COMPARE_WITH_TIMEOUT(view->hasActiveFocus(), true, 1000);
+}
+
QTEST_MAIN(tst_QQuickWebEngineView)
#include "tst_qquickwebengineview.moc"