diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-15 09:45:33 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-15 15:41:16 +0100 |
commit | 5d3adf10341e1882b9c18f71591f9eb037a5f91d (patch) | |
tree | eaff30c95ed32c103d22dbb803bbddfa29bd6be2 /tests/auto | |
parent | cf6768d81ed7b9444e28ede6e26e125d5919b143 (diff) | |
parent | 61eb7b4ff6e4f2de5b5df6d7a76191cbf8dd9312 (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/3rdparty
tests/auto/quick/qmltests/qmltests.pro
tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
Change-Id: I2a1e3a83e29a1d6709f3e98fda3f7b4ab7ab297e
Diffstat (limited to 'tests/auto')
8 files changed, 193 insertions, 0 deletions
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( + "<html>" + + "<head><script>" + + "function init() {" + + " var div = document.getElementById('testDiv');" + + " div.onmouseenter = function(e) { div.innerText = 'Mouse IN' };" + + " div.onmouseleave = function(e) { div.innerText = 'Mouse OUT' };" + + "}" + + "</script></head>" + + "<body onload='init()' style='margin: 0px; padding: 0px'>" + + " <div id='testDiv' style='width: 100%; height: 100%; background-color: green' />" + + "</body>" + + "</html>"); + 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 56e61138d..bb209a70c 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -62,6 +62,7 @@ OTHER_FILES += \ $$PWD/data/tst_loadRecursionCrash.qml \ $$PWD/data/tst_loadUrl.qml \ $$PWD/data/tst_mouseClick.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/qwebenginepage/resources/bar.txt b/tests/auto/widgets/qwebenginepage/resources/bar.txt new file mode 100644 index 000000000..5716ca598 --- /dev/null +++ b/tests/auto/widgets/qwebenginepage/resources/bar.txt @@ -0,0 +1 @@ +bar diff --git a/tests/auto/widgets/qwebenginepage/resources/foo.txt b/tests/auto/widgets/qwebenginepage/resources/foo.txt new file mode 100644 index 000000000..257cc5642 --- /dev/null +++ b/tests/auto/widgets/qwebenginepage/resources/foo.txt @@ -0,0 +1 @@ +foo diff --git a/tests/auto/widgets/qwebenginepage/resources/path with spaces.txt b/tests/auto/widgets/qwebenginepage/resources/path with spaces.txt new file mode 100644 index 000000000..4f79cb0dd --- /dev/null +++ b/tests/auto/widgets/qwebenginepage/resources/path with spaces.txt @@ -0,0 +1 @@ +contents with spaces diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 47e83855c..1c9b668ae 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -202,6 +202,7 @@ private Q_SLOTS: void loadFinishedAfterNotFoundError(); void loadInSignalHandlers_data(); void loadInSignalHandlers(); + void loadFromQrc(); void restoreHistory(); void toPlainTextLoadFinishedRace_data(); @@ -4212,6 +4213,41 @@ void tst_QWebEnginePage::loadInSignalHandlers() QCOMPARE(m_page->url(), urlForSetter); } +void tst_QWebEnginePage::loadFromQrc() +{ + QWebEnginePage page; + QSignalSpy spy(&page, &QWebEnginePage::loadFinished); + + // Standard case. + page.load(QStringLiteral("qrc:///resources/foo.txt")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + QCOMPARE(toPlainTextSync(&page), QStringLiteral("foo\n")); + + // Query and fragment parts are ignored. + page.load(QStringLiteral("qrc:///resources/bar.txt?foo=1#bar")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + QCOMPARE(toPlainTextSync(&page), QStringLiteral("bar\n")); + + // Literal spaces are OK. + page.load(QStringLiteral("qrc:///resources/path with spaces.txt")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + QCOMPARE(toPlainTextSync(&page), QStringLiteral("contents with spaces\n")); + + // Escaped spaces are OK too. + page.load(QStringLiteral("qrc:///resources/path%20with%20spaces.txt")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + QCOMPARE(toPlainTextSync(&page), QStringLiteral("contents with spaces\n")); + + // Resource not found, loading fails. + page.load(QStringLiteral("qrc:///nope")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), false); +} + void tst_QWebEnginePage::restoreHistory() { QWebChannel channel; diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc index 4fddd7a3f..fc83aefa5 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc @@ -19,5 +19,8 @@ <file>resources/test2.html</file> <file>resources/testiframe.html</file> <file>resources/testiframe2.html</file> + <file>resources/foo.txt</file> + <file>resources/bar.txt</file> + <file>resources/path with spaces.txt</file> </qresource> </RCC> diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index c3c8f9b28..8d2f92d96 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -35,6 +35,7 @@ #include <qtemporarydir.h> #include <QClipboard> #include <QCompleter> +#include <QLabel> #include <QLineEdit> #include <QHBoxLayout> #include <QMenu> @@ -172,6 +173,9 @@ private Q_SLOTS: void imeCompositionQueryEvent_data(); void imeCompositionQueryEvent(); void newlineInTextarea(); + + void mouseLeave(); + #ifndef QT_NO_CLIPBOARD void globalMouseSelection(); #endif @@ -2423,5 +2427,55 @@ void tst_QWebEngineView::contextMenu() QTRY_COMPARE(view.findChildren<QMenu *>().count(), childrenCount); } +void tst_QWebEngineView::mouseLeave() +{ + QScopedPointer<QWidget> 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("<html>" + "<head><script>" + "function init() {" + " var div = document.getElementById('testDiv');" + " div.onmouseenter = function(e) { div.innerText = 'Mouse IN' };" + " div.onmouseleave = function(e) { div.innerText = 'Mouse OUT' };" + "}" + "</script></head>" + "<body onload='init()' style='margin: 0px; padding: 0px'>" + " <div id='testDiv' style='width: 100%; height: 100%; background-color: green' />" + "</body>" + "</html>"); + 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" |