diff options
Diffstat (limited to 'tests/auto/quick/qquickwindow')
-rw-r--r-- | tests/auto/quick/qquickwindow/data/windowattached.qml | 4 | ||||
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 248 |
2 files changed, 209 insertions, 43 deletions
diff --git a/tests/auto/quick/qquickwindow/data/windowattached.qml b/tests/auto/quick/qquickwindow/data/windowattached.qml index 0e3f1d4b62..a9f052d55e 100644 --- a/tests/auto/quick/qquickwindow/data/windowattached.qml +++ b/tests/auto/quick/qquickwindow/data/windowattached.qml @@ -7,6 +7,8 @@ Rectangle { height: 100 property bool windowActive: root.Window.active property Item contentItem: root.Window.contentItem + property int windowWidth: root.Window.width + property int windowHeight: root.Window.height Text { objectName: "rectangleWindowText" anchors.centerIn: parent @@ -22,6 +24,8 @@ Rectangle { anchors.centerIn: parent text: (extraWindow.active ? "active" : "inactive") + "\nvisibility: " + Window.visibility property Item contentItem: Window.contentItem + property int windowWidth: Window.width + property int windowHeight: Window.height } } } diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index f638505c72..dfe5276e8e 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -290,6 +290,7 @@ private slots: touchDeviceWithVelocity->setCapabilities(QTouchDevice::Position | QTouchDevice::Velocity); QWindowSystemInterface::registerTouchDevice(touchDeviceWithVelocity); } + void cleanup(); void openglContextCreatedSignal(); void aboutToStopSignal(); @@ -365,6 +366,7 @@ private slots: void testRenderJob(); + void testHoverChildMouseEventFilter(); private: QTouchDevice *touchDevice; QTouchDevice *touchDeviceWithVelocity; @@ -372,6 +374,11 @@ private: Q_DECLARE_METATYPE(QOpenGLContext *); +void tst_qquickwindow::cleanup() +{ + QVERIFY(QGuiApplication::topLevelWindows().isEmpty()); +} + void tst_qquickwindow::openglContextCreatedSignal() { qRegisterMetaType<QOpenGLContext *>(); @@ -379,6 +386,7 @@ void tst_qquickwindow::openglContextCreatedSignal() QQuickWindow window; QSignalSpy spy(&window, SIGNAL(openglContextCreated(QOpenGLContext*))); + window.setTitle(QTest::currentTestFunction()); window.show(); QTest::qWaitForWindowExposed(&window); @@ -391,6 +399,7 @@ void tst_qquickwindow::openglContextCreatedSignal() void tst_qquickwindow::aboutToStopSignal() { QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.show(); QTest::qWaitForWindowExposed(&window); @@ -407,6 +416,7 @@ void tst_qquickwindow::constantUpdates() QQuickWindow window; window.resize(250, 250); ConstantUpdateItem item(window.contentItem()); + window.setTitle(QTest::currentTestFunction()); window.show(); QSignalSpy beforeSpy(&window, SIGNAL(beforeSynchronizing())); @@ -423,6 +433,7 @@ void tst_qquickwindow::constantUpdatesOnWindow_data() QTest::addColumn<QByteArray>("signal"); QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.setGeometry(100, 100, 300, 200); window.show(); QTest::qWaitForWindowExposed(&window); @@ -457,6 +468,7 @@ void tst_qquickwindow::constantUpdatesOnWindow() QFETCH(QByteArray, signal); QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.setGeometry(100, 100, 300, 200); bool ok = connect(&window, signal.constData(), &window, SLOT(update()), Qt::DirectConnection); @@ -487,6 +499,7 @@ void tst_qquickwindow::touchEvent_basic() QQuickWindow *window = new QQuickWindow; QScopedPointer<QQuickWindow> cleanup(window); + window->setTitle(QTest::currentTestFunction()); window->resize(250, 250); window->setPosition(100, 100); @@ -620,6 +633,7 @@ void tst_qquickwindow::touchEvent_propagation() window->resize(250, 250); window->setPosition(100, 100); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -753,6 +767,7 @@ void tst_qquickwindow::touchEvent_cancel() window->resize(250, 250); window->setPosition(100, 100); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -786,6 +801,7 @@ void tst_qquickwindow::touchEvent_reentrant() window->resize(250, 250); window->setPosition(100, 100); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -823,6 +839,7 @@ void tst_qquickwindow::touchEvent_velocity() QScopedPointer<QQuickWindow> cleanup(window); window->resize(250, 250); window->setPosition(100, 100); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); QTest::qWait(10); @@ -884,6 +901,7 @@ void tst_qquickwindow::mouseFromTouch_basic() QScopedPointer<QQuickWindow> cleanup(window); window->resize(250, 250); window->setPosition(100, 100); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); QTest::qWait(10); @@ -952,10 +970,11 @@ void tst_qquickwindow::mouseFromTouch_basic() void tst_qquickwindow::clearWindow() { QQuickWindow *window = new QQuickWindow; + window->setTitle(QTest::currentTestFunction()); QQuickItem *item = new QQuickItem; item->setParentItem(window->contentItem()); - QVERIFY(item->window() == window); + QCOMPARE(item->window(), window); delete window; @@ -972,6 +991,7 @@ void tst_qquickwindow::mouseFiltering() QScopedPointer<QQuickWindow> cleanup(window); window->resize(250, 250); window->setPosition(100, 100); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1032,6 +1052,7 @@ void tst_qquickwindow::clearColor() window->resize(250, 250); window->setPosition(100, 100); window->setColor(Qt::blue); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); QCOMPARE(window->color(), QColor(Qt::blue)); @@ -1048,6 +1069,7 @@ void tst_qquickwindow::defaultState() QQuickWindow *qmlWindow = qobject_cast<QQuickWindow*>(created); QVERIFY(qmlWindow); + qmlWindow->setTitle(QTest::currentTestFunction()); QQuickWindow cppWindow; cppWindow.show(); @@ -1068,6 +1090,7 @@ void tst_qquickwindow::grab() QFETCH(bool, visible); QQuickWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(' ') + QLatin1String(QTest::currentDataTag())); window.setColor(Qt::red); window.resize(250, 250); @@ -1092,6 +1115,7 @@ void tst_qquickwindow::multipleWindows() for (int i=0; i<6; ++i) { QQuickWindow *c = new QQuickWindow(); + c->setTitle(QLatin1String(QTest::currentTestFunction()) + QString::number(i)); c->setColor(Qt::GlobalColor(Qt::red + i)); c->resize(300, 200); c->setPosition(100 + i * 30, 100 + i * 20); @@ -1124,6 +1148,7 @@ void tst_qquickwindow::animationsWhileHidden() QQuickWindow *window = qobject_cast<QQuickWindow*>(created); QVERIFY(window); + window->setTitle(QTest::currentTestFunction()); QVERIFY(window->isVisible()); // Now hide the window and verify that it went off screen @@ -1185,6 +1210,7 @@ void tst_qquickwindow::headless() window->setPersistentOpenGLContext(false); window->setPersistentSceneGraph(false); QVERIFY(window); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1234,6 +1260,7 @@ void tst_qquickwindow::headless() void tst_qquickwindow::noUpdateWhenNothingChanges() { QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.setGeometry(100, 100, 300, 200); QQuickRectangle rect(window.contentItem()); @@ -1270,6 +1297,7 @@ void tst_qquickwindow::focusObject() QQuickWindow *window = qobject_cast<QQuickWindow*>(created); QVERIFY(window); + window->setTitle(QTest::currentTestFunction()); QSignalSpy focusObjectSpy(window, SIGNAL(focusObjectChanged(QObject*))); @@ -1308,6 +1336,7 @@ void tst_qquickwindow::focusReason() QScopedPointer<QQuickWindow> cleanup(window); window->resize(200, 200); window->show(); + window->setTitle(QTest::currentTestFunction()); QVERIFY(QTest::qWaitForWindowExposed(window)); QQuickItem *firstItem = new QQuickItem; @@ -1333,6 +1362,7 @@ void tst_qquickwindow::ignoreUnhandledMouseEvents() { QQuickWindow *window = new QQuickWindow; QScopedPointer<QQuickWindow> cleanup(window); + window->setTitle(QTest::currentTestFunction()); window->resize(100, 100); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1379,6 +1409,7 @@ void tst_qquickwindow::ownershipRootItem() QQuickWindow *window = qobject_cast<QQuickWindow*>(created); QVERIFY(window); + window->setTitle(QTest::currentTestFunction()); window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1395,7 +1426,9 @@ void tst_qquickwindow::ownershipRootItem() void tst_qquickwindow::cursor() { QQuickWindow window; - window.resize(320, 240); + window.setTitle(QTest::currentTestFunction()); + window.setFramePosition(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(50, 50)); + window.resize(320, 290); QQuickItem parentItem; parentItem.setPosition(QPointF(0, 0)); @@ -1550,6 +1583,8 @@ void tst_qquickwindow::hideThenDelete() { QQuickWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(' ') + + QLatin1String(QTest::currentDataTag())); window.setColor(Qt::red); window.setPersistentSceneGraph(persistentSG); @@ -1576,8 +1611,8 @@ void tst_qquickwindow::hideThenDelete() else QVERIFY(openglDestroyed->size() == 0); } else { - QVERIFY(sgInvalidated->size() == 0); - QVERIFY(openglDestroyed->size() == 0); + QCOMPARE(sgInvalidated->size(), 0); + QCOMPARE(openglDestroyed->size(), 0); } } } @@ -1612,6 +1647,7 @@ void tst_qquickwindow::showHideAnimate() void tst_qquickwindow::testExpose() { QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.setGeometry(100, 100, 300, 200); window.show(); @@ -1636,11 +1672,12 @@ void tst_qquickwindow::requestActivate() QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("active.qml")); - QQuickWindow *window1 = qobject_cast<QQuickWindow *>(component.create()); - QVERIFY(window1); + QScopedPointer<QQuickWindow> window1(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window1.isNull()); + window1->setTitle(QTest::currentTestFunction()); QWindowList windows = QGuiApplication::topLevelWindows(); - QVERIFY(windows.size() == 2); + QCOMPARE(windows.size(), 2); for (int i = 0; i < windows.size(); ++i) { if (windows.at(i)->objectName() == window1->objectName()) { @@ -1648,14 +1685,14 @@ void tst_qquickwindow::requestActivate() break; } } - QVERIFY(windows.size() == 1); - QVERIFY(windows.at(0)->objectName() == "window2"); + QCOMPARE(windows.size(), 1); + QCOMPARE(windows.at(0)->objectName(), QLatin1String("window2")); window1->show(); QVERIFY(QTest::qWaitForWindowExposed(windows.at(0))); //We wait till window 2 comes up window1->requestActivate(); // and then transfer the focus to window1 - QTRY_VERIFY(QGuiApplication::focusWindow() == window1); + QTRY_COMPARE(QGuiApplication::focusWindow(), window1.data()); QVERIFY(window1->isActive() == true); QQuickItem *item = QQuickVisualTestUtil::findItem<QQuickItem>(window1->contentItem(), "item1"); @@ -1666,20 +1703,19 @@ void tst_qquickwindow::requestActivate() QMouseEvent me(QEvent::MouseButtonPress, pos, window1->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QSpontaneKeyEvent::setSpontaneous(&me); - if (!qApp->notify(window1, &me)) { + if (!qApp->notify(window1.data(), &me)) { QString warning = QString::fromLatin1("Mouse event MousePress not accepted by receiving window"); QWARN(warning.toLatin1().data()); } me = QMouseEvent(QEvent::MouseButtonPress, pos, window1->mapToGlobal(pos), Qt::LeftButton, 0, Qt::NoModifier); QSpontaneKeyEvent::setSpontaneous(&me); - if (!qApp->notify(window1, &me)) { + if (!qApp->notify(window1.data(), &me)) { QString warning = QString::fromLatin1("Mouse event MouseRelease not accepted by receiving window"); QWARN(warning.toLatin1().data()); } - QTRY_VERIFY(QGuiApplication::focusWindow() == windows.at(0)); + QTRY_COMPARE(QGuiApplication::focusWindow(), windows.at(0)); QVERIFY(windows.at(0)->isActive()); - delete window1; } void tst_qquickwindow::testWindowVisibilityOrder() @@ -1687,12 +1723,13 @@ void tst_qquickwindow::testWindowVisibilityOrder() QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("windoworder.qml")); - QQuickWindow *window1 = qobject_cast<QQuickWindow *>(component.create()); + QScopedPointer<QQuickWindow> window1(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window1.isNull()); + window1->setTitle(QTest::currentTestFunction()); QQuickWindow *window2 = window1->property("win2").value<QQuickWindow*>(); QQuickWindow *window3 = window1->property("win3").value<QQuickWindow*>(); QQuickWindow *window4 = window1->property("win4").value<QQuickWindow*>(); QQuickWindow *window5 = window1->property("win5").value<QQuickWindow*>(); - QVERIFY(window1); QVERIFY(window2); QVERIFY(window3); @@ -1701,7 +1738,7 @@ void tst_qquickwindow::testWindowVisibilityOrder() QWindowList windows = QGuiApplication::topLevelWindows(); QTRY_COMPARE(windows.size(), 5); - QVERIFY(window3 == QGuiApplication::focusWindow()); + QCOMPARE(window3, QGuiApplication::focusWindow()); QVERIFY(window1->isActive()); QVERIFY(window2->isActive()); QVERIFY(window3->isActive()); @@ -1723,17 +1760,18 @@ void tst_qquickwindow::blockClosing() QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("ucantclosethis.qml")); - QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create()); - QVERIFY(window); + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window.isNull()); + window->setTitle(QTest::currentTestFunction()); window->show(); - QTest::qWaitForWindowExposed(window); + QTest::qWaitForWindowExposed(window.data()); QVERIFY(window->isVisible()); - QWindowSystemInterface::handleCloseEvent(window); + QWindowSystemInterface::handleCloseEvent(window.data()); QVERIFY(window->isVisible()); - QWindowSystemInterface::handleCloseEvent(window); + QWindowSystemInterface::handleCloseEvent(window.data()); QVERIFY(window->isVisible()); window->setProperty("canCloseThis", true); - QWindowSystemInterface::handleCloseEvent(window); + QWindowSystemInterface::handleCloseEvent(window.data()); QTRY_VERIFY(!window->isVisible()); } @@ -1742,17 +1780,18 @@ void tst_qquickwindow::blockCloseMethod() QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("ucantclosethis.qml")); - QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create()); - QVERIFY(window); + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window.isNull()); + window->setTitle(QTest::currentTestFunction()); window->show(); - QTest::qWaitForWindowExposed(window); + QTest::qWaitForWindowExposed(window.data()); QVERIFY(window->isVisible()); - QVERIFY(QMetaObject::invokeMethod(window, "close", Qt::DirectConnection)); + QVERIFY(QMetaObject::invokeMethod(window.data(), "close", Qt::DirectConnection)); QVERIFY(window->isVisible()); - QVERIFY(QMetaObject::invokeMethod(window, "close", Qt::DirectConnection)); + QVERIFY(QMetaObject::invokeMethod(window.data(), "close", Qt::DirectConnection)); QVERIFY(window->isVisible()); window->setProperty("canCloseThis", true); - QVERIFY(QMetaObject::invokeMethod(window, "close", Qt::DirectConnection)); + QVERIFY(QMetaObject::invokeMethod(window.data(), "close", Qt::DirectConnection)); QTRY_VERIFY(!window->isVisible()); } @@ -1762,15 +1801,16 @@ void tst_qquickwindow::crashWhenHoverItemDeleted() QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("hoverCrash.qml")); - QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create()); - QVERIFY(window); + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window.isNull()); + window->setTitle(QTest::currentTestFunction()); window->show(); - QTest::qWaitForWindowExposed(window); + QTest::qWaitForWindowExposed(window.data()); // Simulate a move from the first rectangle to the second. Crash will happen in here // Moving instantaneously from (0, 99) to (0, 102) does not cause the crash for (int i = 99; i < 102; ++i) { - QTest::mouseMove(window, QPoint(0, i)); + QTest::mouseMove(window.data(), QPoint(0, i)); } } @@ -1780,10 +1820,11 @@ void tst_qquickwindow::unloadSubWindow() QQmlEngine engine; QQmlComponent component(&engine); component.loadUrl(testFileUrl("unloadSubWindow.qml")); - QQuickWindow *window = qobject_cast<QQuickWindow *>(component.create()); - QVERIFY(window); + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window.isNull()); + window->setTitle(QTest::currentTestFunction()); window->show(); - QTest::qWaitForWindowExposed(window); + QTest::qWaitForWindowExposed(window.data()); QPointer<QQuickWindow> transient; QTRY_VERIFY(transient = window->property("transientWindow").value<QQuickWindow*>()); QTest::qWaitForWindowExposed(transient); @@ -1801,6 +1842,7 @@ void tst_qquickwindow::qobjectEventFilter_touch() window.resize(250, 250); window.setPosition(100, 100); + window.setTitle(QTest::currentTestFunction()); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); @@ -1826,6 +1868,7 @@ void tst_qquickwindow::qobjectEventFilter_key() window.resize(250, 250); window.setPosition(100, 100); + window.setTitle(QTest::currentTestFunction()); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); @@ -1854,7 +1897,9 @@ void tst_qquickwindow::qobjectEventFilter_mouse() window.resize(250, 250); window.setPosition(100, 100); + window.setTitle(QTest::currentTestFunction()); window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); TestTouchItem *item = new TestTouchItem(window.contentItem()); @@ -1875,6 +1920,7 @@ void tst_qquickwindow::qobjectEventFilter_mouse() void tst_qquickwindow::animatingSignal() { QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.setGeometry(100, 100, 300, 200); QSignalSpy spy(&window, SIGNAL(afterAnimating())); @@ -1889,6 +1935,7 @@ void tst_qquickwindow::animatingSignal() void tst_qquickwindow::contentItemSize() { QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); QQuickItem *contentItem = window.contentItem(); QVERIFY(contentItem); QCOMPARE(QSize(contentItem->width(), contentItem->height()), window.size()); @@ -1942,6 +1989,7 @@ void tst_qquickwindow::defaultSurfaceFormat() QSurfaceFormat::setDefaultFormat(format); QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); @@ -1965,11 +2013,14 @@ void tst_qquickwindow::defaultSurfaceFormat() void tst_qquickwindow::attachedProperty() { QQuickView view(testFileUrl("windowattached.qml")); + view.setTitle(QTest::currentTestFunction()); view.show(); view.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()->property("windowActive").toBool()); QCOMPARE(view.rootObject()->property("contentItem").value<QQuickItem*>(), view.contentItem()); + QCOMPARE(view.rootObject()->property("windowWidth").toInt(), view.width()); + QCOMPARE(view.rootObject()->property("windowHeight").toInt(), view.height()); QQuickWindow *innerWindow = view.rootObject()->findChild<QQuickWindow*>("extraWindow"); QVERIFY(innerWindow); @@ -1980,6 +2031,8 @@ void tst_qquickwindow::attachedProperty() QVERIFY(text); QCOMPARE(text->text(), QLatin1String("active\nvisibility: 2")); QCOMPARE(text->property("contentItem").value<QQuickItem*>(), innerWindow->contentItem()); + QCOMPARE(text->property("windowWidth").toInt(), innerWindow->width()); + QCOMPARE(text->property("windowHeight").toInt(), innerWindow->height()); } class RenderJob : public QRunnable @@ -2002,6 +2055,7 @@ void tst_qquickwindow::testRenderJob() QList<QQuickWindow::RenderStage> completedJobs; QQuickWindow window; + window.setTitle(QTest::currentTestFunction()); QQuickWindow::RenderStage stages[] = { QQuickWindow::BeforeSynchronizingStage, @@ -2034,6 +2088,114 @@ void tst_qquickwindow::testRenderJob() QCOMPARE(RenderJob::deleted, 5); } +class EventCounter : public QQuickRectangle +{ + Q_OBJECT +public: + EventCounter(QQuickItem *parent = 0) + : QQuickRectangle(parent) + { } + + void addFilterEvent(QEvent::Type type) + { + m_returnTrueForType.append(type); + } + + int childMouseEventFilterEventCount(QEvent::Type type) + { + return m_childMouseEventFilterEventCount.value(type, 0); + } + + int eventCount(QEvent::Type type) + { + return m_eventCount.value(type, 0); + } + + void reset() + { + m_eventCount.clear(); + m_childMouseEventFilterEventCount.clear(); + } +protected: + bool childMouseEventFilter(QQuickItem *, QEvent *event) Q_DECL_OVERRIDE + { + m_childMouseEventFilterEventCount[event->type()]++; + return m_returnTrueForType.contains(event->type()); + } + + bool event(QEvent *event) Q_DECL_OVERRIDE + { + m_eventCount[event->type()]++; + return QQuickRectangle::event(event); + } + + +private: + QList<QEvent::Type> m_returnTrueForType; + QMap<QEvent::Type, int> m_childMouseEventFilterEventCount; + QMap<QEvent::Type, int> m_eventCount; +}; + +void tst_qquickwindow::testHoverChildMouseEventFilter() +{ + QQuickWindow window; + + window.resize(250, 250); + window.setPosition(100, 100); + window.setTitle(QTest::currentTestFunction()); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + EventCounter *bottomItem = new EventCounter(window.contentItem()); + bottomItem->setObjectName("Bottom Item"); + bottomItem->setSize(QSizeF(150, 150)); + bottomItem->setAcceptHoverEvents(true); + + EventCounter *middleItem = new EventCounter(bottomItem); + middleItem->setObjectName("Middle Item"); + middleItem->setPosition(QPointF(50, 50)); + middleItem->setSize(QSizeF(150, 150)); + middleItem->setAcceptHoverEvents(true); + + EventCounter *topItem = new EventCounter(middleItem); + topItem->setObjectName("Top Item"); + topItem->setPosition(QPointF(50, 50)); + topItem->setSize(QSizeF(150, 150)); + topItem->setAcceptHoverEvents(true); + + QPoint pos(10, 10); + + QTest::mouseMove(&window, pos); + + QTRY_VERIFY(bottomItem->eventCount(QEvent::HoverEnter) > 0); + QCOMPARE(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter), 0); + QCOMPARE(middleItem->eventCount(QEvent::HoverEnter), 0); + QCOMPARE(topItem->eventCount(QEvent::HoverEnter), 0); + bottomItem->reset(); + + pos = QPoint(60, 60); + QTest::mouseMove(&window, pos); + QTRY_VERIFY(middleItem->eventCount(QEvent::HoverEnter) > 0); + QCOMPARE(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter), 0); + middleItem->reset(); + + pos = QPoint(70,70); + bottomItem->setFiltersChildMouseEvents(true); + QTest::mouseMove(&window, pos); + QTRY_VERIFY(middleItem->eventCount(QEvent::HoverMove) > 0); + QVERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverMove) > 0); + QCOMPARE(topItem->eventCount(QEvent::HoverEnter), 0); + bottomItem->reset(); + middleItem->reset(); + + pos = QPoint(110,110); + bottomItem->addFilterEvent(QEvent::HoverEnter); + QTest::mouseMove(&window, pos); + QTRY_VERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter) > 0); + QCOMPARE(topItem->eventCount(QEvent::HoverEnter), 0); + QCOMPARE(middleItem->eventCount(QEvent::HoverEnter), 0); +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" |