diff options
Diffstat (limited to 'tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp')
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 89 |
1 files changed, 76 insertions, 13 deletions
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" |