From 4de8486b6614896a2b84cc64b69606c7b3bd07e8 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 6 Nov 2017 16:04:45 +0100 Subject: Notify Chromium about leaving view Forward QEvent::Leave for Widget and QEvent::HoverLeave for Quick. Task-number: QTBUG-64265 Change-Id: Ide32768902956476d24b1d4115e305392b62feb3 Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qmltests/data/tst_mouseMove.qml | 96 ++++++++++++++++++++++ tests/auto/quick/qmltests/qmltests.pro | 1 + .../widgets/qwebengineview/tst_qwebengineview.cpp | 53 ++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 tests/auto/quick/qmltests/data/tst_mouseMove.qml (limited to 'tests') diff --git a/tests/auto/quick/qmltests/data/tst_mouseMove.qml b/tests/auto/quick/qmltests/data/tst_mouseMove.qml new file mode 100644 index 000000000..adb937139 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_mouseMove.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtWebEngine 1.4 + +Rectangle { + id: root + width: 200 + height: 200 + + Column { + anchors.fill: parent + Rectangle { + id: placeHolder + width: parent.width + height: 100 + color: "red" + } + + TestWebEngineView { + id: webEngineView + width: parent.width + height: 100 + + function getInnerText(element) { + var innerText; + runJavaScript("document.getElementById('" + element + "').innerText", function(result) { + innerText = result; + }); + testCase.tryVerify(function() { return innerText != undefined; }); + return innerText; + } + } + } + + TestCase { + id: testCase + name: "WebEngineViewMouseMove" + when: windowShown + + function test_mouseLeave() { + mouseMove(root, 0, 0); + webEngineView.loadHtml( + "" + + "" + + "" + + "
" + + "" + + ""); + verify(webEngineView.waitForLoadSucceeded()); + verify(!webEngineView.getInnerText("testDiv")); + + for (var i = 90; i < 110; ++i) + mouseMove(root, 50, i); + tryVerify(function() { return webEngineView.getInnerText("testDiv") == "Mouse IN" }); + + for (var i = 110; i > 90; --i) + mouseMove(root, 50, i); + tryVerify(function() { return webEngineView.getInnerText("testDiv") == "Mouse OUT" }); + } + } +} + diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index e7c5ededc..f09e5f009 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -59,6 +59,7 @@ OTHER_FILES += \ $$PWD/data/tst_loadProgress.qml \ $$PWD/data/tst_loadRecursionCrash.qml \ $$PWD/data/tst_loadUrl.qml \ + $$PWD/data/tst_mouseMove.qml \ $$PWD/data/tst_navigationHistory.qml \ $$PWD/data/tst_navigationRequested.qml \ $$PWD/data/tst_newViewRequest.qml \ diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 7f9e1cff5..04de4d951 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,8 @@ private Q_SLOTS: void imeCompositionQueryEvent_data(); void imeCompositionQueryEvent(); void newlineInTextarea(); + + void mouseLeave(); }; // This will be called before the first test function is executed. @@ -2207,5 +2210,55 @@ void tst_QWebEngineView::imeCompositionQueryEvent() QTRY_COMPARE(anchorPosQuery.value(Qt::ImAnchorPosition).toInt(), 11); } +void tst_QWebEngineView::mouseLeave() +{ + QScopedPointer containerWidget(new QWidget); + + QLabel *label = new QLabel(containerWidget.data()); + label->setStyleSheet("background-color: red;"); + label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + label->setMinimumHeight(100); + + QWebEngineView *view = new QWebEngineView(containerWidget.data()); + view->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + view->setMinimumHeight(100); + + QVBoxLayout *layout = new QVBoxLayout; + layout->setAlignment(Qt::AlignTop); + layout->setSpacing(0); + layout->setMargin(0); + layout->addWidget(label); + layout->addWidget(view); + containerWidget->setLayout(layout); + containerWidget->show(); + QVERIFY(QTest::qWaitForWindowExposed(containerWidget.data())); + QTest::mouseMove(containerWidget->windowHandle(), QPoint(0, 0)); + + auto innerText = [view]() -> QString { + return evaluateJavaScriptSync(view->page(), "document.getElementById('testDiv').innerText").toString(); + }; + + QSignalSpy loadFinishedSpy(view, SIGNAL(loadFinished(bool))); + view->setHtml("" + "" + "" + "
" + "" + ""); + QVERIFY(loadFinishedSpy.wait()); + QVERIFY(innerText().isEmpty()); + + QTest::mouseMove(containerWidget->windowHandle(), QPoint(50, 150)); + QTRY_COMPARE(innerText(), QStringLiteral("Mouse IN")); + QTest::mouseMove(containerWidget->windowHandle(), QPoint(50, 50)); + QTRY_COMPARE(innerText(), QStringLiteral("Mouse OUT")); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" -- cgit v1.2.3