diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2021-07-13 17:56:05 +0200 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2021-07-20 17:06:20 +0200 |
commit | 9c663f51c63f7661edcc604ce89171b3f037543d (patch) | |
tree | 402291f9e6e6cfccb814dd5a323c4b6de53e7a4a | |
parent | 4a81478a493f337b516af8995e0f41e79f15c33c (diff) |
Get rid of Quick's TestSupport API
- Moved TestInputContext and TestInputEvent APIs to tst_qmltests.
- Removed loadVisuallyCommitted and use Item.grabToImage to check if
page is rendered.
- Removed windowCloseRejected signal and use a hidden callback instead.
Pick-to: 6.2
Change-Id: Ica6e4c6017426e0171d738a6a59afa557c786698
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
36 files changed, 260 insertions, 753 deletions
diff --git a/src/core/api/qwebenginepage_p.h b/src/core/api/qwebenginepage_p.h index 811bec52e..d661fd442 100644 --- a/src/core/api/qwebenginepage_p.h +++ b/src/core/api/qwebenginepage_p.h @@ -134,7 +134,6 @@ public: QColor backgroundColor() const override; void loadStarted(QWebEngineLoadingInfo info) override; void loadCommitted() override { } - void didFirstVisuallyNonEmptyPaint() override { } void loadFinished(QWebEngineLoadingInfo info) override; void focusContainer() override; void unhandledKeyEvent(QKeyEvent *event) override; diff --git a/src/core/common/qt_messages.h b/src/core/common/qt_messages.h index ebf49e8c3..ef7ba7f8d 100644 --- a/src/core/common/qt_messages.h +++ b/src/core/common/qt_messages.h @@ -22,12 +22,6 @@ IPC_MESSAGE_ROUTED2(QtWebEngineMsg_RequestStorageAccessAsyncResponse, bool /* allowed */) //----------------------------------------------------------------------------- -// WebContents messages -// These are messages sent from the renderer back to the browser process. - -IPC_MESSAGE_ROUTED0(RenderViewObserverHostQt_DidFirstVisuallyNonEmptyLayout) - -//----------------------------------------------------------------------------- // Misc messages // These are messages sent from the renderer to the browser process. diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 7f7d7bcaa..9d5744cbf 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -41,7 +41,6 @@ #include "render_widget_host_view_qt.h" #include "browser_accessibility_manager_qt.h" -#include "common/qt_messages.h" #include "qtwebenginecoreglobal_p.h" #include "render_widget_host_view_qt_delegate.h" #include "render_widget_host_view_qt_delegate_client.h" @@ -820,11 +819,6 @@ void RenderWidgetHostViewQt::OnDidUpdateVisualPropertiesComplete(const cc::Rende synchronizeVisualProperties(metadata.local_surface_id); } -void RenderWidgetHostViewQt::OnDidFirstVisuallyNonEmptyPaint() -{ - m_adapterClient->didFirstVisuallyNonEmptyPaint(); -} - Compositor::Id RenderWidgetHostViewQt::compositorId() { return m_uiCompositor->frame_sink_id(); diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index 7f102547f..15ef4fa2a 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -188,9 +188,6 @@ public: void processMotionEvent(const ui::MotionEvent &motionEvent); void resetInputManagerState() { m_imState = 0; } - // Called from WebContentsDelegateQt. - void OnDidFirstVisuallyNonEmptyPaint(); - // Called from WebContentsAdapter. gfx::SizeF lastContentsSize() const { return m_lastContentsSize; } gfx::Vector2dF lastScrollOffset() const { return m_lastScrollOffset; } diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 42a5a3ab0..2e81f21e8 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -195,7 +195,6 @@ public: virtual QColor backgroundColor() const = 0; virtual void loadStarted(QWebEngineLoadingInfo info) = 0; virtual void loadCommitted() = 0; - virtual void didFirstVisuallyNonEmptyPaint() = 0; virtual void loadFinished(QWebEngineLoadingInfo info) = 0; virtual void focusContainer() = 0; virtual void unhandledKeyEvent(QKeyEvent *event) = 0; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 1fcef3274..5366e6a26 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -659,15 +659,6 @@ void WebContentsDelegateQt::OnVisibilityChanged(content::Visibility visibility) web_cache::WebCacheManager::GetInstance()->ObserveActivity(web_contents()->GetMainFrame()->GetProcess()->GetID()); } -void WebContentsDelegateQt::DidFirstVisuallyNonEmptyPaint() -{ - RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt*>(web_contents()->GetRenderWidgetHostView()); - if (!rwhv) - return; - - rwhv->OnDidFirstVisuallyNonEmptyPaint(); -} - void WebContentsDelegateQt::ActivateContents(content::WebContents* contents) { QWebEngineSettings *settings = m_viewClient->webEngineSettings(); diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 9ddd1d192..4704f78fb 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -166,7 +166,6 @@ public: void DidFinishLoad(content::RenderFrameHost *render_frame_host, const GURL &validated_url) override; void BeforeUnloadFired(bool proceed, const base::TimeTicks& proceed_time) override; void OnVisibilityChanged(content::Visibility visibility) override; - void DidFirstVisuallyNonEmptyPaint() override; void ActivateContents(content::WebContents* contents) override; void ResourceLoadComplete(content::RenderFrameHost* render_frame_host, const content::GlobalRequestID& request_id, diff --git a/src/webenginequick/CMakeLists.txt b/src/webenginequick/CMakeLists.txt index 7c7f9c942..5e56cf53f 100644 --- a/src/webenginequick/CMakeLists.txt +++ b/src/webenginequick/CMakeLists.txt @@ -3,10 +3,6 @@ find_package(Qt6 ${PROJECT_VERSION} CONFIG QUIET OPTIONAL_COMPONENTS PrintSuppor get_configure_mode(configureMode) - -if(QT_FEATURE_webenginequick_testsupport) - add_subdirectory(testsupport) -endif() add_subdirectory(ui) qt_internal_add_qml_module(WebEngineQuick @@ -68,8 +64,3 @@ qt_internal_extend_target(qtwebenginequickplugin make_install_only(WebEngineQuick) make_install_only(qtwebenginequickplugin) - -qt_internal_extend_target(WebEngineQuick CONDITION QT_FEATURE_webenginequick_testsupport - LIBRARIES - Qt::WebEngineTestSupportPrivate -) diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp index e26d5cf25..0f3adca92 100644 --- a/src/webenginequick/api/qquickwebengineview.cpp +++ b/src/webenginequick/api/qquickwebengineview.cpp @@ -99,11 +99,6 @@ #include <QtWebChannel/qqmlwebchannel.h> #endif -#if QT_CONFIG(webenginequick_testsupport) -#include <QtWebEngineTestSupport/private/qquickwebenginetestsupport_p.h> -#endif - - QT_BEGIN_NAMESPACE using namespace QtWebEngineCore; @@ -138,9 +133,6 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , m_history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this, [] (const QUrl &url) { return QQuickWebEngineFaviconProvider::faviconProviderUrl(url); }))) -#if QT_CONFIG(webenginequick_testsupport) - , m_testSupport(nullptr) -#endif , contextMenuExtraItems(nullptr) , loadProgress(0) , m_fullscreenMode(false) @@ -453,32 +445,6 @@ void QQuickWebEngineViewPrivate::loadCommitted() m_history->reset(); } -void QQuickWebEngineViewPrivate::didFirstVisuallyNonEmptyPaint() -{ -#if QT_CONFIG(webenginequick_testsupport) - if (m_loadVisuallyCommittedState == NotCommitted) { - m_loadVisuallyCommittedState = DidFirstVisuallyNonEmptyPaint; - } else if (m_loadVisuallyCommittedState == DidFirstCompositorFrameSwap) { - if (m_testSupport) - Q_EMIT m_testSupport->loadVisuallyCommitted(); - m_loadVisuallyCommittedState = NotCommitted; - } -#endif -} - -void QQuickWebEngineViewPrivate::didCompositorFrameSwap() -{ -#if QT_CONFIG(webenginequick_testsupport) - if (m_loadVisuallyCommittedState == NotCommitted) { - m_loadVisuallyCommittedState = DidFirstCompositorFrameSwap; - } else if (m_loadVisuallyCommittedState == DidFirstVisuallyNonEmptyPaint) { - if (m_testSupport) - Q_EMIT m_testSupport->loadVisuallyCommitted(); - m_loadVisuallyCommittedState = NotCommitted; - } -#endif -} - void QQuickWebEngineViewPrivate::loadFinished(QWebEngineLoadingInfo info) { Q_Q(QQuickWebEngineView); @@ -552,10 +518,10 @@ void QQuickWebEngineViewPrivate::close() void QQuickWebEngineViewPrivate::windowCloseRejected() { -#if QT_CONFIG(webenginequick_testsupport) - if (m_testSupport) - Q_EMIT m_testSupport->windowCloseRejected(); -#endif + Q_Q(QQuickWebEngineView); + + if (Q_UNLIKELY(q->metaObject()->indexOfMethod("windowCloseRejected()") != -1)) + QMetaObject::invokeMethod(q, "windowCloseRejected"); } void QQuickWebEngineViewPrivate::requestFullScreenMode(const QUrl &origin, bool fullscreen) @@ -1168,21 +1134,6 @@ void QQuickWebEngineViewPrivate::updateAdapter() } } -#if QT_CONFIG(webenginequick_testsupport) -QQuickWebEngineTestSupport *QQuickWebEngineView::testSupport() const -{ - Q_D(const QQuickWebEngineView); - return d->m_testSupport; -} - -void QQuickWebEngineView::setTestSupport(QQuickWebEngineTestSupport *testSupport) -{ - Q_D(QQuickWebEngineView); - d->m_testSupport = testSupport; - Q_EMIT testSupportChanged(); -} -#endif - bool QQuickWebEngineView::activeFocusOnPress() const { Q_D(const QQuickWebEngineView); diff --git a/src/webenginequick/api/qquickwebengineview_p.h b/src/webenginequick/api/qquickwebengineview_p.h index 2e3252777..ab891f4e2 100644 --- a/src/webenginequick/api/qquickwebengineview_p.h +++ b/src/webenginequick/api/qquickwebengineview_p.h @@ -74,7 +74,6 @@ class QQuickWebEngineJavaScriptDialogRequest; class QQuickWebEngineNewViewRequest; class QQuickWebEngineProfile; class QQuickWebEngineSettings; -class QQuickWebEngineTestSupport; class QQuickWebEngineTooltipRequest; class QQuickWebEngineViewPrivate; class QWebEngineCertificateError; @@ -118,9 +117,6 @@ class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem { Q_PROPERTY(QQuickWebEngineView *inspectedView READ inspectedView WRITE setInspectedView NOTIFY inspectedViewChanged REVISION(1,7) FINAL) Q_PROPERTY(QQuickWebEngineView *devToolsView READ devToolsView WRITE setDevToolsView NOTIFY devToolsViewChanged REVISION(1,7) FINAL) -#if QT_CONFIG(webenginequick_testsupport) - Q_PROPERTY(QQuickWebEngineTestSupport *testSupport READ testSupport WRITE setTestSupport NOTIFY testSupportChanged FINAL) -#endif Q_PROPERTY(LifecycleState lifecycleState READ lifecycleState WRITE setLifecycleState NOTIFY lifecycleStateChanged REVISION(1,10) FINAL) Q_PROPERTY(LifecycleState recommendedState READ recommendedState NOTIFY recommendedStateChanged REVISION(1,10) FINAL) @@ -456,11 +452,6 @@ public: qint64 renderProcessPid() const; -#if QT_CONFIG(webenginequick_testsupport) - QQuickWebEngineTestSupport *testSupport() const; - void setTestSupport(QQuickWebEngineTestSupport *testSupport); -#endif - bool activeFocusOnPress() const; void setInspectedView(QQuickWebEngineView *); @@ -542,10 +533,6 @@ Q_SIGNALS: Q_REVISION(1,11) void canGoBackChanged(); Q_REVISION(1,11) void canGoForwardChanged(); -#if QT_CONFIG(webenginequick_testsupport) - void testSupportChanged(); -#endif - protected: void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; void itemChange(ItemChange, const ItemChangeData &) override; diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h index 4f07ce909..da0d79d60 100644 --- a/src/webenginequick/api/qquickwebengineview_p_p.h +++ b/src/webenginequick/api/qquickwebengineview_p_p.h @@ -80,10 +80,6 @@ class QWebEngineContextMenuRequest; class QWebEngineFindTextResult; class QWebEngineHistory; -#if QT_CONFIG(webenginequick_testsupport) -class QQuickWebEngineTestSupport; -#endif - class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineViewPrivate : public QtWebEngineCore::WebContentsAdapterClient { public: @@ -113,7 +109,6 @@ public: QColor backgroundColor() const override; void loadStarted(QWebEngineLoadingInfo info) override; void loadCommitted() override; - void didFirstVisuallyNonEmptyPaint() override; void loadFinished(QWebEngineLoadingInfo info) override; void focusContainer() override; void unhandledKeyEvent(QKeyEvent *event) override; @@ -168,9 +163,6 @@ public: QtWebEngineCore::WebContentsAdapter *webContentsAdapter() override; void printRequested() override; void findTextFinished(const QWebEngineFindTextResult &result) override; - - void didCompositorFrameSwap(); - void updateAction(QQuickWebEngineView::WebAction) const; void adoptWebContents(QtWebEngineCore::WebContentsAdapter *webContents); void setProfile(QQuickWebEngineProfile *profile); @@ -186,9 +178,6 @@ public: QSharedPointer<QtWebEngineCore::WebContentsAdapter> adapter; QScopedPointer<QWebEngineHistory> m_history; QScopedPointer<QQuickWebEngineSettings> m_settings; -#if QT_CONFIG(webenginequick_testsupport) - QQuickWebEngineTestSupport *m_testSupport; -#endif QQmlComponent *contextMenuExtraItems; QUrl m_url; QString m_html; @@ -212,18 +201,11 @@ public: bool profileInitialized() const; private: - enum LoadVisuallyCommittedState { - NotCommitted, - DidFirstVisuallyNonEmptyPaint, - DidFirstCompositorFrameSwap - }; - QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; QColor m_backgroundColor; qreal m_zoomFactor; bool m_profileInitialized; QWebEngineContextMenuRequest *m_contextMenuRequest; - LoadVisuallyCommittedState m_loadVisuallyCommittedState = NotCommitted; QScopedPointer<QQuickWebEngineScriptCollection> m_scriptCollection; QQuickWebEngineFaviconProvider *m_faviconProvider = nullptr; }; diff --git a/src/webenginequick/configure.cmake b/src/webenginequick/configure.cmake index 19dded637..683a3f383 100644 --- a/src/webenginequick/configure.cmake +++ b/src/webenginequick/configure.cmake @@ -6,12 +6,7 @@ qt_feature("webenginequick-ui-delegates" PRIVATE SECTION "WebEngine" LABEL "UI Delegates" ) -qt_feature("webenginequick-testsupport" PRIVATE - LABEL "Test Support" - AUTODETECT QT_FEATURE_webengine_developer_build -) qt_configure_add_summary_section(NAME "Qt WebEngineQuick") qt_configure_add_summary_entry(ARGS "webenginequick-qml") qt_configure_add_summary_entry(ARGS "webenginequick-ui-delegates") -qt_configure_add_summary_entry(ARGS "webenginequick-testsupport") qt_configure_end_summary_section() diff --git a/src/webenginequick/configure.json b/src/webenginequick/configure.json index 6297195e9..ce9421575 100644 --- a/src/webenginequick/configure.json +++ b/src/webenginequick/configure.json @@ -19,11 +19,6 @@ "label": "UI Delegates", "section": "WebEngine", "output": [ "privateFeature" ] - }, - "webenginequick-testsupport": { - "label": "Test Support", - "autoDetect": "features.private_tests || call.isTestsInBuildParts", - "output": [ "privateFeature" ] } }, "summary": [ @@ -31,8 +26,7 @@ "section": "Qt WebEngineQuick", "entries": [ "webengine-quick", - "webenginequick-ui-delegates", - "webenginequick-testsupport" + "webenginequick-ui-delegates" ] } ] diff --git a/src/webenginequick/module.pro b/src/webenginequick/module.pro index 7b494bb5b..2c10aaa73 100644 --- a/src/webenginequick/module.pro +++ b/src/webenginequick/module.pro @@ -56,12 +56,6 @@ HEADERS = \ render_widget_host_view_qt_delegate_quickwindow.h \ ui_delegates_manager.h -qtConfig(webenginequick-testsupport) { - QT_PRIVATE += testlib - SOURCES += api/qquickwebenginetestsupport.cpp - HEADERS += api/qquickwebenginetestsupport_p.h -} - !build_pass { python = $$pythonPathForShell() chromium_attributions.commands = \ diff --git a/src/webenginequick/render_widget_host_view_qt_delegate_quick.cpp b/src/webenginequick/render_widget_host_view_qt_delegate_quick.cpp index c0a48ccd5..c4d80cb7e 100644 --- a/src/webenginequick/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webenginequick/render_widget_host_view_qt_delegate_quick.cpp @@ -349,13 +349,6 @@ QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, Q_UNREACHABLE(); } -#if QT_CONFIG(webenginequick_testsupport) - if (m_view) - QMetaObject::invokeMethod( - m_view, [view = m_view]() { view->d_ptr->didCompositorFrameSwap(); }, - Qt::QueuedConnection); -#endif - return node; } diff --git a/src/webenginequick/testsupport/CMakeLists.txt b/src/webenginequick/testsupport/CMakeLists.txt deleted file mode 100644 index 7058a6029..000000000 --- a/src/webenginequick/testsupport/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -qt_internal_add_qml_module(WebEngineTestSupport - ${configureMode} - URI "QtWebEngine.testsupport" - VERSION "${PROJECT_VERSION}" - CLASS_NAME QtWebEngineTestSupportPlugin - PLUGIN_TARGET qtwebenginetestsupportplugin - NO_PLUGIN_OPTIONAL - SOURCES - qquickwebenginetestsupport.cpp qquickwebenginetestsupport_p.h - DEFINES - QT_BUILD_WEBENGINEQUICK_TESTSUPPORT_LIB - LIBRARIES - Qt::GuiPrivate - Qt::Qml - Qt::TestPrivate - Qt::WebEngineCore -) -make_install_only(WebEngineTestSupport) -make_install_only(qtwebenginetestsupportplugin) diff --git a/src/webenginequick/testsupport/qquickwebenginetestsupport.cpp b/src/webenginequick/testsupport/qquickwebenginetestsupport.cpp deleted file mode 100644 index 15290e0e9..000000000 --- a/src/webenginequick/testsupport/qquickwebenginetestsupport.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** 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:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickwebenginetestsupport_p.h" - -#include <QtWebEngineCore/qwebengineloadinginfo.h> - -#include <QQuickItem> -#include <QQuickWindow> -#include <QtTest/qtest.h> -#include <QtCore/QTimer> - -QT_BEGIN_NAMESPACE - -namespace QTest { - int Q_TESTLIB_EXPORT defaultMouseDelay(); -} - -QQuickWebEngineTestInputContext::QQuickWebEngineTestInputContext() - : m_visible(false) -{ -} - -QQuickWebEngineTestInputContext::~QQuickWebEngineTestInputContext() -{ - release(); -} - -void QQuickWebEngineTestInputContext::create() -{ - QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = this; -} - -void QQuickWebEngineTestInputContext::release() -{ - QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = 0; -} - -void QQuickWebEngineTestInputContext::showInputPanel() -{ - m_visible = true; -} - -void QQuickWebEngineTestInputContext::hideInputPanel() -{ - m_visible = false; -} - -bool QQuickWebEngineTestInputContext::isInputPanelVisible() const -{ - return m_visible; -} - - -QQuickWebEngineTestEvent::QQuickWebEngineTestEvent() -{ -} - -bool QQuickWebEngineTestEvent::mouseMultiClick(QObject *item, qreal x, qreal y, int clickCount) -{ - QTEST_ASSERT(item); - - QWindow *view = eventWindow(item); - if (!view) - return false; - - for (int i = 0; i < clickCount; ++i) { - mouseEvent(QMouseEvent::MouseButtonPress, view, item, QPointF(x, y)); - mouseEvent(QMouseEvent::MouseButtonRelease, view, item, QPointF(x, y)); - } - QTest::lastMouseTimestamp += QTest::mouseDoubleClickInterval; - - return true; -} - -QWindow *QQuickWebEngineTestEvent::eventWindow(QObject *item) -{ - QWindow *window = qobject_cast<QWindow *>(item); - if (window) - return window; - - QQuickItem *quickItem = qobject_cast<QQuickItem *>(item); - if (quickItem) - return quickItem->window(); - - QQuickItem *testParentItem = qobject_cast<QQuickItem *>(parent()); - if (testParentItem) - return testParentItem->window(); - - return nullptr; -} - -void QQuickWebEngineTestEvent::mouseEvent(QEvent::Type type, QWindow *window, QObject *item, const QPointF &_pos) -{ - QTest::qWait(QTest::defaultMouseDelay()); - QTest::lastMouseTimestamp += QTest::defaultMouseDelay(); - - QPoint pos; - QQuickItem *sgitem = qobject_cast<QQuickItem *>(item); - if (sgitem) - pos = sgitem->mapToScene(_pos).toPoint(); - - QMouseEvent me(type, pos, window->mapFromGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); - me.setTimestamp(++QTest::lastMouseTimestamp); - - QSpontaneKeyEvent::setSpontaneous(&me); - if (!qApp->notify(window, &me)) - QTest::qWarn("Mouse click event not accepted by receiving window"); -} - - -QQuickWebEngineTestSupport::QQuickWebEngineTestSupport() - : m_testInputContext(new QQuickWebEngineTestInputContext) - , m_testEvent(new QQuickWebEngineTestEvent) -{ -} - -QQuickWebEngineTestInputContext *QQuickWebEngineTestSupport::testInputContext() const -{ - return m_testInputContext.data(); -} - -QQuickWebEngineTestEvent * QQuickWebEngineTestSupport::testEvent() const -{ - return m_testEvent.data(); -} - -QT_END_NAMESPACE - -#include "moc_qquickwebenginetestsupport_p.cpp" diff --git a/src/webenginequick/testsupport/qquickwebenginetestsupport_p.h b/src/webenginequick/testsupport/qquickwebenginetestsupport_p.h deleted file mode 100644 index c84bf6126..000000000 --- a/src/webenginequick/testsupport/qquickwebenginetestsupport_p.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** 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:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKWEBENGINETESTSUPPORT_P_H -#define QQUICKWEBENGINETESTSUPPORT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QT_STATIC -# if defined(QT_BUILD_WEBENGINEQUICK_TESTSUPPORT_LIB) -# define Q_WEBENGINEQUICK_TESTSUPPORT_EXPORT Q_DECL_EXPORT -# else -# define Q_WEBENGINEQUICK_TESTSUPPORT_EXPORT Q_DECL_IMPORT -# endif -#else -# define Q_WEBENGINEQUICK_TESTSUPPORT_EXPORT -#endif - -#include <QtGui/private/qinputmethod_p.h> -#include <QtQml/qqmlregistration.h> - -#include <QEvent> -#include <QObject> -#include <QUrl> - -QT_BEGIN_NAMESPACE - -class QWebEngineLoadingInfo; -class QWindow; - -class Q_WEBENGINEQUICK_TESTSUPPORT_EXPORT QQuickWebEngineTestInputContext : public QPlatformInputContext { - Q_OBJECT - QML_NAMED_ELEMENT(TestInputContext) - QML_ADDED_IN_VERSION(1, 0) - QML_EXTRA_VERSION(2, 0) - QML_UNCREATABLE("") - -public: - QQuickWebEngineTestInputContext(); - ~QQuickWebEngineTestInputContext(); - - Q_INVOKABLE void create(); - Q_INVOKABLE void release(); - - void showInputPanel() override; - void hideInputPanel() override; - bool isInputPanelVisible() const override; - -private: - bool m_visible; -}; - -class Q_WEBENGINEQUICK_TESTSUPPORT_EXPORT QQuickWebEngineTestEvent : public QObject { - Q_OBJECT - QML_NAMED_ELEMENT(WebEngineTestEvent) - QML_ADDED_IN_VERSION(1, 0) - QML_EXTRA_VERSION(2, 0) - QML_UNCREATABLE("") - -public: - QQuickWebEngineTestEvent(); - -public Q_SLOTS: - bool mouseMultiClick(QObject *item, qreal x, qreal y, int clickCount); - -private: - QWindow *eventWindow(QObject *item = nullptr); - void mouseEvent(QEvent::Type type, QWindow *window, QObject *item, const QPointF &_pos); -}; - -class Q_WEBENGINEQUICK_TESTSUPPORT_EXPORT QQuickWebEngineTestSupport : public QObject { - Q_OBJECT - Q_PROPERTY(QQuickWebEngineTestInputContext *testInputContext READ testInputContext CONSTANT FINAL) - Q_PROPERTY(QQuickWebEngineTestEvent *testEvent READ testEvent CONSTANT FINAL) - QML_NAMED_ELEMENT(WebEngineTestSupport) - QML_ADDED_IN_VERSION(1, 0) - QML_EXTRA_VERSION(2, 0) - -public: - QQuickWebEngineTestSupport(); - QQuickWebEngineTestInputContext *testInputContext() const; - QQuickWebEngineTestEvent *testEvent() const; - -Q_SIGNALS: - void windowCloseRejected(); - void loadVisuallyCommitted(); - -private: - QScopedPointer<QQuickWebEngineTestInputContext> m_testInputContext; - QScopedPointer<QQuickWebEngineTestEvent> m_testEvent; -}; - -QT_END_NAMESPACE - -#endif // QQUICKWEBENGINETESTSUPPORT_P_H diff --git a/src/webenginequick/webenginequick.pro b/src/webenginequick/webenginequick.pro index 17b3bd0fa..d7271a220 100644 --- a/src/webenginequick/webenginequick.pro +++ b/src/webenginequick/webenginequick.pro @@ -7,12 +7,6 @@ qml_plugin.depends = qml_module SUBDIRS += qml_module qml_plugin -qtConfig(webenginequick-testsupport) { - testsupport_plugin.file = testsupport/testsupport.pro - testsupport_plugin.depends = qml_module - SUBDIRS += testsupport_plugin -} - qtConfig(webenginequick-ui-delegates) { SUBDIRS += ui } diff --git a/sync.profile b/sync.profile index 77a499d4c..57ec30099 100644 --- a/sync.profile +++ b/sync.profile @@ -1,7 +1,6 @@ %modules = ( # path to module name map "QtWebEngineQuick" => "$basedir/src/webenginequick", "QtWebEngineWidgets" => "$basedir/src/webenginewidgets", - "QtWebEngineTestSupport" => "$basedir/src/webenginequick/testsupport", "QtWebEngineCore" => "$basedir/src/core/api", "QtPdf" => "$basedir/src/pdf", "QtPdfWidgets" => "$basedir/src/pdfwidgets", diff --git a/tests/auto/quick/CMakeLists.txt b/tests/auto/quick/CMakeLists.txt index 6349e9335..d44d67d38 100644 --- a/tests/auto/quick/CMakeLists.txt +++ b/tests/auto/quick/CMakeLists.txt @@ -6,6 +6,4 @@ add_subdirectory(uidelegates) add_subdirectory(inspectorserver) add_subdirectory(qmltests) add_subdirectory(qquickwebengineview) -if(QT_FEATURE_webenginequick_testsupport) - add_subdirectory(qquickwebengineviewgraphics) -endif() +add_subdirectory(qquickwebengineviewgraphics) diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index b133ea12e..62b8ae21c 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -101,8 +101,6 @@ static const QStringList hardcodedTypes = QStringList() << "QQmlListProperty<QQuickWebEngineClientCertificateOption>" << "const QQuickWebEngineClientCertificateOption*" << "QQmlWebChannel*" - // Ignore the testSupport types without making a fuss. - << "QQuickWebEngineTestSupport*" << "const QQuickWebEngineContextMenuData*" << "QWebEngineCookieStore*" << "Qt::LayoutDirection" @@ -749,10 +747,6 @@ static const QStringList expectedAPI = QStringList() << "QQuickWebEngineView.setActiveFocusOnPress(bool) --> void" << "QQuickWebEngineView.settings --> QQuickWebEngineSettings*" << "QQuickWebEngineView.stop() --> void" -#if QT_CONFIG(webenginequick_testsupport) - << "QQuickWebEngineView.testSupport --> QQuickWebEngineTestSupport*" - << "QQuickWebEngineView.testSupportChanged() --> void" -#endif << "QQuickWebEngineView.title --> QString" << "QQuickWebEngineView.titleChanged() --> void" << "QQuickWebEngineView.tooltipRequested(QQuickWebEngineTooltipRequest*) --> void" diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt index 2cbc52f5f..455c4c746 100644 --- a/tests/auto/quick/qmltests/CMakeLists.txt +++ b/tests/auto/quick/qmltests/CMakeLists.txt @@ -5,8 +5,10 @@ qt_internal_add_test(tst_qmltests SOURCES tst_qmltests.cpp LIBRARIES - Qt::WebEngineQuick + Qt::GuiPrivate Qt::QuickTest + Qt::TestPrivate + Qt::WebEngineQuick Test::HttpServer Test::Util ) @@ -26,13 +28,17 @@ set(testList tst_fullScreenRequest.qml tst_geopermission.qml tst_getUserMedia.qml + tst_inputMethod.qml + tst_javaScriptDialogs.qml tst_keyboardEvents.qml tst_keyboardModifierMapping.qml + tst_linkHovered.qml tst_loadFail.qml tst_loadHtml.qml tst_loadProgress.qml tst_loadRecursionCrash.qml tst_loadUrl.qml + tst_mouseClick.qml tst_mouseMove.qml tst_navigationHistory.qml tst_navigationRequested.qml @@ -56,16 +62,6 @@ if(QT_FEATURE_ssl) list(APPEND testList tst_certificateError.qml) endif() -if(QT_FEATURE_webenginequick_testsupport) - list(APPEND testList - tst_inputMethod.qml - tst_javaScriptDialogs.qml - tst_linkHovered.qml - tst_mouseClick.qml - tst_viewSoure.qml - ) -endif() - set(content "") foreach(test ${testList}) set(contents "${contents}${CMAKE_CURRENT_LIST_DIR}/data/${test}\n") diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml index f82589f7d..aa9d67d99 100644 --- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml +++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml @@ -26,9 +26,9 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.1 -import QtWebEngine 1.7 +import QtQuick +import QtTest +import QtWebEngine WebEngineView { property var loadStatus: null @@ -119,5 +119,38 @@ WebEngineView { testCase.tryVerify(function() { return text !== undefined }) return text } + + function getItemPixel(item) { + var grabImage = Qt.createQmlObject(" + import QtQuick\n + Image { }", testCase) + var itemCanvas = Qt.createQmlObject(" + import QtQuick\n + Canvas { }", testCase) + + // Mark QML images with objectName: "image" to be able to check if the image is loaded. + if (item.objectName === "image") { + testCase.tryVerify(function() { return item.status === Image.Ready }); + } + + item.grabToImage(function(result) { + grabImage.source = result.url + }); + testCase.tryVerify(function() { return grabImage.status === Image.Ready }); + + itemCanvas.width = item.width; + itemCanvas.height = item.height; + var ctx = itemCanvas.getContext("2d"); + ctx.drawImage(grabImage, 0, 0, grabImage.width, grabImage.height); + var imageData = ctx.getImageData(Math.round(itemCanvas.width/2), + Math.round(itemCanvas.height/2), + itemCanvas.width, + itemCanvas.height); + + grabImage.destroy(); + itemCanvas.destroy(); + + return imageData.data; + } } diff --git a/tests/auto/quick/qmltests/data/test2.html b/tests/auto/quick/qmltests/data/test2.html index 7a02bf1f2..06b1c40cb 100644 --- a/tests/auto/quick/qmltests/data/test2.html +++ b/tests/auto/quick/qmltests/data/test2.html @@ -1,6 +1,6 @@ <html> <head><title>Test page with huge link area</title></head> <body> -<a id="link" title="A title" href="test1.html"><img width=200 height=200></a> +<a id="link" title="A title" href="test1.html"><div style="width:200px; height:200px; background-color:red"></div></a> </body> </html> diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml index 84b3db5e5..79c835c70 100644 --- a/tests/auto/quick/qmltests/data/tst_favicon.qml +++ b/tests/auto/quick/qmltests/data/tst_favicon.qml @@ -52,35 +52,6 @@ TestWebEngineView { return url.toString().substring(16) } - function getFaviconPixel(faviconImage) { - var grabImage = Qt.createQmlObject(" - import QtQuick\n - Image { }", testCase) - var faviconCanvas = Qt.createQmlObject(" - import QtQuick\n - Canvas { }", testCase) - - testCase.tryVerify(function() { return faviconImage.status == Image.Ready }); - faviconImage.grabToImage(function(result) { - grabImage.source = result.url - }); - testCase.tryVerify(function() { return grabImage.status == Image.Ready }); - - faviconCanvas.width = faviconImage.width; - faviconCanvas.height = faviconImage.height; - var ctx = faviconCanvas.getContext("2d"); - ctx.drawImage(grabImage, 0, 0, grabImage.width, grabImage.height); - var imageData = ctx.getImageData(Math.round(faviconCanvas.width/2), - Math.round(faviconCanvas.height/2), - faviconCanvas.width, - faviconCanvas.height); - - grabImage.destroy(); - faviconCanvas.destroy(); - - return imageData.data; - } - SignalSpy { id: iconChangedSpy target: webEngineView @@ -418,7 +389,7 @@ TestWebEngineView { var faviconImage = Qt.createQmlObject(" import QtQuick\n - Image { width: 16; height: 16; sourceSize: Qt.size(width, height); }", testCase) + Image { width: 16; height: 16; sourceSize: Qt.size(width, height); objectName: 'image' }", testCase) faviconImage.source = Qt.binding(function() { return webEngineView.icon; }); var colors = [ @@ -437,7 +408,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); tryCompare(iconChangedSpy, "count", 1); - pixel = getFaviconPixel(faviconImage); + pixel = getItemPixel(faviconImage); compare(pixel[0], 0); compare(pixel[1], 0); compare(pixel[2], 0); @@ -448,7 +419,7 @@ TestWebEngineView { tryCompare(faviconImage, "source", "image://favicon/data:image/png;base64," + colors[i]["url"]); compare(iconChangedSpy.count, 1); - pixel = getFaviconPixel(faviconImage); + pixel = getItemPixel(faviconImage); compare(pixel[0], colors[i]["r"]); compare(pixel[1], colors[i]["g"]); compare(pixel[2], colors[i]["b"]); diff --git a/tests/auto/quick/qmltests/data/tst_inputMethod.qml b/tests/auto/quick/qmltests/data/tst_inputMethod.qml index 00f85cb71..16b7a06d5 100644 --- a/tests/auto/quick/qmltests/data/tst_inputMethod.qml +++ b/tests/auto/quick/qmltests/data/tst_inputMethod.qml @@ -26,10 +26,10 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.4 -import QtWebEngine.testsupport 1.0 +import QtQuick +import QtTest +import QtWebEngine +import Test.util import "../../qmltests/data" 1.0 TestWebEngineView { @@ -37,7 +37,7 @@ TestWebEngineView { width: 200 height: 400 - testSupport: WebEngineTestSupport { } + TestInputContext { id: testInputContext } TestCase { id: testCase @@ -45,11 +45,11 @@ TestWebEngineView { when: windowShown function init() { - testSupport.testInputContext.create(); + testInputContext.create(); } function cleanup() { - testSupport.testInputContext.release(); + testInputContext.release(); } function test_softwareInputPanel() { diff --git a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml index a521ea0d6..91b57c101 100644 --- a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml +++ b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml @@ -26,29 +26,21 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.2 -import QtWebEngine.testsupport 1.0 -import "../../qmltests/data" 1.0 -import "../mock-delegates/TestParams" 1.0 +import QtQuick +import QtTest +import QtWebEngine +import "../../qmltests/data" +import "../mock-delegates/TestParams" TestWebEngineView { id: webEngineView anchors.fill: parent - testSupport: WebEngineTestSupport { - property bool windowCloseRejectedSignalEmitted: false + property bool windowCloseRejectedCalled: false - function waitForWindowCloseRejected() { - return _waitFor(function () { - return testSupport.windowCloseRejectedSignalEmitted; - }); - } - - onWindowCloseRejected: { - windowCloseRejectedSignalEmitted = true; - } + // Called by QQuickWebEngineViewPrivate::windowCloseRejected() + function windowCloseRejected() { + windowCloseRejectedCalled = true; } TestCase { @@ -124,12 +116,12 @@ TestWebEngineView { function test_rejectClose() { webEngineView.url = Qt.resolvedUrl("confirmclose.html"); verify(webEngineView.waitForLoadSucceeded()); - webEngineView.testSupport.windowCloseRejectedSignalEmitted = false; + webEngineView.windowCloseRejectedCalled = false; JSDialogParams.shouldAcceptDialog = false; simulateUserGesture() webEngineView.triggerWebAction(WebEngineView.RequestClose); - verify(webEngineView.testSupport.waitForWindowCloseRejected()); + tryVerify(function() { return webEngineView.windowCloseRejectedCalled; }); // Navigate away from page with onbeforeunload handler, // otherwise it would trigger an extra dialog request when diff --git a/tests/auto/quick/qmltests/data/tst_linkHovered.qml b/tests/auto/quick/qmltests/data/tst_linkHovered.qml index faf943c55..d21d74434 100644 --- a/tests/auto/quick/qmltests/data/tst_linkHovered.qml +++ b/tests/auto/quick/qmltests/data/tst_linkHovered.qml @@ -26,10 +26,9 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.2 -import QtWebEngine.testsupport 1.0 +import QtQuick +import QtTest +import QtWebEngine import "../../qmltests/data" 1.0 TestWebEngineView { @@ -40,25 +39,29 @@ TestWebEngineView { property string lastUrl - testSupport: WebEngineTestSupport { } - - SignalSpy { - id: loadVisuallyCommittedSpy - target: webEngineView.testSupport - signalName: "loadVisuallyCommitted" - } - SignalSpy { id: linkHoveredSpy target: webEngineView signalName: "linkHovered" } - onLinkHovered: { + onLinkHovered: function(hoveredUrl) { webEngineView.lastUrl = hoveredUrl } + function isViewRendered() { + var pixel = getItemPixel(webEngineView); + + // The center pixel is expected to be red. + if (pixel[0] !== 255) return false; + if (pixel[1] !== 0) return false; + if (pixel[2] !== 0) return false; + + return true; + } + TestCase { + id: testCase name: "DesktopWebEngineViewLinkHovered" // Delayed windowShown to workaround problems with Qt5 in debug mode. @@ -72,7 +75,6 @@ TestWebEngineView { function init() { webEngineView.lastUrl = ""; - loadVisuallyCommittedSpy.clear(); linkHoveredSpy.clear(); } @@ -88,7 +90,7 @@ TestWebEngineView { compare(webEngineView.lastUrl, "") // Wait for the page to be rendered before trying to test based on input events - loadVisuallyCommittedSpy.wait(); + tryVerify(isViewRendered); mouseMove(webEngineView, 100, 100) linkHoveredSpy.wait(12000); @@ -111,7 +113,7 @@ TestWebEngineView { compare(webEngineView.lastUrl, "") // Wait for the page to be rendered before trying to test based on input events - loadVisuallyCommittedSpy.wait(); + tryVerify(isViewRendered); for (var i = 0; i < 100; i += 10) mouseMove(webEngineView, 100, 100 + i) diff --git a/tests/auto/quick/qmltests/data/tst_mouseClick.qml b/tests/auto/quick/qmltests/data/tst_mouseClick.qml index 6c314d44c..647c84573 100644 --- a/tests/auto/quick/qmltests/data/tst_mouseClick.qml +++ b/tests/auto/quick/qmltests/data/tst_mouseClick.qml @@ -26,10 +26,10 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.4 -import QtWebEngine.testsupport 1.0 +import QtQuick +import QtTest +import QtWebEngine +import Test.util import "../../qmltests/data" 1.0 TestWebEngineView { @@ -37,8 +37,10 @@ TestWebEngineView { width: 200 height: 200 - testSupport: WebEngineTestSupport { - function mouseMultiClick(item, x, y, clickCount) { + TestInputEvent { + id: testInputEvent + + function __mouseMultiClick(item, x, y, clickCount) { if (!item) qtest_fail("No item given to mouseMultiClick", 1); @@ -46,20 +48,20 @@ TestWebEngineView { x = item.width / 2; if (y === undefined) y = item.height / 2; - if (!testEvent.mouseMultiClick(item, x, y, clickCount)) + if (!mouseMultiClick(item, x, y, clickCount)) qtest_fail("window not shown", 2); } function mouseDoubleClick(item, x, y) { - mouseMultiClick(item, x, y, 2); + __mouseMultiClick(item, x, y, 2); } function mouseTripleClick(item, x, y) { - mouseMultiClick(item, x, y, 3); + __mouseMultiClick(item, x, y, 3); } function mouseQuadraClick(item, x, y) { - mouseMultiClick(item, x, y, 4); + __mouseMultiClick(item, x, y, 4); } } @@ -91,7 +93,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); var center = getElementCenter("input"); - webEngineView.testSupport.mouseDoubleClick(webEngineView, center.x, center.y); + testInputEvent.mouseDoubleClick(webEngineView, center.x, center.y); verifyElementHasFocus("input"); tryVerify(function() { return getTextSelection() == "Company" }); @@ -107,7 +109,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); var center = getElementCenter("input"); - webEngineView.testSupport.mouseTripleClick(webEngineView, center.x, center.y); + testInputEvent.mouseTripleClick(webEngineView, center.x, center.y); verifyElementHasFocus("input"); tryVerify(function() { return getTextSelection() == "The Qt Company" }); @@ -123,7 +125,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); var center = getElementCenter("input"); - webEngineView.testSupport.mouseQuadraClick(webEngineView, center.x, center.y); + testInputEvent.mouseQuadraClick(webEngineView, center.x, center.y); verifyElementHasFocus("input"); tryVerify(function() { return getTextSelection() == "" }); } diff --git a/tests/auto/quick/qmltests/data/tst_viewSource.qml b/tests/auto/quick/qmltests/data/tst_viewSource.qml index 0b5f6a7ab..8097758fd 100644 --- a/tests/auto/quick/qmltests/data/tst_viewSource.qml +++ b/tests/auto/quick/qmltests/data/tst_viewSource.qml @@ -26,9 +26,9 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtTest 1.0 -import QtWebEngine 1.4 +import QtQuick +import QtTest +import QtWebEngine TestWebEngineView { id: webEngineView @@ -38,6 +38,12 @@ TestWebEngineView { property var viewRequest: null SignalSpy { + id: loadSpy + target: webEngineView + signalName: 'loadingChanged' + } + + SignalSpy { id: newViewRequestedSpy target: webEngineView signalName: "newViewRequested" @@ -68,6 +74,7 @@ TestWebEngineView { tryCompare(webEngineView, "loadStatus", WebEngineView.LoadSucceededStatus); webEngineView.loadStatus = null; + loadSpy.clear(); newViewRequestedSpy.clear(); titleChangedSpy.clear(); viewRequest = null; @@ -121,6 +128,40 @@ TestWebEngineView { tryCompare(webEngineView, "url", "view-source:" + url.replace("user:passwd@", "")); tryCompare(webEngineView, "title", "view-source:" + url.replace("http://user:passwd@", "")); } + + function test_viewSourceURL_data() { + var testLocalUrl = "view-source:" + Qt.resolvedUrl("test1.html"); + var testLocalUrlWithoutScheme = "view-source:" + Qt.resolvedUrl("test1.html").toString().substring(7); + + return [ + { tag: "view-source:", userInputUrl: "view-source:", loadSucceed: true, url: "view-source:", title: "view-source:" }, + { tag: "view-source:about:blank", userInputUrl: "view-source:about:blank", loadSucceed: true, url: "view-source:about:blank", title: "view-source:about:blank" }, + { tag: testLocalUrl, userInputUrl: testLocalUrl, loadSucceed: true, url: testLocalUrl, title: "test1.html" }, + { tag: testLocalUrlWithoutScheme, userInputUrl: testLocalUrlWithoutScheme, loadSucceed: true, url: testLocalUrl, title: "test1.html" }, + { tag: "view-source:http://non.existent", userInputUrl: "view-source:http://non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" }, + { tag: "view-source:non.existent", userInputUrl: "view-source:non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" }, + ]; + } + + function test_viewSourceURL(row) { + WebEngine.settings.errorPageEnabled = true + webEngineView.url = row.userInputUrl; + + tryCompare(loadSpy, 'count', 2); + let load = loadSpy.signalArguments[1][0] + let expectedStatus = row.loadSucceed ? WebEngineView.LoadSucceededStatus : WebEngineView.LoadFailedStatus + compare(load.status, expectedStatus); + compare(load.isErrorPage, !row.loadSucceed); + tryVerify(function() { return titleChangedSpy.count == 1; }); + + compare(webEngineView.url, row.url); + tryCompare(webEngineView, "title", row.title); + if (row.loadSucceed) { + verify(!webEngineView.action(WebEngineView.ViewSource).enabled); + } else { + verify(webEngineView.action(WebEngineView.ViewSource).enabled); + } + } } } diff --git a/tests/auto/quick/qmltests/data/tst_viewSoure.qml b/tests/auto/quick/qmltests/data/tst_viewSoure.qml deleted file mode 100644 index 8d7c052aa..000000000 --- a/tests/auto/quick/qmltests/data/tst_viewSoure.qml +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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 -import QtWebEngine.testsupport 1.0 -import "../../qmltests/data" 1.0 - -TestWebEngineView { - id: webEngineView - width: 200 - height: 400 - - property var viewRequest: null - - SignalSpy { - id: loadSpy - target: webEngineView - signalName: 'loadingChanged' - } - - SignalSpy { - id: newViewRequestedSpy - target: webEngineView - signalName: "newViewRequested" - } - - SignalSpy { - id: titleChangedSpy - target: webEngineView - signalName: "titleChanged" - } - - onNewViewRequested: { - viewRequest = { - "destination": request.destination, - "userInitiated": request.userInitiated - }; - - request.openIn(webEngineView); - } - - TestCase { - id: testCase - name: "WebEngineViewSource" - - function init() { - webEngineView.loadStatus = null; - webEngineView.url = Qt.resolvedUrl("test1.html"); - tryCompare(webEngineView, "loadStatus", WebEngineView.LoadSucceededStatus); - webEngineView.loadStatus = null; - - loadSpy.clear() - newViewRequestedSpy.clear(); - titleChangedSpy.clear(); - viewRequest = null; - } - - function test_viewSourceURL_data() { - var testLocalUrl = "view-source:" + Qt.resolvedUrl("test1.html"); - var testLocalUrlWithoutScheme = "view-source:" + Qt.resolvedUrl("test1.html").toString().substring(7); - - return [ - { tag: "view-source:", userInputUrl: "view-source:", loadSucceed: true, url: "view-source:", title: "view-source:" }, - { tag: "view-source:about:blank", userInputUrl: "view-source:about:blank", loadSucceed: true, url: "view-source:about:blank", title: "view-source:about:blank" }, - { tag: testLocalUrl, userInputUrl: testLocalUrl, loadSucceed: true, url: testLocalUrl, title: "test1.html" }, - { tag: testLocalUrlWithoutScheme, userInputUrl: testLocalUrlWithoutScheme, loadSucceed: true, url: testLocalUrl, title: "test1.html" }, - { tag: "view-source:http://non.existent", userInputUrl: "view-source:http://non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" }, - { tag: "view-source:non.existent", userInputUrl: "view-source:non.existent", loadSucceed: false, url: "http://non.existent/", title: "non.existent" }, - ]; - } - - function test_viewSourceURL(row) { - WebEngine.settings.errorPageEnabled = true - webEngineView.url = row.userInputUrl; - - tryCompare(loadSpy, 'count', 2); - let load = loadSpy.signalArguments[1][0] - let expectedStatus = row.loadSucceed ? WebEngineView.LoadSucceededStatus : WebEngineView.LoadFailedStatus - compare(load.status, expectedStatus); - compare(load.isErrorPage, !row.loadSucceed); - tryVerify(function() { return titleChangedSpy.count == 1; }); - - compare(webEngineView.url, row.url); - tryCompare(webEngineView, "title", row.title); - if (row.loadSucceed) { - verify(!webEngineView.action(WebEngineView.ViewSource).enabled); - } else { - verify(webEngineView.action(WebEngineView.ViewSource).enabled); - } - } - } -} - diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index bc034790e..e5d4b26a1 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -14,17 +14,24 @@ QML_TESTS = \ $$PWD/data/tst_contextMenu.qml \ $$PWD/data/tst_desktopBehaviorLoadHtml.qml \ $$PWD/data/tst_download.qml \ + $$PWD/data/tst_favicon.qml \ + $$PWD/data/tst_faviconDatabase.qml \ $$PWD/data/tst_findText.qml \ $$PWD/data/tst_focusOnNavigation.qml \ $$PWD/data/tst_fullScreenRequest.qml \ $$PWD/data/tst_geopermission.qml \ $$PWD/data/tst_getUserMedia.qml \ + $$PWD/data/tst_inputMethod.qml \ + $$PWD/data/tst_javaScriptDialogs.qml $$PWD/data/tst_keyboardEvents.qml \ $$PWD/data/tst_keyboardModifierMapping.qml \ + $$PWD/data/tst_linkHovered.qml \ + $$PWD/data/tst_loadFail.qml \ $$PWD/data/tst_loadHtml.qml \ $$PWD/data/tst_loadProgress.qml \ $$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 \ @@ -51,35 +58,6 @@ qtConfig(ssl) { include(../../shared/http.pri) } -qtConfig(webenginequick-testsupport) { - QML_TESTS += \ - $$PWD/data/tst_favicon.qml \ - $$PWD/data/tst_faviconDownload.qml \ - $$PWD/data/tst_inputMethod.qml \ - $$PWD/data/tst_javaScriptDialogs.qml \ - $$PWD/data/tst_linkHovered.qml \ - $$PWD/data/tst_loadFail.qml \ - $$PWD/data/tst_mouseClick.qml \ - $$PWD/data/tst_viewSoure.qml -} else { - PLUGIN_EXTENSION = .so - PLUGIN_PREFIX = lib - macos: PLUGIN_PREFIX = .dylib - win32 { - PLUGIN_EXTENSION = .dll - PLUGIN_PREFIX = - } - - TESTSUPPORT_MODULE = $$shell_path($$[QT_INSTALL_QML]/QtWebEngine/testsupport/$${PLUGIN_PREFIX}qtwebenginetestsupportplugin$${PLUGIN_EXTENSION}) - BUILD_DIR = $$shell_path($$clean_path($$OUT_PWD/../../../..)) - SRC_DIR = $$shell_path($$clean_path($$PWD/../../../..)) - - warning("QML Test Support API is disabled. This means some QML tests that use Test Support API will fail.") - warning("Use the following command to build Test Support module and rebuild WebEngineView API:") - warning("cd $$BUILD_DIR && qmake -r $$shell_path($$SRC_DIR/qtwebengine.pro -- --feature-testsupport=yes) && make -C $$shell_path($$BUILD_DIR/src/webengine) clean && make") - warning("After performing the command above make sure QML module \"QtWebEngine.testsupport\" is deployed at $$TESTSUPPORT_MODULE") -} - qtHaveModule(quickcontrols) { QML_TESTS += \ $$PWD/data/tst_filePicker.qml diff --git a/tests/auto/quick/qmltests/tst_qmltests.cpp b/tests/auto/quick/qmltests/tst_qmltests.cpp index a60994f85..78c167106 100644 --- a/tests/auto/quick/qmltests/tst_qmltests.cpp +++ b/tests/auto/quick/qmltests/tst_qmltests.cpp @@ -32,11 +32,16 @@ #include <httpsserver.h> #endif -#include <QtCore/QScopedPointer> -#include <QTemporaryDir> +#include <QtCore/qscopedpointer.h> +#include <QtCore/qtemporarydir.h> +#include <QtGui/private/qinputmethod_p.h> +#include <QtQml/qqmlengine.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/qquickwindow.h> #include <QtQuickTest/quicktest.h> -#include <QtWebEngineQuick/QQuickWebEngineProfile> -#include <QtQml/QQmlEngine> +#include <QtTest/qtest.h> +#include <QtWebEngineQuick/qquickwebengineprofile.h> +#include <QtWebEngineQuick/qtwebenginequickglobal.h> #include <qt_webengine_quicktest.h> #if defined(Q_OS_LINUX) && defined(QT_DEBUG) @@ -142,6 +147,99 @@ private: QTemporaryDir tempDir; }; +class TestInputContext : public QPlatformInputContext { + Q_OBJECT + +public: + TestInputContext() = default; + ~TestInputContext() { release(); } + + Q_INVOKABLE void create() + { + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = this; + } + + Q_INVOKABLE void release() + { + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = nullptr; + } + + void showInputPanel() override { m_visible = true; } + void hideInputPanel() override { m_visible = false; } + bool isInputPanelVisible() const override { return m_visible; } + +private: + bool m_visible = false; +}; + +QT_BEGIN_NAMESPACE +namespace QTest { + int Q_TESTLIB_EXPORT defaultMouseDelay(); +} +QT_END_NAMESPACE + +class TestInputEvent : public QObject { + Q_OBJECT + +public: + TestInputEvent() = default; + + Q_INVOKABLE bool mouseMultiClick(QObject *item, qreal x, qreal y, int clickCount) + { + QTEST_ASSERT(item); + + QWindow *view = eventWindow(item); + if (!view) + return false; + + for (int i = 0; i < clickCount; ++i) { + mouseEvent(QMouseEvent::MouseButtonPress, view, item, QPointF(x, y)); + mouseEvent(QMouseEvent::MouseButtonRelease, view, item, QPointF(x, y)); + } + QTest::lastMouseTimestamp += QTest::mouseDoubleClickInterval; + + return true; + } + +private: + QWindow *eventWindow(QObject *item = nullptr) + { + QWindow *window = qobject_cast<QWindow *>(item); + if (window) + return window; + + QQuickItem *quickItem = qobject_cast<QQuickItem *>(item); + if (quickItem) + return quickItem->window(); + + QQuickItem *testParentItem = qobject_cast<QQuickItem *>(parent()); + if (testParentItem) + return testParentItem->window(); + + return nullptr; + } + + void mouseEvent(QEvent::Type type, QWindow *window, QObject *item, const QPointF &_pos) + { + QTest::qWait(QTest::defaultMouseDelay()); + QTest::lastMouseTimestamp += QTest::defaultMouseDelay(); + + QPoint pos; + QQuickItem *sgitem = qobject_cast<QQuickItem *>(item); + if (sgitem) + pos = sgitem->mapToScene(_pos).toPoint(); + + QMouseEvent me(type, pos, window->mapFromGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); + me.setTimestamp(++QTest::lastMouseTimestamp); + + QSpontaneKeyEvent::setSpontaneous(&me); + if (!qApp->notify(window, &me)) + QTest::qWarn("Mouse click event not accepted by receiving window"); + } +}; + int main(int argc, char **argv) { #if defined(Q_OS_LINUX) && defined(QT_DEBUG) @@ -171,6 +269,8 @@ int main(int argc, char **argv) QtWebEngineQuick::initialize(); QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); qmlRegisterType<TempDir>("Test.util", 1, 0, "TempDir"); + qmlRegisterType<TestInputContext>("Test.util", 1, 0, "TestInputContext"); + qmlRegisterType<TestInputEvent>("Test.util", 1, 0, "TestInputEvent"); QTEST_SET_MAIN_SOURCE_PATH qmlRegisterSingletonType<HttpServer>("Test.Shared", 1, 0, "HttpServer", [&] (QQmlEngine *, QJSEngine *) { diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index 1b518c27f..13e4d78cc 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -9,11 +9,8 @@ SUBDIRS += \ qmltests \ publicapi \ qquickwebenginedefaultsurfaceformat \ + qquickwebengineviewgraphics \ qquickwebengineview \ qtbug-70248 -qtConfig(webenginequick-testsupport) { - SUBDIRS += qquickwebengineviewgraphics -} - boot2qt: SUBDIRS -= inspectorserver qquickwebengineview qmltests diff --git a/tests/auto/util/qt_webengine_quicktest.h b/tests/auto/util/qt_webengine_quicktest.h index 3fba3b905..0428783bf 100644 --- a/tests/auto/util/qt_webengine_quicktest.h +++ b/tests/auto/util/qt_webengine_quicktest.h @@ -37,9 +37,6 @@ #include <QtGui/QGuiApplication> #endif -#include "qopenglcontext.h" -#include <QtWebEngineQuick/qtwebenginequickglobal.h> - QT_BEGIN_NAMESPACE #ifdef QT_WIDGETS_LIB |