diff options
Diffstat (limited to 'tests/auto')
4 files changed, 94 insertions, 27 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml index 44836d67c..07236c3be 100644 --- a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml +++ b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml @@ -83,6 +83,15 @@ TestWebEngineView { compare(webEngineView.title, "REJECTED") } + function readMousePressRecieved() { + var mousePressReceived; + runJavaScript("window.mousePressReceived", function(result) { + mousePressReceived = result; + }); + + _waitFor(function() { return mousePressReceived != undefined; }); + return mousePressReceived; + } function simulateUserGesture() { // A user gesture after page load is required since Chromium 60 to allow showing @@ -90,14 +99,7 @@ TestWebEngineView { // See https://www.chromestatus.com/feature/5082396709879808 mouseClick(webEngineView, 10, 10, Qt.LeftButton) - var mousePressReceived; - runJavaScript("window.mousePressReceived", function(result) { - mousePressReceived = result; - }); - - tryVerify(function() { - return mousePressReceived != undefined - }, 5000); + tryVerify(readMousePressRecieved) } function test_confirmClose() { diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 5c02d3312..63569bd4b 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -482,7 +482,9 @@ void tst_QWebEnginePage::pasteImage() "window.myImageDataURL ? window.myImageDataURL.length : 0").toInt() > 0); QByteArray data = evaluateJavaScriptSync(page, "window.myImageDataURL").toByteArray(); data.remove(0, data.indexOf(";base64,") + 8); - const QImage image = QImage::fromData(QByteArray::fromBase64(data), "PNG"); + QImage image = QImage::fromData(QByteArray::fromBase64(data), "PNG"); + if (image.format() == QImage::Format_RGB32) + image.reinterpretAsFormat(QImage::Format_ARGB32); QCOMPARE(image, origImage); } @@ -3586,7 +3588,7 @@ void tst_QWebEnginePage::scrollPosition() view.setFixedSize(200,200); view.show(); - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QSignalSpy loadSpy(view.page(), SIGNAL(loadFinished(bool))); view.setHtml(html); @@ -3665,7 +3667,7 @@ void tst_QWebEnginePage::evaluateWillCauseRepaint() { WebView view; view.show(); - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QString html("<html><body>" " top" @@ -4301,7 +4303,7 @@ void tst_QWebEnginePage::mouseButtonTranslation() </div>\ </body></html>")); view.show(); - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(spy.count() == 1); QVERIFY(view.focusProxy() != nullptr); @@ -4325,7 +4327,7 @@ void tst_QWebEnginePage::mouseMovementProperties() ConsolePage page; view.setPage(&page); view.show(); - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool))); page.setHtml(QStringLiteral( diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index 1a8110bb6..e614c74d8 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -67,7 +67,7 @@ void tst_QWebEngineScript::domEditing() QVERIFY(spyFinished.wait()); QCOMPARE(evaluateJavaScriptSync(&page, "document.getElementById(\"banner\").innerText"), QVariant(QStringLiteral("Injected banner"))); // elementFromPoint only works for exposed elements - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QCOMPARE(evaluateJavaScriptSync(&page, "document.elementFromPoint(2, 2).id"), QVariant::fromValue(QStringLiteral("banner"))); } diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index f46590bdf..f46d9f455 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -37,6 +37,7 @@ #include <QCompleter> #include <QLineEdit> #include <QHBoxLayout> +#include <QMenu> #include <QQuickItem> #include <QQuickWidget> #include <QtWebEngineCore/qwebenginehttprequest.h> @@ -174,6 +175,9 @@ private Q_SLOTS: #ifndef QT_NO_CLIPBOARD void globalMouseSelection(); #endif + void noContextMenu(); + void contextMenu_data(); + void contextMenu(); }; // This will be called before the first test function is executed. @@ -273,14 +277,14 @@ void tst_QWebEngineView::reusePage() } view1->show(); - QTest::qWaitForWindowExposed(view1); + QVERIFY(QTest::qWaitForWindowExposed(view1)); delete view1; QVERIFY(page != 0); // deleting view must not have deleted the page, since it's not a child of view QWebEngineView *view2 = new QWebEngineView; view2->setPage(page.data()); view2->show(); // in Windowless mode, you should still be able to see the plugin here - QTest::qWaitForWindowExposed(view2); + QVERIFY(QTest::qWaitForWindowExposed(view2)); delete view2; delete page.data(); // must not crash @@ -335,7 +339,7 @@ void tst_QWebEngineView::microFocusCoordinates() { QWebEngineView webView; webView.show(); - QTest::qWaitForWindowExposed(&webView); + QVERIFY(QTest::qWaitForWindowExposed(&webView)); QSignalSpy scrollSpy(webView.page(), SIGNAL(scrollPositionChanged(QPointF))); QSignalSpy loadFinishedSpy(&webView, SIGNAL(loadFinished(bool))); @@ -369,7 +373,7 @@ void tst_QWebEngineView::focusInputTypes() QWebEngineView webView; webView.show(); - QTest::qWaitForWindowExposed(&webView); + QVERIFY(QTest::qWaitForWindowExposed(&webView)); QSignalSpy loadFinishedSpy(&webView, SIGNAL(loadFinished(bool))); webView.load(QUrl("qrc:///resources/input_types.html")); @@ -472,7 +476,7 @@ void tst_QWebEngineView::unhandledKeyEventPropagation() KeyEventRecordingWidget parentWidget; QWebEngineView webView(&parentWidget); parentWidget.show(); - QTest::qWaitForWindowExposed(&webView); + QVERIFY(QTest::qWaitForWindowExposed(&webView)); QSignalSpy loadFinishedSpy(&webView, SIGNAL(loadFinished(bool))); webView.load(QUrl("qrc:///resources/keyboardEvents.html")); @@ -530,7 +534,7 @@ void tst_QWebEngineView::horizontalScrollbarTest() view.setFixedSize(600, 600); view.show(); - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QSignalSpy loadSpy(view.page(), SIGNAL(loadFinished(bool))); view.setHtml(html); @@ -820,7 +824,7 @@ void tst_QWebEngineView::doNotSendMouseKeyboardEventsWhenDisabled() parentWidget.layout()->addWidget(&webView); webView.resize(640, 480); parentWidget.show(); - QTest::qWaitForWindowExposed(&webView); + QVERIFY(QTest::qWaitForWindowExposed(&webView)); QSignalSpy loadSpy(&webView, SIGNAL(loadFinished(bool))); webView.setHtml("<html><head><title>Title</title></head><body>Hello" @@ -866,7 +870,7 @@ void tst_QWebEngineView::stopSettingFocusWhenDisabled() webView.resize(640, 480); webView.show(); webView.setEnabled(viewEnabled); - QTest::qWaitForWindowExposed(&webView); + QVERIFY(QTest::qWaitForWindowExposed(&webView)); QSignalSpy loadSpy(&webView, SIGNAL(loadFinished(bool))); webView.setHtml("<html><head><title>Title</title></head><body>Hello" @@ -926,7 +930,7 @@ void tst_QWebEngineView::focusOnNavigation() containerWidget->setLayout(layout); containerWidget->show(); - QTest::qWaitForWindowExposed(containerWidget.data()); + QVERIFY(QTest::qWaitForWindowExposed(containerWidget.data())); // Load the content, invoke javascript focus on the view, and check which widget has focus. QSignalSpy loadSpy(webView, SIGNAL(loadFinished(bool))); @@ -992,7 +996,7 @@ void tst_QWebEngineView::focusInternalRenderWidgetHostViewQuickItem() containerWidget->setLayout(layout); containerWidget->show(); - QTest::qWaitForWindowExposed(containerWidget.data()); + QVERIFY(QTest::qWaitForWindowExposed(containerWidget.data())); // Load the content, and check that focus is not set. QSignalSpy loadSpy(webView, SIGNAL(loadFinished(bool))); @@ -1252,7 +1256,7 @@ void tst_QWebEngineView::keyboardFocusAfterPopup() containerWidget->setLayout(layout); containerWidget->show(); - QTest::qWaitForWindowExposed(containerWidget.data()); + QVERIFY(QTest::qWaitForWindowExposed(containerWidget.data())); // Trigger completer's popup and select the first suggestion QTest::keyClick(urlLine, Qt::Key_T); @@ -1277,7 +1281,7 @@ void tst_QWebEngineView::mouseClick() QWebEngineView view; view.show(); view.resize(200, 200); - QTest::qWaitForWindowExposed(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool))); QSignalSpy selectionChangedSpy(&view, SIGNAL(selectionChanged())); @@ -1490,7 +1494,7 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() QVERIFY(loadFinishedSpy.wait()); view.show(); - QTest::qWaitForWindowActive(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); auto inputFieldValue = [&view] () -> QString { return evaluateJavaScriptSync(view.page(), @@ -2354,5 +2358,64 @@ void tst_QWebEngineView::globalMouseSelection() } #endif +void tst_QWebEngineView::noContextMenu() +{ + QWidget wrapper; + wrapper.setContextMenuPolicy(Qt::CustomContextMenu); + + connect(&wrapper, &QWidget::customContextMenuRequested, [&wrapper](const QPoint &pt) { + QMenu* menu = new QMenu(&wrapper); + menu->addAction("Action1"); + menu->addAction("Action2"); + menu->popup(pt); + }); + + QWebEngineView view(&wrapper); + view.setContextMenuPolicy(Qt::NoContextMenu); + wrapper.show(); + + QVERIFY(view.findChildren<QMenu *>().isEmpty()); + QVERIFY(wrapper.findChildren<QMenu *>().isEmpty()); + QTest::mouseMove(wrapper.windowHandle(), QPoint(10,10)); + QTest::mouseClick(wrapper.windowHandle(), Qt::RightButton); + + QTRY_COMPARE(wrapper.findChildren<QMenu *>().count(), 1); + QVERIFY(view.findChildren<QMenu *>().isEmpty()); +} + +void tst_QWebEngineView::contextMenu_data() +{ + QTest::addColumn<int>("childrenCount"); + QTest::addColumn<Qt::ContextMenuPolicy>("contextMenuPolicy"); + QTest::newRow("defaultContextMenu") << 1 << Qt::DefaultContextMenu; + QTest::newRow("customContextMenu") << 1 << Qt::CustomContextMenu; + QTest::newRow("preventContextMenu") << 0 << Qt::PreventContextMenu; +} + +void tst_QWebEngineView::contextMenu() +{ + QFETCH(int, childrenCount); + QFETCH(Qt::ContextMenuPolicy, contextMenuPolicy); + + QWebEngineView view; + + if (contextMenuPolicy == Qt::CustomContextMenu) { + connect(&view, &QWebEngineView::customContextMenuRequested, [&view](const QPoint &pt) { + QMenu* menu = new QMenu(&view); + menu->addAction("Action1"); + menu->addAction("Action2"); + menu->popup(pt); + }); + } + + view.setContextMenuPolicy(contextMenuPolicy); + view.show(); + + QVERIFY(view.findChildren<QMenu *>().isEmpty()); + QTest::mouseMove(view.windowHandle(), QPoint(10,10)); + QTest::mouseClick(view.windowHandle(), Qt::RightButton); + QTRY_COMPARE(view.findChildren<QMenu *>().count(), childrenCount); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" |