diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-06-20 13:38:11 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-06-20 18:27:44 +0200 |
commit | 25ccef35eb19fd656eba2a7abe5419972ed28552 (patch) | |
tree | e0c92532c3c70135d0a547675414e95d21a66822 /tests | |
parent | 3398abfc1b5b789d11592aada0b5860e36a50041 (diff) | |
parent | e91f09947b55dda8a13b2aeb0963836dee2ece8d (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
src/3rdparty
src/core/permission_manager_qt.cpp
src/core/renderer/web_channel_ipc_transport.cpp
src/core/renderer/web_channel_ipc_transport.h
Change-Id: I25fd8ed7c433dadce44d8ac1e39f86e211ec25f0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qmltests/data/TestWebEngineView.qml | 2 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/test4.html | 11 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_filePicker.qml | 18 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_scrollPosition.qml | 81 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/qmltests.pro | 1 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginepage/BLACKLIST | 3 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 36 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 25 |
8 files changed, 162 insertions, 15 deletions
diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml index 34fc5fb2f..0d2a34645 100644 --- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml +++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtWebEngine 1.2 +import QtWebEngine 1.3 WebEngineView { property var loadStatus: null diff --git a/tests/auto/quick/qmltests/data/test4.html b/tests/auto/quick/qmltests/data/test4.html index 8f75af606..142b53668 100644 --- a/tests/auto/quick/qmltests/data/test4.html +++ b/tests/auto/quick/qmltests/data/test4.html @@ -12,6 +12,17 @@ <meta name="viewport" content="initial-scale=2.0"/> </head> <body> + <button onclick="scrollWin()", id="scroll">Click me to scroll!</button><br><br> + + <script> + window.onload = function() { + document.getElementById("scroll").focus(); + } + + function scrollWin() { + window.scrollTo(0, 600); + } + </script> <div id="content"> bla00<br/> bla01<br/> diff --git a/tests/auto/quick/qmltests/data/tst_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml index 117141935..4e74af733 100644 --- a/tests/auto/quick/qmltests/data/tst_filePicker.qml +++ b/tests/auto/quick/qmltests/data/tst_filePicker.qml @@ -68,10 +68,8 @@ TestWebEngineView { FilePickerParams.selectedFilesUrl.push(Qt.resolvedUrl("test1.html")) keyPress(Qt.Key_Enter) // Focus is on the button. Open FileDialog. - wait(100) // The ui delegate is invoked asynchronously - verify(FilePickerParams.filePickerOpened) - titleSpy.wait() - compare(webEngineView.title, "test1.html") + tryCompare(FilePickerParams, "filePickerOpened", true) + tryCompare(webEngineView, "title", "test1.html") } function test_acceptMultipleFilesSelection() { @@ -83,10 +81,8 @@ TestWebEngineView { FilePickerParams.selectedFilesUrl.push(Qt.resolvedUrl("test2.html")) keyPress(Qt.Key_Enter) // Focus is on the button. Open FileDialog. - wait(100) - verify(FilePickerParams.filePickerOpened) - titleSpy.wait() - compare(webEngineView.title, "test1.html,test2.html") + tryCompare(FilePickerParams, "filePickerOpened", true) + tryCompare(webEngineView, "title", "test1.html,test2.html") } function test_acceptDirectory() { @@ -97,10 +93,8 @@ TestWebEngineView { FilePickerParams.selectedFilesUrl.push(Qt.resolvedUrl("../data")) keyPress(Qt.Key_Enter) // Focus is on the button. Open FileDialog. - wait(100) // The ui delegate is invoked asynchronously - verify(FilePickerParams.filePickerOpened) - titleSpy.wait() - compare(webEngineView.title, "data") + tryCompare(FilePickerParams, "filePickerOpened", true) + tryCompare(webEngineView, "title", "data") } function test_reject() { diff --git a/tests/auto/quick/qmltests/data/tst_scrollPosition.qml b/tests/auto/quick/qmltests/data/tst_scrollPosition.qml new file mode 100644 index 000000000..08bb0f3b4 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_scrollPosition.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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.2 +import QtTest 1.0 +import QtWebEngine 1.3 + +TestWebEngineView { + id: webEngineView + width: 300 + height: 400 + + property var testUrl: Qt.resolvedUrl("test4.html") + + SignalSpy { + id: scrollPositionSpy + target: webEngineView + signalName: "onScrollPositionChanged" + } + + TestCase { + name: "ScrollPosition" + when: windowShown + + function init() { + webEngineView.url = Qt.resolvedUrl("about:blank"); + verify(webEngineView.waitForLoadSucceeded()); + } + + function test_scrollPosition() { + webEngineView.url = testUrl; + verify(webEngineView.waitForLoadSucceeded()); + + keyPress(Qt.Key_Return); // Focus is on the scroll button. + + tryCompare(scrollPositionSpy, "count", 1); + compare(webEngineView.scrollPosition.x, 0); + compare(webEngineView.scrollPosition.y, 600); + } + + function test_scrollPositionAfterReload() { + webEngineView.url = testUrl; + verify(webEngineView.waitForLoadSucceeded()); + tryCompare(webEngineView.scrollPosition, "y", 0); + + keyPress(Qt.Key_Return); // Focus is on the scroll button. + scrollPositionSpy.wait(); + + webEngineView.reload(); + verify(webEngineView.waitForLoadSucceeded()); + + tryCompare(webEngineView.scrollPosition, "x", 0); + tryCompare(webEngineView.scrollPosition, "y", 600); + } + } +} diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index 64f7414ce..0158a7268 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -59,6 +59,7 @@ OTHER_FILES += \ $$PWD/data/tst_navigationRequested.qml \ $$PWD/data/tst_properties.qml \ $$PWD/data/tst_runJavaScript.qml \ + $$PWD/data/tst_scrollPosition.qml \ $$PWD/data/tst_titleChanged.qml \ $$PWD/data/tst_unhandledKeyEventPropagation.qml \ $$PWD/data/tst_userScripts.qml \ diff --git a/tests/auto/widgets/qwebenginepage/BLACKLIST b/tests/auto/widgets/qwebenginepage/BLACKLIST index fcd36ba83..507fb7dbd 100644 --- a/tests/auto/widgets/qwebenginepage/BLACKLIST +++ b/tests/auto/widgets/qwebenginepage/BLACKLIST @@ -1,2 +1,5 @@ [macCopyUnicodeToClipboard] osx + +[getUserMediaRequest] +windows diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index b39c07fc2..2461a588b 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -236,6 +236,7 @@ private Q_SLOTS: void toPlainTextLoadFinishedRace_data(); void toPlainTextLoadFinishedRace(); void setZoomFactor(); + void mouseButtonTranslation(); void printToPdf(); @@ -4886,5 +4887,40 @@ void tst_QWebEnginePage::printToPdf() QCOMPARE(failedInvalidLayoutSpy.waitForResult().length(), 0); } +void tst_QWebEnginePage::mouseButtonTranslation() +{ + QWebEngineView *view = new QWebEngineView; + + QSignalSpy spy(view, SIGNAL(loadFinished(bool))); + view->setHtml(QStringLiteral( + "<html><head><script>\ + var lastEvent = { 'button' : -1 }; \ + function saveLastEvent(event) { console.log(event); lastEvent = event; }; \ + </script></head>\ + <body>\ + <div style=\"height:600px;\" onmousedown=\"saveLastEvent(event)\">\ + </div>\ + </body></html>")); + view->show(); + QTest::qWaitForWindowExposed(view); + QTRY_VERIFY(spy.count() == 1); + + QVERIFY(view->focusProxy() != nullptr); + + QMouseEvent evpres(QEvent::MouseButtonPress, view->rect().center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QGuiApplication::sendEvent(view->focusProxy(), &evpres); + + QTRY_COMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.button").toInt(), 0); + QCOMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.buttons").toInt(), 1); + + QMouseEvent evpres2(QEvent::MouseButtonPress, view->rect().center(), Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier); + QGuiApplication::sendEvent(view->focusProxy(), &evpres2); + + QTRY_COMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.button").toInt(), 2); + QCOMPARE(evaluateJavaScriptSync(view->page(), "lastEvent.buttons").toInt(), 3); + + delete view; +} + QTEST_MAIN(tst_QWebEnginePage) #include "tst_qwebenginepage.moc" diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index ad10234f4..d5ecd8841 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -37,6 +37,7 @@ private Q_SLOTS: void scriptModifications(); void webChannel_data(); void webChannel(); + void noTransportWithoutWebChannel(); }; void tst_QWebEngineScript::domEditing() @@ -180,13 +181,17 @@ private: void tst_QWebEngineScript::webChannel_data() { QTest::addColumn<int>("worldId"); - QTest::newRow("MainWorld") << static_cast<int>(QWebEngineScript::MainWorld); - QTest::newRow("ApplicationWorld") << static_cast<int>(QWebEngineScript::ApplicationWorld); + QTest::addColumn<bool>("reloadFirst"); + QTest::newRow("MainWorld") << static_cast<int>(QWebEngineScript::MainWorld) << false; + QTest::newRow("ApplicationWorld") << static_cast<int>(QWebEngineScript::ApplicationWorld) << false; + QTest::newRow("MainWorldWithReload") << static_cast<int>(QWebEngineScript::MainWorld) << true; + QTest::newRow("ApplicationWorldWithReload") << static_cast<int>(QWebEngineScript::ApplicationWorld) << true; } void tst_QWebEngineScript::webChannel() { QFETCH(int, worldId); + QFETCH(bool, reloadFirst); QWebEnginePage page; TestObject testObject; QScopedPointer<QWebChannel> channel(new QWebChannel(this)); @@ -205,6 +210,11 @@ void tst_QWebEngineScript::webChannel() page.scripts().insert(script); page.setHtml(QStringLiteral("<html><body></body></html>")); waitForSignal(&page, SIGNAL(loadFinished(bool))); + if (reloadFirst) { + // Check that the transport is also reinstalled on navigation + page.triggerAction(QWebEnginePage::Reload); + waitForSignal(&page, SIGNAL(loadFinished(bool))); + } page.runJavaScript(QLatin1String( "new QWebChannel(qt.webChannelTransport," " function(channel) {" @@ -218,6 +228,17 @@ void tst_QWebEngineScript::webChannel() QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); } +void tst_QWebEngineScript::noTransportWithoutWebChannel() +{ + QWebEnginePage page; + page.setHtml(QStringLiteral("<html><body></body></html>")); + + QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); + page.triggerAction(QWebEnginePage::Reload); + waitForSignal(&page, SIGNAL(loadFinished(bool))); + QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); +} + QTEST_MAIN(tst_QWebEngineScript) #include "tst_qwebenginescript.moc" |