From 97dcbd4019456b9a1c567faddb0521b7505d80fc Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 11 Feb 2021 10:03:24 +0100 Subject: Add tests to the cmake build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use QT_TESTCASE_SOURCEDIR instead of TESTS_SOURCE_DIR. Introduce Test::HttpServer and Test::Util targets. Query shared data location from server. Clean up "shared" resources. Note QT_TESTCASE_SOURCEDIR must be turned into the canonical form since the user can call on windows: "cmake \path\to\foo" instead of "cmake c:\path\to\foo" which will break all file:// urls. Note this patch breaks qmake builds. Task-number: QTBUG-91760 Change-Id: Ibc1f904ac9acd375d1ff70ff80f0c533497e3f20 Reviewed-by: Michael BrĂ¼ning --- tests/CMakeLists.txt | 24 ++ tests/auto/CMakeLists.txt | 17 ++ tests/auto/core/CMakeLists.txt | 5 + .../CMakeLists.txt | 21 ++ .../auto/core/qwebenginecookiestore/CMakeLists.txt | 23 ++ .../tst_qwebenginecookiestore.cpp | 2 +- .../qwebengineurlrequestinterceptor/CMakeLists.txt | 41 ++++ .../tst_qwebengineurlrequestinterceptor.cpp | 62 ++++-- tests/auto/httpserver/CMakeLists.txt | 7 + tests/auto/httpserver/data/hedgehog.html | 9 + tests/auto/httpserver/data/hedgehog.png | Bin 0 -> 11273 bytes .../data/loadprogress/downloadable.tar.gz | Bin 0 -> 131 bytes tests/auto/httpserver/data/loadprogress/main.html | 30 +++ tests/auto/httpserver/data/loadprogress/page1.html | 8 + tests/auto/httpserver/data/loadprogress/page2.html | 15 ++ tests/auto/httpserver/data/loadprogress/page3.html | 20 ++ tests/auto/httpserver/data/loadprogress/page4.html | 8 + tests/auto/httpserver/data/loadprogress/page5.html | 20 ++ tests/auto/httpserver/data/loadprogress/page6.html | 13 ++ tests/auto/httpserver/data/loadprogress/page7.html | 13 ++ tests/auto/httpserver/data/loadprogress/page8.html | 20 ++ tests/auto/httpserver/data/notification.html | 70 ++++++ tests/auto/httpserver/httpreqrep.cpp | 143 ++++++++++++ tests/auto/httpserver/httpreqrep.h | 109 ++++++++++ tests/auto/httpserver/httpserver.cmake | 38 ++++ tests/auto/httpserver/httpserver.cpp | 148 +++++++++++++ tests/auto/httpserver/httpserver.h | 105 +++++++++ tests/auto/httpserver/httpsserver.h | 85 ++++++++ tests/auto/httpserver/proxy_server.cpp | 108 +++++++++ tests/auto/httpserver/proxy_server.h | 67 ++++++ tests/auto/quick/CMakeLists.txt | 15 ++ tests/auto/quick/certificateerror/CMakeLists.txt | 26 +++ .../auto/quick/certificateerror/resources/cert.pem | 64 ++++++ .../auto/quick/certificateerror/resources/key.pem | 27 +++ .../certificateerror/tst_certificateerror.cpp | 4 +- tests/auto/quick/dialogs/CMakeLists.txt | 25 +++ tests/auto/quick/dialogs/server.cpp | 79 ------- tests/auto/quick/dialogs/server.h | 59 ----- tests/auto/quick/dialogs/tst_dialogs.cpp | 18 +- tests/auto/quick/html/basic_page.html | 6 - tests/auto/quick/html/basic_page2.html | 1 - .../auto/quick/html/direct-image-compositing.html | 66 ------ tests/auto/quick/html/inputmethod.html | 11 - tests/auto/quick/html/resources/simple_image.png | Bin 10585 -> 0 bytes tests/auto/quick/html/scroll.html | 29 --- tests/auto/quick/inspectorserver/CMakeLists.txt | 9 + .../quick/inspectorserver/html/basic_page.html | 6 + .../quick/inspectorserver/tst_inspectorserver.cpp | 11 +- tests/auto/quick/publicapi/CMakeLists.txt | 8 + tests/auto/quick/qmltests/CMakeLists.txt | 102 +++++++++ .../auto/quick/qmltests/data/tst_notification.qml | 4 +- tests/auto/quick/qmltests/resources/cert.pem | 64 ++++++ tests/auto/quick/qmltests/resources/key.pem | 27 +++ tests/auto/quick/qmltests/tst_qmltests.cpp | 12 +- .../CMakeLists.txt | 10 + .../html/basic_page.html | 6 + .../tst_qquickwebenginedefaultsurfaceformat.cpp | 4 +- .../auto/quick/qquickwebengineview/CMakeLists.txt | 13 ++ .../quick/qquickwebengineview/html/basic_page.html | 6 + .../qquickwebengineview/html/basic_page2.html | 1 + .../html/direct-image-compositing.html | 66 ++++++ .../qquickwebengineview/html/inputmethod.html | 11 + .../html/resources/simple_image.png | Bin 0 -> 10585 bytes .../quick/qquickwebengineview/html/scroll.html | 29 +++ .../tst_qquickwebengineview.cpp | 5 +- tests/auto/quick/qtbug-70248/CMakeLists.txt | 17 ++ tests/auto/quick/shared/qt_webengine_quicktest.h | 57 ----- tests/auto/quick/shared/testwindow.h | 68 ------ tests/auto/quick/shared/util.h | 191 ---------------- .../shared/data/loadprogress/downloadable.tar.gz | Bin 131 -> 0 bytes tests/auto/shared/data/loadprogress/main.html | 30 --- tests/auto/shared/data/loadprogress/page1.html | 8 - tests/auto/shared/data/loadprogress/page2.html | 15 -- tests/auto/shared/data/loadprogress/page3.html | 20 -- tests/auto/shared/data/loadprogress/page4.html | 8 - tests/auto/shared/data/loadprogress/page5.html | 20 -- tests/auto/shared/data/loadprogress/page6.html | 13 -- tests/auto/shared/data/loadprogress/page7.html | 13 -- tests/auto/shared/data/loadprogress/page8.html | 20 -- tests/auto/shared/data/notification.html | 70 ------ tests/auto/shared/httpreqrep.cpp | 135 ------------ tests/auto/shared/httpreqrep.h | 108 --------- tests/auto/shared/httpserver.cpp | 134 ------------ tests/auto/shared/httpserver.h | 99 --------- tests/auto/shared/httpsserver.h | 81 ------- tests/auto/shared/resources/cert.pem | 64 ------ tests/auto/shared/resources/key.pem | 27 --- tests/auto/util/CMakeLists.txt | 7 + tests/auto/util/qt_webengine_quicktest.h | 53 +++++ tests/auto/util/quickutil.h | 191 ++++++++++++++++ tests/auto/util/testwindow.h | 68 ++++++ tests/auto/util/util.cmake | 5 + tests/auto/util/util.h | 238 ++++++++++++++++++++ tests/auto/widgets/CMakeLists.txt | 36 +++ tests/auto/widgets/accessibility/CMakeLists.txt | 9 + .../widgets/accessibility/tst_accessibility.cpp | 2 +- tests/auto/widgets/certificateerror/CMakeLists.txt | 23 ++ .../widgets/certificateerror/resources/cert.pem | 64 ++++++ .../widgets/certificateerror/resources/key.pem | 27 +++ .../certificateerror/tst_certificateerror.cpp | 2 +- .../widgets/defaultsurfaceformat/CMakeLists.txt | 20 ++ .../tst_defaultsurfaceformat.cpp | 2 +- tests/auto/widgets/devtools/CMakeLists.txt | 7 + tests/auto/widgets/faviconmanager/CMakeLists.txt | 29 +++ .../widgets/faviconmanager/tst_faviconmanager.cpp | 118 +++++++--- tests/auto/widgets/loadsignals/CMakeLists.txt | 60 +++++ tests/auto/widgets/loadsignals/tst_loadsignals.cpp | 6 +- tests/auto/widgets/offscreen/CMakeLists.txt | 22 ++ tests/auto/widgets/origins/CMakeLists.txt | 45 ++++ tests/auto/widgets/origins/tst_origins.cpp | 85 +++++--- tests/auto/widgets/printing/CMakeLists.txt | 34 +++ tests/auto/widgets/printing/tst_printing.cpp | 6 +- tests/auto/widgets/proxy/CMakeLists.txt | 9 + tests/auto/widgets/proxy/proxy_server.cpp | 102 --------- tests/auto/widgets/proxy/proxy_server.h | 64 ------ tests/auto/widgets/proxypac/CMakeLists.txt | 46 ++++ tests/auto/widgets/proxypac/tst_proxypac.cpp | 8 +- .../qwebenginedownloadrequest/CMakeLists.txt | 11 + .../tst_qwebenginedownloadrequest.cpp | 2 +- .../auto/widgets/qwebenginehistory/CMakeLists.txt | 26 +++ .../qwebenginehistory/tst_qwebenginehistory.cpp | 2 +- tests/auto/widgets/qwebenginepage/CMakeLists.txt | 61 ++++++ .../widgets/qwebenginepage/resources/image2.png | Bin 0 -> 14743 bytes .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 28 ++- .../auto/widgets/qwebengineprofile/CMakeLists.txt | 11 + .../qwebengineprofile/tst_qwebengineprofile.cpp | 4 +- tests/auto/widgets/qwebenginescript/CMakeLists.txt | 26 +++ .../qwebenginescript/tst_qwebenginescript.cpp | 2 +- .../auto/widgets/qwebenginesettings/CMakeLists.txt | 9 + .../qwebenginesettings/tst_qwebenginesettings.cpp | 2 +- tests/auto/widgets/qwebengineview/CMakeLists.txt | 29 +++ .../auto/widgets/qwebengineview/resources/test.swf | Bin 0 -> 10085 bytes .../widgets/qwebengineview/tst_qwebengineview.cpp | 19 +- tests/auto/widgets/resources/image2.png | Bin 14743 -> 0 bytes tests/auto/widgets/resources/test.swf | Bin 10085 -> 0 bytes tests/auto/widgets/schemes/CMakeLists.txt | 7 + tests/auto/widgets/shutdown/CMakeLists.txt | 6 + tests/auto/widgets/touchinput/CMakeLists.txt | 10 + tests/auto/widgets/touchinput/tst_touchinput.cpp | 2 +- tests/auto/widgets/util.h | 242 --------------------- 140 files changed, 3158 insertions(+), 1982 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/auto/CMakeLists.txt create mode 100644 tests/auto/core/CMakeLists.txt create mode 100644 tests/auto/core/qwebengineclientcertificatestore/CMakeLists.txt create mode 100644 tests/auto/core/qwebenginecookiestore/CMakeLists.txt create mode 100644 tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt create mode 100644 tests/auto/httpserver/CMakeLists.txt create mode 100644 tests/auto/httpserver/data/hedgehog.html create mode 100644 tests/auto/httpserver/data/hedgehog.png create mode 100644 tests/auto/httpserver/data/loadprogress/downloadable.tar.gz create mode 100644 tests/auto/httpserver/data/loadprogress/main.html create mode 100644 tests/auto/httpserver/data/loadprogress/page1.html create mode 100644 tests/auto/httpserver/data/loadprogress/page2.html create mode 100644 tests/auto/httpserver/data/loadprogress/page3.html create mode 100644 tests/auto/httpserver/data/loadprogress/page4.html create mode 100644 tests/auto/httpserver/data/loadprogress/page5.html create mode 100644 tests/auto/httpserver/data/loadprogress/page6.html create mode 100644 tests/auto/httpserver/data/loadprogress/page7.html create mode 100644 tests/auto/httpserver/data/loadprogress/page8.html create mode 100644 tests/auto/httpserver/data/notification.html create mode 100644 tests/auto/httpserver/httpreqrep.cpp create mode 100644 tests/auto/httpserver/httpreqrep.h create mode 100644 tests/auto/httpserver/httpserver.cmake create mode 100644 tests/auto/httpserver/httpserver.cpp create mode 100644 tests/auto/httpserver/httpserver.h create mode 100644 tests/auto/httpserver/httpsserver.h create mode 100644 tests/auto/httpserver/proxy_server.cpp create mode 100644 tests/auto/httpserver/proxy_server.h create mode 100644 tests/auto/quick/CMakeLists.txt create mode 100644 tests/auto/quick/certificateerror/CMakeLists.txt create mode 100644 tests/auto/quick/certificateerror/resources/cert.pem create mode 100644 tests/auto/quick/certificateerror/resources/key.pem create mode 100644 tests/auto/quick/dialogs/CMakeLists.txt delete mode 100644 tests/auto/quick/dialogs/server.cpp delete mode 100644 tests/auto/quick/dialogs/server.h delete mode 100644 tests/auto/quick/html/basic_page.html delete mode 100644 tests/auto/quick/html/basic_page2.html delete mode 100644 tests/auto/quick/html/direct-image-compositing.html delete mode 100644 tests/auto/quick/html/inputmethod.html delete mode 100644 tests/auto/quick/html/resources/simple_image.png delete mode 100644 tests/auto/quick/html/scroll.html create mode 100644 tests/auto/quick/inspectorserver/CMakeLists.txt create mode 100644 tests/auto/quick/inspectorserver/html/basic_page.html create mode 100644 tests/auto/quick/publicapi/CMakeLists.txt create mode 100644 tests/auto/quick/qmltests/CMakeLists.txt create mode 100644 tests/auto/quick/qmltests/resources/cert.pem create mode 100644 tests/auto/quick/qmltests/resources/key.pem create mode 100644 tests/auto/quick/qquickwebenginedefaultsurfaceformat/CMakeLists.txt create mode 100644 tests/auto/quick/qquickwebenginedefaultsurfaceformat/html/basic_page.html create mode 100644 tests/auto/quick/qquickwebengineview/CMakeLists.txt create mode 100644 tests/auto/quick/qquickwebengineview/html/basic_page.html create mode 100644 tests/auto/quick/qquickwebengineview/html/basic_page2.html create mode 100644 tests/auto/quick/qquickwebengineview/html/direct-image-compositing.html create mode 100644 tests/auto/quick/qquickwebengineview/html/inputmethod.html create mode 100644 tests/auto/quick/qquickwebengineview/html/resources/simple_image.png create mode 100644 tests/auto/quick/qquickwebengineview/html/scroll.html create mode 100644 tests/auto/quick/qtbug-70248/CMakeLists.txt delete mode 100644 tests/auto/quick/shared/qt_webengine_quicktest.h delete mode 100644 tests/auto/quick/shared/testwindow.h delete mode 100644 tests/auto/quick/shared/util.h delete mode 100644 tests/auto/shared/data/loadprogress/downloadable.tar.gz delete mode 100644 tests/auto/shared/data/loadprogress/main.html delete mode 100644 tests/auto/shared/data/loadprogress/page1.html delete mode 100644 tests/auto/shared/data/loadprogress/page2.html delete mode 100644 tests/auto/shared/data/loadprogress/page3.html delete mode 100644 tests/auto/shared/data/loadprogress/page4.html delete mode 100644 tests/auto/shared/data/loadprogress/page5.html delete mode 100644 tests/auto/shared/data/loadprogress/page6.html delete mode 100644 tests/auto/shared/data/loadprogress/page7.html delete mode 100644 tests/auto/shared/data/loadprogress/page8.html delete mode 100644 tests/auto/shared/data/notification.html delete mode 100644 tests/auto/shared/httpreqrep.cpp delete mode 100644 tests/auto/shared/httpreqrep.h delete mode 100644 tests/auto/shared/httpserver.cpp delete mode 100644 tests/auto/shared/httpserver.h delete mode 100644 tests/auto/shared/httpsserver.h delete mode 100644 tests/auto/shared/resources/cert.pem delete mode 100644 tests/auto/shared/resources/key.pem create mode 100644 tests/auto/util/CMakeLists.txt create mode 100644 tests/auto/util/qt_webengine_quicktest.h create mode 100644 tests/auto/util/quickutil.h create mode 100644 tests/auto/util/testwindow.h create mode 100644 tests/auto/util/util.cmake create mode 100644 tests/auto/util/util.h create mode 100644 tests/auto/widgets/CMakeLists.txt create mode 100644 tests/auto/widgets/accessibility/CMakeLists.txt create mode 100644 tests/auto/widgets/certificateerror/CMakeLists.txt create mode 100644 tests/auto/widgets/certificateerror/resources/cert.pem create mode 100644 tests/auto/widgets/certificateerror/resources/key.pem create mode 100644 tests/auto/widgets/defaultsurfaceformat/CMakeLists.txt create mode 100644 tests/auto/widgets/devtools/CMakeLists.txt create mode 100644 tests/auto/widgets/faviconmanager/CMakeLists.txt create mode 100644 tests/auto/widgets/loadsignals/CMakeLists.txt create mode 100644 tests/auto/widgets/offscreen/CMakeLists.txt create mode 100644 tests/auto/widgets/origins/CMakeLists.txt create mode 100644 tests/auto/widgets/printing/CMakeLists.txt create mode 100644 tests/auto/widgets/proxy/CMakeLists.txt delete mode 100644 tests/auto/widgets/proxy/proxy_server.cpp delete mode 100644 tests/auto/widgets/proxy/proxy_server.h create mode 100644 tests/auto/widgets/proxypac/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebenginedownloadrequest/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebenginehistory/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebenginepage/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebenginepage/resources/image2.png create mode 100644 tests/auto/widgets/qwebengineprofile/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebenginescript/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebenginesettings/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebengineview/CMakeLists.txt create mode 100644 tests/auto/widgets/qwebengineview/resources/test.swf delete mode 100644 tests/auto/widgets/resources/image2.png delete mode 100644 tests/auto/widgets/resources/test.swf create mode 100644 tests/auto/widgets/schemes/CMakeLists.txt create mode 100644 tests/auto/widgets/shutdown/CMakeLists.txt create mode 100644 tests/auto/widgets/touchinput/CMakeLists.txt delete mode 100644 tests/auto/widgets/util.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..87383cc24 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +if(NOT QT_BUILD_STANDALONE_TESTS) + cmake_minimum_required(VERSION 3.18) + + include(${CMAKE_CURRENT_LIST_DIR}/../.cmake.conf) + + project(QtWebEngineTests + VERSION "${QT_REPO_MODULE_VERSION}" + DESCRIPTION "Qt WebEngine Tests" + HOMEPAGE_URL "https://qt.io/" + LANGUAGES CXX C + ) +endif() + +find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) +find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Gui Widgets + WebEngineCore WebEngineWidgets WebEngineQuick QuickWidgets Test QuickTest) + +if(NOT QT_BUILD_STANDALONE_TESTS) + qt_build_repo_begin() + qt_build_tests() + qt_build_repo_end() +else() + qt_build_tests() +endif() diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt new file mode 100644 index 000000000..2227e6e46 --- /dev/null +++ b/tests/auto/CMakeLists.txt @@ -0,0 +1,17 @@ +if(QT_FEATURE_qtwebengine_build + OR (QT_BUILD_STANDALONE_TESTS AND TARGET Qt::WebEngineCore)) + add_subdirectory(core) + add_subdirectory(httpserver) + add_subdirectory(util) +endif() +if(QT_FEATURE_qtwebengine_quick_build + OR (QT_BUILD_STANDALONE_TESTS AND TARGET Qt::WebEngineQuick)) + add_subdirectory(quick) +endif() +if(QT_FEATURE_qtwebengine_widgets_build + OR (QT_BUILD_STANDALONE_TESTS AND TARGET Qt::WebEngineWidgets)) + add_subdirectory(widgets) +endif() +#if(QT_FEATURE_build_qtpdf AND QT_FEATURE_webengine_qtpdf_support) +# add_subdirectory(pdf) +#endif() diff --git a/tests/auto/core/CMakeLists.txt b/tests/auto/core/CMakeLists.txt new file mode 100644 index 000000000..ee2f010d0 --- /dev/null +++ b/tests/auto/core/CMakeLists.txt @@ -0,0 +1,5 @@ +add_subdirectory(qwebenginecookiestore) +add_subdirectory(qwebengineurlrequestinterceptor) +if(QT_FEATURE_ssl) + add_subdirectory(qwebengineclientcertificatestore) +endif() diff --git a/tests/auto/core/qwebengineclientcertificatestore/CMakeLists.txt b/tests/auto/core/qwebengineclientcertificatestore/CMakeLists.txt new file mode 100644 index 000000000..18bba2e26 --- /dev/null +++ b/tests/auto/core/qwebengineclientcertificatestore/CMakeLists.txt @@ -0,0 +1,21 @@ +qt_internal_add_test(tst_qwebengineclientcertificatestore + SOURCES + tst_qwebengineclientcertificatestore.cpp + LIBRARIES + Qt::WebEngineCore +) + +set(tst_qwebengineclientcertificatestore_resource_files + "resources/certificate.crt" + "resources/certificate1.crt" + "resources/privatekey.key" + "resources/privatekey1.key" +) + +qt_add_resource(tst_qwebengineclientcertificatestore "tst_qwebengineclientcertificatestore" + PREFIX + "/" + FILES + ${tst_qwebengineclientcertificatestore_resource_files} +) + diff --git a/tests/auto/core/qwebenginecookiestore/CMakeLists.txt b/tests/auto/core/qwebenginecookiestore/CMakeLists.txt new file mode 100644 index 000000000..078259ccf --- /dev/null +++ b/tests/auto/core/qwebenginecookiestore/CMakeLists.txt @@ -0,0 +1,23 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebenginecookiestore + SOURCES + tst_qwebenginecookiestore.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) + +set(tst_qwebenginecookiestore_resource_files + "resources/content.html" + "resources/index.html" +) + +qt_add_resource(tst_qwebenginecookiestore "tst_qwebenginecookiestore" + PREFIX + "/" + FILES + ${tst_qwebenginecookiestore_resource_files} +) diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp index dbd645a83..e056fef8f 100644 --- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp +++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "../../widgets/util.h" +#include #include #include #include diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt b/tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt new file mode 100644 index 000000000..fa6de9ef5 --- /dev/null +++ b/tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt @@ -0,0 +1,41 @@ +include(../../util/util.cmake) +include(../../httpserver/httpserver.cmake) + +qt_internal_add_test(tst_qwebengineurlrequestinterceptor + SOURCES + tst_qwebengineurlrequestinterceptor.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) + +set(tst_qwebengineurlrequestinterceptor_resource_files + "resources/content.html" + "resources/favicon.html" + "resources/firstparty.html" + "resources/fontawesome.woff" + "resources/icons/favicon.png" + "resources/iframe.html" + "resources/iframe2.html" + "resources/iframe3.html" + "resources/image.html" + "resources/image_in_iframe.html" + "resources/index.html" + "resources/media.html" + "resources/media.mp4" + "resources/media_in_iframe.html" + "resources/resource.html" + "resources/resource_in_iframe.html" + "resources/script.js" + "resources/style.css" + "resources/sw.html" + "resources/sw.js" +) + +qt_add_resource(tst_qwebengineurlrequestinterceptor "tst_qwebengineurlrequestinterceptor" + PREFIX + "/" + FILES + ${tst_qwebengineurlrequestinterceptor_resource_files} +) diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp index 34ef111f2..8a6cbb331 100644 --- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp +++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "../../widgets/util.h" +#include #include #include #include @@ -416,7 +416,8 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl() void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes_data() { - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/iframe.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/iframe.html")); QTest::addColumn("requestUrl"); QTest::newRow("ui file") << url; QTest::newRow("ui qrc") << QUrl("qrc:///resources/iframe.html"); @@ -426,8 +427,13 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes() { QFETCH(QUrl, requestUrl); - if (requestUrl.scheme() == "file" && !QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (requestUrl.scheme() == "file" + && !QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QString adjustedUrl = requestUrl.adjusted(QUrl::RemoveFilename).toString(); @@ -461,17 +467,30 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes() void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType_data() { - QUrl firstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/resource_in_iframe.html")); - QUrl styleRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/style.css")); - QUrl scriptRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/script.js")); - QUrl fontRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/fontawesome.woff")); - QUrl xhrRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/test")); - QUrl imageFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/image_in_iframe.html")); - QUrl imageRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/icons/favicon.png")); - QUrl mediaFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/media_in_iframe.html")); - QUrl mediaRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/media.mp4")); - QUrl faviconFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/favicon.html")); - QUrl faviconRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/icons/favicon.png")); + QUrl firstPartyUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/resource_in_iframe.html")); + QUrl styleRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/style.css")); + QUrl scriptRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/script.js")); + QUrl fontRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/fontawesome.woff")); + QUrl xhrRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/test")); + QUrl imageFirstPartyUrl = + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/image_in_iframe.html")); + QUrl imageRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/favicon.png")); + QUrl mediaFirstPartyUrl = + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/media_in_iframe.html")); + QUrl mediaRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/media.mp4")); + QUrl faviconFirstPartyUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon.html")); + QUrl faviconRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/favicon.png")); QTest::addColumn("requestUrl"); QTest::addColumn("firstPartyUrl"); @@ -498,8 +517,12 @@ void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType_data( void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QFETCH(QUrl, requestUrl); QFETCH(QUrl, firstPartyUrl); QFETCH(int, resourceType); @@ -583,7 +606,8 @@ void tst_QWebEngineUrlRequestInterceptor::customHeaders() { // Create HTTP Server to parse the request. HttpServer httpServer; - httpServer.setResourceDirs({ TESTS_SOURCE_DIR "qwebengineurlrequestinterceptor/resources" }); + httpServer.setResourceDirs({ QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources" }); QVERIFY(httpServer.start()); QWebEngineProfile profile; @@ -700,7 +724,7 @@ void tst_QWebEngineUrlRequestInterceptor::jsServiceWorker() { HttpServer server; - server.setResourceDirs({ TESTS_SOURCE_DIR "qwebengineurlrequestinterceptor/resources" }); + server.setResourceDirs({ QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + "/resources" }); QVERIFY(server.start()); QWebEngineProfile profile(QStringLiteral("Test")); diff --git a/tests/auto/httpserver/CMakeLists.txt b/tests/auto/httpserver/CMakeLists.txt new file mode 100644 index 000000000..7d4ddd030 --- /dev/null +++ b/tests/auto/httpserver/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.18) +project(minimal LANGUAGES CXX) + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Network) + +include(httpserver.cmake) diff --git a/tests/auto/httpserver/data/hedgehog.html b/tests/auto/httpserver/data/hedgehog.html new file mode 100644 index 000000000..d8abbcd48 --- /dev/null +++ b/tests/auto/httpserver/data/hedgehog.html @@ -0,0 +1,9 @@ + + + + BREAKING NEWS: 15 Hedgehogs With Things That Look Like Hedgehogs + + + + + diff --git a/tests/auto/httpserver/data/hedgehog.png b/tests/auto/httpserver/data/hedgehog.png new file mode 100644 index 000000000..4d56d8633 Binary files /dev/null and b/tests/auto/httpserver/data/hedgehog.png differ diff --git a/tests/auto/httpserver/data/loadprogress/downloadable.tar.gz b/tests/auto/httpserver/data/loadprogress/downloadable.tar.gz new file mode 100644 index 000000000..741cb8ca6 Binary files /dev/null and b/tests/auto/httpserver/data/loadprogress/downloadable.tar.gz differ diff --git a/tests/auto/httpserver/data/loadprogress/main.html b/tests/auto/httpserver/data/loadprogress/main.html new file mode 100644 index 000000000..3b7d2034b --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/main.html @@ -0,0 +1,30 @@ + +Load Progress Test Page + + page1 + + + +

Hello.

+ +

body in monospace

+ + + + + + diff --git a/tests/auto/httpserver/data/loadprogress/page1.html b/tests/auto/httpserver/data/loadprogress/page1.html new file mode 100644 index 000000000..9b11ce887 --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page1.html @@ -0,0 +1,8 @@ + + + page1 + + + + + diff --git a/tests/auto/httpserver/data/loadprogress/page2.html b/tests/auto/httpserver/data/loadprogress/page2.html new file mode 100644 index 000000000..223817c8c --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page2.html @@ -0,0 +1,15 @@ + + + page2 + + + + +
page2 anchor
+ + diff --git a/tests/auto/httpserver/data/loadprogress/page3.html b/tests/auto/httpserver/data/loadprogress/page3.html new file mode 100644 index 000000000..d38ca31f0 --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page3.html @@ -0,0 +1,20 @@ + + + page3 + + + + + +
page3 anchor
+ + diff --git a/tests/auto/httpserver/data/loadprogress/page4.html b/tests/auto/httpserver/data/loadprogress/page4.html new file mode 100644 index 000000000..61976b4fb --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page4.html @@ -0,0 +1,8 @@ + + + page4 + + + download + + diff --git a/tests/auto/httpserver/data/loadprogress/page5.html b/tests/auto/httpserver/data/loadprogress/page5.html new file mode 100644 index 000000000..47709ff08 --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page5.html @@ -0,0 +1,20 @@ + + + page5 + + + + + +
here is the anchor
+ + diff --git a/tests/auto/httpserver/data/loadprogress/page6.html b/tests/auto/httpserver/data/loadprogress/page6.html new file mode 100644 index 000000000..98042701a --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page6.html @@ -0,0 +1,13 @@ + + + page6 + + + + + + diff --git a/tests/auto/httpserver/data/loadprogress/page7.html b/tests/auto/httpserver/data/loadprogress/page7.html new file mode 100644 index 000000000..42538c5de --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page7.html @@ -0,0 +1,13 @@ + + + page6 + + + + + + diff --git a/tests/auto/httpserver/data/loadprogress/page8.html b/tests/auto/httpserver/data/loadprogress/page8.html new file mode 100644 index 000000000..8ebdddf97 --- /dev/null +++ b/tests/auto/httpserver/data/loadprogress/page8.html @@ -0,0 +1,20 @@ + + + Page with js navigation in the end of document to anchor within the page + + + + +
here is the anchor
+ + + diff --git a/tests/auto/httpserver/data/notification.html b/tests/auto/httpserver/data/notification.html new file mode 100644 index 000000000..1d1e9c411 --- /dev/null +++ b/tests/auto/httpserver/data/notification.html @@ -0,0 +1,70 @@ + + + +Desktop Notifications Demo + + + +
+ Title:
+ Body:
+
+ +
+
+ + diff --git a/tests/auto/httpserver/httpreqrep.cpp b/tests/auto/httpserver/httpreqrep.cpp new file mode 100644 index 000000000..ee9dbbaa9 --- /dev/null +++ b/tests/auto/httpserver/httpreqrep.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#include "httpreqrep.h" + +HttpReqRep::HttpReqRep(QTcpSocket *socket, QObject *parent) + : QObject(parent), m_socket(socket) +{ + m_socket->setParent(this); + connect(m_socket, &QTcpSocket::readyRead, this, &HttpReqRep::handleReadyRead); + connect(m_socket, &QTcpSocket::disconnected, this, &HttpReqRep::handleDisconnected); +} + +void HttpReqRep::sendResponse(int statusCode) +{ + if (m_state != State::REQUEST_RECEIVED) + return; + m_responseStatusCode = statusCode; + m_socket->write("HTTP/1.1 "); + m_socket->write(QByteArray::number(m_responseStatusCode)); + m_socket->write(" OK?\r\n"); + for (const auto & kv : m_responseHeaders) { + m_socket->write(kv.first); + m_socket->write(": "); + m_socket->write(kv.second); + m_socket->write("\r\n"); + } + m_socket->write("Connection: close\r\n"); + m_socket->write("\r\n"); + m_socket->write(m_responseBody); + m_state = State::DISCONNECTING; + m_socket->disconnectFromHost(); + Q_EMIT responseSent(); +} + +void HttpReqRep::sendResponse(const QByteArray &response) +{ + m_socket->write(response); + m_state = State::DISCONNECTING; + m_socket->disconnectFromHost(); + Q_EMIT responseSent(); +} + +void HttpReqRep::close() +{ + if (m_state != State::REQUEST_RECEIVED) + return; + m_state = State::DISCONNECTING; + m_socket->disconnectFromHost(); + Q_EMIT error(QStringLiteral("missing response")); +} + +QByteArray HttpReqRep::requestHeader(const QByteArray &key) const +{ + auto it = m_requestHeaders.find(key.toLower()); + if (it != m_requestHeaders.end()) + return it->second; + return {}; +} + +void HttpReqRep::handleReadyRead() +{ + while (m_socket->canReadLine()) { + switch (m_state) { + case State::RECEIVING_REQUEST: { + const auto requestLine = m_socket->readLine(); + const auto requestLineParts = requestLine.split(' '); + if (requestLineParts.size() != 3 || !requestLineParts[2].toUpper().startsWith("HTTP/")) { + m_state = State::DISCONNECTING; + m_socket->disconnectFromHost(); + Q_EMIT error(QStringLiteral("invalid request line")); + return; + } + m_requestMethod = requestLineParts[0]; + m_requestPath = requestLineParts[1]; + m_state = State::RECEIVING_HEADERS; + break; + } + case State::RECEIVING_HEADERS: { + const auto headerLine = m_socket->readLine(); + if (headerLine == QByteArrayLiteral("\r\n")) { + m_state = State::REQUEST_RECEIVED; + Q_EMIT requestReceived(); + return; + } + int colonIndex = headerLine.indexOf(':'); + if (colonIndex < 0) { + m_state = State::DISCONNECTING; + m_socket->disconnectFromHost(); + Q_EMIT error(QStringLiteral("invalid header line")); + return; + } + auto headerKey = headerLine.left(colonIndex).trimmed().toLower(); + auto headerValue = headerLine.mid(colonIndex + 1).trimmed().toLower(); + m_requestHeaders.emplace(headerKey, headerValue); + break; + } + default: + return; + } + } +} + +void HttpReqRep::handleDisconnected() +{ + switch (m_state) { + case State::RECEIVING_REQUEST: + case State::RECEIVING_HEADERS: + case State::REQUEST_RECEIVED: + Q_EMIT error(QStringLiteral("unexpected disconnect")); + break; + case State::DISCONNECTING: + break; + case State::DISCONNECTED: + Q_UNREACHABLE(); + } + m_state = State::DISCONNECTED; + Q_EMIT closed(); +} diff --git a/tests/auto/httpserver/httpreqrep.h b/tests/auto/httpserver/httpreqrep.h new file mode 100644 index 000000000..e1979e050 --- /dev/null +++ b/tests/auto/httpserver/httpreqrep.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#ifndef HTTPREQREP_H +#define HTTPREQREP_H + +#include + +#include +#include + +// Represents an HTTP request-response exchange. +class HttpReqRep : public QObject +{ + Q_OBJECT +public: + explicit HttpReqRep(QTcpSocket *socket, QObject *parent = nullptr); + + Q_INVOKABLE void sendResponse(int statusCode = 200); + void sendResponse(const QByteArray &response); + void close(); + bool isClosed() const { return m_state == State::DISCONNECTED; } + + // Request parameters (only valid after requestReceived()) + + QByteArray requestMethod() const { return m_requestMethod; } + QByteArray requestPath() const { return m_requestPath; } + QByteArray requestHeader(const QByteArray &key) const; + + // Response parameters (can be set until sendResponse()/close()). + + int responseStatus() const { return m_responseStatusCode; } + void setResponseStatus(int statusCode) + { + m_responseStatusCode = statusCode; + } + void setResponseHeader(const QByteArray &key, QByteArray value) + { + m_responseHeaders[key.toLower()] = std::move(value); + } + QByteArray responseBody() const { return m_responseBody; } + Q_INVOKABLE void setResponseBody(QByteArray content) + { + m_responseHeaders["content-length"] = QByteArray::number(content.size()); + m_responseBody = std::move(content); + } + +Q_SIGNALS: + // Emitted when the request has been correctly parsed. + void requestReceived(); + // Emitted on first call to sendResponse(). + void responseSent(); + // Emitted when something goes wrong. + void error(const QString &error); + // Emitted during or some time after sendResponse() or close(). + void closed(); + +private Q_SLOTS: + void handleReadyRead(); + void handleDisconnected(); + +private: + enum class State { + // Waiting for first line of request. + RECEIVING_REQUEST, // Next: RECEIVING_HEADERS or DISCONNECTING. + // Waiting for header lines. + RECEIVING_HEADERS, // Next: REQUEST_RECEIVED or DISCONNECTING. + // Request parsing succeeded, waiting for sendResponse() or close(). + REQUEST_RECEIVED, // Next: DISCONNECTING. + // Waiting for network. + DISCONNECTING, // Next: DISCONNECTED. + // Connection is dead. + DISCONNECTED, // Next: - + }; + QTcpSocket *m_socket = nullptr; + State m_state = State::RECEIVING_REQUEST; + QByteArray m_requestMethod; + QByteArray m_requestPath; + std::map m_requestHeaders; + int m_responseStatusCode = -1; + std::map m_responseHeaders; + QByteArray m_responseBody; +}; + +#endif // !HTTPREQREP_H diff --git a/tests/auto/httpserver/httpserver.cmake b/tests/auto/httpserver/httpserver.cmake new file mode 100644 index 000000000..78d13055c --- /dev/null +++ b/tests/auto/httpserver/httpserver.cmake @@ -0,0 +1,38 @@ +if (NOT TARGET Test::HttpServer) + + set(CMAKE_AUTOMOC ON) + set(CMAKE_AUTORCC ON) + set(CMAKE_AUTOUIC ON) + + add_library(httpserver STATIC + ${CMAKE_CURRENT_LIST_DIR}/httpreqrep.cpp + ${CMAKE_CURRENT_LIST_DIR}/httpreqrep.h + ${CMAKE_CURRENT_LIST_DIR}/httpserver.cpp + ${CMAKE_CURRENT_LIST_DIR}/httpserver.h + ${CMAKE_CURRENT_LIST_DIR}/proxy_server.h + ${CMAKE_CURRENT_LIST_DIR}/proxy_server.cpp + ) + + if(QT_FEATURE_ssl) + target_sources(httpserver INTERFACE ${CMAKE_CURRENT_LIST_DIR}/httpsserver.h) + endif() + + add_library(Test::HttpServer ALIAS httpserver) + + target_include_directories(httpserver INTERFACE + $ + ) + + target_link_libraries(httpserver PUBLIC + Qt::Core + Qt::Network + ) + + target_compile_definitions(httpserver PRIVATE + SERVER_SOURCE_DIR="${CMAKE_CURRENT_LIST_DIR}" + ) + + set_target_properties(httpserver PROPERTIES + SHARED_DATA "${CMAKE_CURRENT_LIST_DIR}/data" + ) +endif() diff --git a/tests/auto/httpserver/httpserver.cpp b/tests/auto/httpserver/httpserver.cpp new file mode 100644 index 000000000..10147ae6c --- /dev/null +++ b/tests/auto/httpserver/httpserver.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#include "httpserver.h" + +#include +#include +#include + +Q_LOGGING_CATEGORY(gHttpServerLog, "HttpServer") + +HttpServer::HttpServer(QObject *parent) + : HttpServer(new QTcpServer, "http", QHostAddress::LocalHost, 0, parent) +{ +} + +HttpServer::HttpServer(const QHostAddress &hostAddress, quint16 port, QObject *parent) + : HttpServer(new QTcpServer, "http", hostAddress, port, parent) +{ +} + +HttpServer::HttpServer(QTcpServer *tcpServer, const QString &protocol, + const QHostAddress &hostAddress, quint16 port, QObject *parent) + : QObject(parent), m_tcpServer(tcpServer), m_hostAddress(hostAddress), m_port(port) +{ + m_url.setHost(hostAddress.toString()); + m_url.setScheme(protocol); + connect(tcpServer, &QTcpServer::newConnection, this, &HttpServer::handleNewConnection); +} + +HttpServer::~HttpServer() +{ + delete m_tcpServer; +} + +bool HttpServer::start() +{ + m_error = false; + m_expectingError = false; + m_ignoreNewConnection = false; + + if (!m_tcpServer->listen(m_hostAddress, m_port)) { + qCWarning(gHttpServerLog).noquote() << m_tcpServer->errorString(); + return false; + } + + m_url.setPort(m_tcpServer->serverPort()); + return true; +} + +bool HttpServer::stop() +{ + m_tcpServer->close(); + return m_error == m_expectingError; +} + +void HttpServer::setExpectError(bool b) +{ + m_expectingError = b; +} + +QUrl HttpServer::url(const QString &path) const +{ + auto copy = m_url; + copy.setPath(path); + return copy; +} + +void HttpServer::handleNewConnection() +{ + if (m_ignoreNewConnection) + return; + + auto rr = new HttpReqRep(m_tcpServer->nextPendingConnection(), this); + connect(rr, &HttpReqRep::requestReceived, [this, rr]() { + Q_EMIT newRequest(rr); + if (rr->isClosed()) // was explicitly answered + return; + + // if request wasn't handled or purposely ignored for default behavior + // then try to serve htmls from resources dirs if set + if (rr->requestMethod() == "GET") { + for (auto &&dir : qAsConst(m_dirs)) { + QFile f(dir + rr->requestPath()); + if (f.exists()) { + if (f.open(QFile::ReadOnly)) { + QMimeType mime = QMimeDatabase().mimeTypeForFileNameAndData(f.fileName(), &f); + rr->setResponseHeader(QByteArrayLiteral("Content-Type"), mime.name().toUtf8()); + rr->setResponseBody(f.readAll()); + rr->sendResponse(); + } else { + qWarning() << "Can't open resource" << f.fileName() << ": " << f.errorString(); + rr->sendResponse(500); // internal server error + } + break; + } else { + qWarning() << "Can't open resource" << dir + rr->requestPath(); + } + } + } + + if (!rr->isClosed()) + rr->sendResponse(404); + }); + connect(rr, &HttpReqRep::responseSent, [rr]() { + qCInfo(gHttpServerLog).noquote() << rr->requestMethod() << rr->requestPath() + << rr->responseStatus() << rr->responseBody().size(); + }); + connect(rr, &HttpReqRep::error, [this, rr](const QString &error) { + qCWarning(gHttpServerLog).noquote() << rr->requestMethod() << rr->requestPath() + << error; + m_error = true; + }); + + if (!m_tcpServer->isListening()) { + m_ignoreNewConnection = true; + connect(rr, &HttpReqRep::closed, rr, &QObject::deleteLater); + } +} + +QString HttpServer::sharedDataDir() const +{ + return SERVER_SOURCE_DIR + QLatin1String("/data"); +} diff --git a/tests/auto/httpserver/httpserver.h b/tests/auto/httpserver/httpserver.h new file mode 100644 index 000000000..acc742775 --- /dev/null +++ b/tests/auto/httpserver/httpserver.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#ifndef HTTPSERVER_H +#define HTTPSERVER_H + +#include "httpreqrep.h" + +#include +#include + +// Listens on a TCP socket and creates HttpReqReps for each connection. +// +// Usage: +// +// HttpServer server; +// connect(&server, &HttpServer::newRequest, [](HttpReqRep *rr) { +// if (rr->requestPath() == "/myPage.html") { +// rr->setResponseBody("Hello, World!"); +// rr->sendResponse(); +// } +// }); +// QVERIFY(server.start()); +// /* do stuff */ +// QVERIFY(server.stop()); +// +// HttpServer owns the HttpReqRep objects. The signal handler should not store +// references to HttpReqRep objects. +// +// Only if a handler calls sendResponse() will a response be actually sent. This +// means that multiple handlers can be connected to the signal, with different +// handlers responsible for different paths. +class HttpServer : public QObject +{ + Q_OBJECT +public: + explicit HttpServer(QObject *parent = nullptr); + HttpServer(const QHostAddress &hostAddress, quint16 port, QObject *parent = nullptr); + HttpServer(QTcpServer *server, const QString &protocol, const QHostAddress &address, + quint16 port, QObject *parent = nullptr); + + ~HttpServer() override; + + // Must be called to start listening. + // + // Returns true if a TCP port has been successfully bound. + Q_INVOKABLE Q_REQUIRED_RESULT bool start(); + + // Stops listening and performs final error checks. + Q_INVOKABLE Q_REQUIRED_RESULT bool stop(); + + Q_INVOKABLE void setExpectError(bool b); + + // Full URL for given relative path + Q_INVOKABLE QUrl url(const QString &path = QStringLiteral("/")) const; + + Q_INVOKABLE QString sharedDataDir() const; + + Q_INVOKABLE void setResourceDirs(const QStringList &dirs) { m_dirs = dirs; } + + Q_INVOKABLE void setHostDomain(const QString &host) { m_url.setHost(host); } + +Q_SIGNALS: + // Emitted after a HTTP request has been successfully parsed. + void newRequest(HttpReqRep *reqRep); + +private Q_SLOTS: + void handleNewConnection(); + +private: + QTcpServer *m_tcpServer; + QUrl m_url; + QStringList m_dirs; + bool m_error = false; + bool m_ignoreNewConnection = false; + bool m_expectingError = false; + QHostAddress m_hostAddress; + quint16 m_port; +}; + +#endif // !HTTPSERVER_H diff --git a/tests/auto/httpserver/httpsserver.h b/tests/auto/httpserver/httpsserver.h new file mode 100644 index 000000000..b257e69a7 --- /dev/null +++ b/tests/auto/httpserver/httpsserver.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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$ +** +****************************************************************************/ +#ifndef HTTPSSERVER_H +#define HTTPSSERVER_H + +#include "httpreqrep.h" +#include "httpserver.h" + +#include +#include +#include +#include +#include +#include + +struct SslTcpServer : QTcpServer +{ + SslTcpServer(const QString &certPath, const QString &keyPath) { + sslconf.setLocalCertificateChain(QSslCertificate::fromPath(certPath)); + sslconf.setPrivateKey(readKey(keyPath)); + } + + void incomingConnection(qintptr d) override { + auto socket = new QSslSocket(this); + socket->setSslConfiguration(sslconf); + + if (!socket->setSocketDescriptor(d)) { + qWarning() << "Failed to setup ssl socket!"; + delete socket; + return; + } + + connect(socket, QOverload::of(&QSslSocket::errorOccurred), + [] (QSslSocket::SocketError e) { qWarning() << "! Socket Error:" << e; }); + connect(socket, QOverload &>::of(&QSslSocket::sslErrors), + [] (const QList &le) { qWarning() << "! SSL Errors:\n" << le; }); + + addPendingConnection(socket); + socket->startServerEncryption(); + } + + QSslKey readKey(const QString &path) const { + QFile file(path); + file.open(QIODevice::ReadOnly); + return QSslKey(file.readAll(), QSsl::Rsa, QSsl::Pem); + } + + QSslConfiguration sslconf; +}; + +struct HttpsServer : HttpServer +{ + HttpsServer(const QString &certPath, const QString &keyPath, QObject *parent = nullptr) + : HttpServer(new SslTcpServer(certPath, keyPath), "https", QHostAddress::LocalHost, 0, + parent) + { + } +}; + +#endif diff --git a/tests/auto/httpserver/proxy_server.cpp b/tests/auto/httpserver/proxy_server.cpp new file mode 100644 index 000000000..3c5588603 --- /dev/null +++ b/tests/auto/httpserver/proxy_server.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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$ +** +****************************************************************************/ + +#include "proxy_server.h" +#include +#include +#include + +ProxyServer::ProxyServer(QObject *parent) : QObject(parent) +{ + connect(&m_server, &QTcpServer::newConnection, this, &ProxyServer::handleNewConnection); +} + +void ProxyServer::setPort(int port) +{ + m_port = port; +} + +void ProxyServer::setCredentials(const QByteArray &user, const QByteArray password) +{ + m_auth.append(user); + m_auth.append(':'); + m_auth.append(password); + m_auth = m_auth.toBase64(); + m_authenticate = true; +} + +void ProxyServer::setCookie(const QByteArray &cookie) +{ + m_cookie.append(QByteArrayLiteral("Cookie: ")); + m_cookie.append(cookie); +} + + +bool ProxyServer::isListening() +{ + return m_server.isListening(); +} + +void ProxyServer::run() +{ + if (!m_server.listen(QHostAddress::LocalHost, m_port)) + qFatal("Could not start the test server"); +} + +void ProxyServer::handleNewConnection() +{ + // do one connection at the time + Q_ASSERT(m_data.isEmpty()); + QTcpSocket *socket = m_server.nextPendingConnection(); + Q_ASSERT(socket); + connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); + connect(socket, &QAbstractSocket::readyRead, this, &ProxyServer::handleReadReady); +} + +void ProxyServer::handleReadReady() +{ + QTcpSocket *socket = qobject_cast(sender()); + Q_ASSERT(socket); + + m_data.append(socket->readAll()); + + if (!m_data.endsWith("\r\n\r\n")) + return; + + if (m_authenticate && !m_data.contains(QByteArrayLiteral("Proxy-Authorization: Basic"))) { + socket->write("HTTP/1.1 407 Proxy Authentication Required\nProxy-Authenticate: " + "Basic realm=\"Proxy requires authentication\"\r\n" + "content-length: 0\r\n" + "\r\n"); + return; + } + + if (m_authenticate && m_data.contains(m_auth)) { + emit authenticationSuccess(); + } + + if (m_data.contains(m_cookie)) { + emit cookieMatch(); + } + m_data.clear(); + emit requestReceived(); +} diff --git a/tests/auto/httpserver/proxy_server.h b/tests/auto/httpserver/proxy_server.h new file mode 100644 index 000000000..57e69efe7 --- /dev/null +++ b/tests/auto/httpserver/proxy_server.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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$ +** +****************************************************************************/ + +#ifndef PROXY_SERVER_H +#define PROXY_SERVER_H + +#include +#include + +class ProxyServer : public QObject +{ + Q_OBJECT + +public: + explicit ProxyServer(QObject *parent = nullptr); + void setCredentials(const QByteArray &user, const QByteArray password); + void setCookie(const QByteArray &cookie); + bool isListening(); + void setPort(int port); + +public slots: + void run(); + +private slots: + void handleNewConnection(); + void handleReadReady(); + +signals: + void authenticationSuccess(); + void cookieMatch(); + void requestReceived(); + +private: + int m_port = 5555; + QByteArray m_data; + QTcpServer m_server; + QByteArray m_auth; + QByteArray m_cookie; + bool m_authenticate = false; +}; + +#endif // PROXY_SERVER_H diff --git a/tests/auto/quick/CMakeLists.txt b/tests/auto/quick/CMakeLists.txt new file mode 100644 index 000000000..32d58ec7f --- /dev/null +++ b/tests/auto/quick/CMakeLists.txt @@ -0,0 +1,15 @@ +add_subdirectory(dialogs) +add_subdirectory(publicapi) +add_subdirectory(qquickwebenginedefaultsurfaceformat) +add_subdirectory(qtbug-70248) +if(QT_FEATURE_ssl) + add_subdirectory(certificateerror) +endif() +if(NOT boot2qt) + add_subdirectory(inspectorserver) + add_subdirectory(qmltests) + add_subdirectory(qquickwebengineview) +endif() +if(QT_FEATURE_webengine_testsupport) +# add_subdirectory(qquickwebengineviewgraphics) +endif() diff --git a/tests/auto/quick/certificateerror/CMakeLists.txt b/tests/auto/quick/certificateerror/CMakeLists.txt new file mode 100644 index 000000000..4fe350978 --- /dev/null +++ b/tests/auto/quick/certificateerror/CMakeLists.txt @@ -0,0 +1,26 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_certificateerror_quick + SOURCES + testhandler.cpp testhandler.h + tst_certificateerror.cpp + LIBRARIES + Qt::CorePrivate + Qt::WebEngineQuickPrivate + Test::HttpServer + Test::Util +) + +set(certificateerror_resource_files + "resources/cert.pem" + "resources/key.pem" + "WebView.qml" +) + +qt_add_resource(tst_certificateerror_quick "certificateerror" + PREFIX + "/" + FILES + ${certificateerror_resource_files} +) diff --git a/tests/auto/quick/certificateerror/resources/cert.pem b/tests/auto/quick/certificateerror/resources/cert.pem new file mode 100644 index 000000000..3aaaf289c --- /dev/null +++ b/tests/auto/quick/certificateerror/resources/cert.pem @@ -0,0 +1,64 @@ +-----BEGIN CERTIFICATE----- +MIIEpDCCAoygAwIBAgIUO90aty9AMjvBvzfUhr1WwdBrKkMwDQYJKoZIhvcNAQEL +BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM +DVNhbiBGcmFuY2lzY28xDzANBgNVBAoMBkJhZFNTTDEyMDAGA1UEAwwpQmFkU1NM +IEludGVybWVkaWF0ZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTkwOD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tlUL5owNL4uhRP8BbwOja2Gopn2+kA9CNqdwPI4Ipjlr +yo61oCqzy3RAXOUct8WAvybacADmJODAxDq9O5fAZuYZScjjj1ASowmbyDH/Wb9z ++WfiKKH4BfgOIukzK3I1M9wiSDefIodCFfEVXbdNudZj8f9Gw4RrZwkUuxDLeRWG +ReDtzAWq7G0Diw3uX40S4jaj3MeS6oHp2Nrj/VyjSRiYTeN/pnA9N0M5VuCYYvXD +f50rrigjQfOgb4TmnyJAjXWVkXW7Fa+ooLsbvlfr8wP8f31y1cgWPHTVIv6Kmug7 +Bg88k3x5gLTXmutDjseORonhGMRdAxHgJVf5aKfzdRpwXZTDZJXhsAz9OdlOhNZd +UrYo680QugA0V3H5D8Egbr2AUUSMDkn133COjeOIDknFxX3qDqeTzqLZCAEBIoKn +Adpix0jvG1Ys4Ayq6K2wQFdGFjtl6LsiGC7pWWU= +-----END CERTIFICATE----- diff --git a/tests/auto/quick/certificateerror/resources/key.pem b/tests/auto/quick/certificateerror/resources/key.pem new file mode 100644 index 000000000..89922679a --- /dev/null +++ b/tests/auto/quick/certificateerror/resources/key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAkybT/L4zJCqefpd+eYT6aQ0PtobQfFgP+n+z5wWoUxIAJnjb +5ZW47IJxka/2/ggzJOfrUBur54LkTfFQ+yX85eKYCuH0GLz+Rve50LDn0ya6qSgm +EhDG0bend2tMZY+Nl3B+5Ane1vua8hdJjv3ZO3e5UgpQwysL54eYyhEWWlbFWF11 +LhEdMYp953UGLqoV4Mlw+Li8TmFwdKQx6icgBTuloXLzk9aUU+b6NbXdadNXkmzg +09ICsb8pnMXiF2P9Xm5rK0IoiRkSHxVnU12nQXh65Ns/2Dj5DcbHmVdvallfr4wn +LeFPUotysZnvFmE7FLMSr/eQfkTG+Jlb7ZhoGwIDAQABAoIBADRXy3BL98UVo+tD +2ClBtBFKJBy5N9ADQyvH4SZ8TLO/423L7+xqpaz7eYppH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G6jtmPwxWk4EYAsO1u4XiyziABkoNyLKVH4hZg61BsV +jL7R5UrUvBbhKLFOwkcB4Kwdwu7COB/UKa5XJBTMbuw1UTyxlUeI +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/quick/certificateerror/tst_certificateerror.cpp b/tests/auto/quick/certificateerror/tst_certificateerror.cpp index 3e2dc85fb..dd7799919 100644 --- a/tests/auto/quick/certificateerror/tst_certificateerror.cpp +++ b/tests/auto/quick/certificateerror/tst_certificateerror.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include "testhandler.h" #include -#include +#include #include #include #include @@ -75,7 +75,7 @@ void tst_CertificateError::handleError_data() void tst_CertificateError::handleError() { - HttpsServer server; + HttpsServer server(":/resources/cert.pem",":/resources/key.pem"); server.setExpectError(true); QVERIFY(server.start()); diff --git a/tests/auto/quick/dialogs/CMakeLists.txt b/tests/auto/quick/dialogs/CMakeLists.txt new file mode 100644 index 000000000..b1fbfe3a3 --- /dev/null +++ b/tests/auto/quick/dialogs/CMakeLists.txt @@ -0,0 +1,25 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_dialogs + SOURCES + testhandler.cpp testhandler.h + tst_dialogs.cpp + LIBRARIES + Qt::CorePrivate + Qt::WebEngineQuickPrivate + Test::HttpServer + Test::Util +) + +set(dialogs_resource_files + "WebView.qml" + "index.html" +) + +qt_add_resource(tst_dialogs "dialogs" + PREFIX + "/" + FILES + ${dialogs_resource_files} +) diff --git a/tests/auto/quick/dialogs/server.cpp b/tests/auto/quick/dialogs/server.cpp deleted file mode 100644 index dfc7c97ad..000000000 --- a/tests/auto/quick/dialogs/server.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ - -#include "server.h" -#include -#include -#include - -Server::Server(QObject *parent) : QObject(parent) -{ - connect(&m_server, &QTcpServer::newConnection, this, &Server::handleNewConnection); -} - -bool Server::isListening() -{ - return m_server.isListening(); -} - -void Server::setReply(const QByteArray &reply) -{ - m_reply = reply; -} - -void Server::run() -{ - if (!m_server.listen(QHostAddress::LocalHost, 5555)) - qFatal("Could not start the test server"); -} - -void Server::handleNewConnection() -{ - // do one connection at the time - Q_ASSERT(m_data.isEmpty()); - QTcpSocket *socket = m_server.nextPendingConnection(); - Q_ASSERT(socket); - connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); - connect(socket, &QAbstractSocket::readyRead, this, &Server::handleReadReady); -} - -void Server::handleReadReady() -{ - QTcpSocket *socket = qobject_cast(sender()); - Q_ASSERT(socket); - - m_data.append(socket->readAll()); - - //simply wait for whole request - if (!m_data.endsWith("\r\n\r\n")) - return; - - socket->write(m_reply); - m_data.clear(); - socket->disconnectFromHost(); -} diff --git a/tests/auto/quick/dialogs/server.h b/tests/auto/quick/dialogs/server.h deleted file mode 100644 index fa9a73811..000000000 --- a/tests/auto/quick/dialogs/server.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ - -#ifndef SERVER_H -#define SERVER_H - -#include -#include - -class Server : public QObject -{ - Q_OBJECT - -public: - explicit Server(QObject *parent = nullptr); - - bool isListening(); - void setReply(const QByteArray &reply); - -public slots: - void run(); - -private slots: - void handleNewConnection(); - void handleReadReady(); - -private: - QByteArray m_data; - QByteArray m_reply; - QTcpServer m_server; - -}; - -#endif // SERVER_H diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp index 97a39ed01..8543c47da 100644 --- a/tests/auto/quick/dialogs/tst_dialogs.cpp +++ b/tests/auto/quick/dialogs/tst_dialogs.cpp @@ -27,8 +27,8 @@ ****************************************************************************/ #include "testhandler.h" -#include "server.h" -#include "util.h" +#include +#include #include #include @@ -147,7 +147,7 @@ void tst_Dialogs::authenticationDialogRequested_data() QTest::addColumn("url"); QTest::addColumn("type"); QTest::addColumn("realm"); - QTest::addColumn("reply"); + QTest::addColumn("response"); QTest::newRow("Http Authentication Dialog") << QUrl("http://localhost:5555/") << QQuickWebEngineAuthenticationDialogRequest::AuthenticationTypeHTTP << QStringLiteral("Very Restricted Area") @@ -167,12 +167,13 @@ void tst_Dialogs::authenticationDialogRequested() QFETCH(QUrl, url); QFETCH(QQuickWebEngineAuthenticationDialogRequest::AuthenticationType, type); QFETCH(QString, realm); + QFETCH(QByteArray, response); - QFETCH(QByteArray, reply); - Server server; - server.setReply(reply); - server.run(); - QTRY_VERIFY2(server.isListening(), "Could not setup authentication server"); + HttpServer server(QHostAddress::LocalHost, 5555); + connect(&server, &HttpServer::newRequest, [url, response](HttpReqRep *rr) { + rr->sendResponse(response); + }); + QVERIFY(server.start()); QSignalSpy dialogSpy(m_listener, &TestHandler::requestChanged); m_listener->load(url); @@ -186,6 +187,7 @@ void tst_Dialogs::authenticationDialogRequested() QCOMPARE(dialog->realm(),realm); QCOMPARE(dialog->url(), url); QCOMPARE(dialog->proxyHost(), QStringLiteral("localhost")); + QVERIFY(server.stop()); } void tst_Dialogs::javaScriptDialogRequested_data() diff --git a/tests/auto/quick/html/basic_page.html b/tests/auto/quick/html/basic_page.html deleted file mode 100644 index 53726e4a6..000000000 --- a/tests/auto/quick/html/basic_page.html +++ /dev/null @@ -1,6 +0,0 @@ - - - Basic Page - -

Basic page

- diff --git a/tests/auto/quick/html/basic_page2.html b/tests/auto/quick/html/basic_page2.html deleted file mode 100644 index f8cff2969..000000000 --- a/tests/auto/quick/html/basic_page2.html +++ /dev/null @@ -1 +0,0 @@ -

Basic page 2

diff --git a/tests/auto/quick/html/direct-image-compositing.html b/tests/auto/quick/html/direct-image-compositing.html deleted file mode 100644 index 53a4ca137..000000000 --- a/tests/auto/quick/html/direct-image-compositing.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - Testing direct image layer optimization - - - - -

Image optimization in layers

- -

- This test exercises direct compositing of images with hardware acceleration. The visual results - using ACCELERATED_COMPOSITING and regular TOT should be identical. Running this test manually with - the correct debug options will show which elements are directly composited. See - https://bugs.webkit.org/show_bug.cgi?id=23361 -

- -
- - Basic image - no style - can be directly composited -
- -
- - 5px blue border - can NOT be directly composited -
- -
- - margin - can NOT be directly composited -
- -
- - solid background - can be directly composited -
- -
- - background image - can NOT be directly composited -
- -
- - rotated but otherwise no style - can be directly composited -
- - - diff --git a/tests/auto/quick/html/inputmethod.html b/tests/auto/quick/html/inputmethod.html deleted file mode 100644 index dc9140f9d..000000000 --- a/tests/auto/quick/html/inputmethod.html +++ /dev/null @@ -1,11 +0,0 @@ - - -Basic Page For Input Method Testing - - -

Basic page

- - -
- - diff --git a/tests/auto/quick/html/resources/simple_image.png b/tests/auto/quick/html/resources/simple_image.png deleted file mode 100644 index 4685399ca..000000000 Binary files a/tests/auto/quick/html/resources/simple_image.png and /dev/null differ diff --git a/tests/auto/quick/html/scroll.html b/tests/auto/quick/html/scroll.html deleted file mode 100644 index ce2193b6c..000000000 --- a/tests/auto/quick/html/scroll.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - -Scroll test - - -
-
- - diff --git a/tests/auto/quick/inspectorserver/CMakeLists.txt b/tests/auto/quick/inspectorserver/CMakeLists.txt new file mode 100644 index 000000000..e2c3bb2ab --- /dev/null +++ b/tests/auto/quick/inspectorserver/CMakeLists.txt @@ -0,0 +1,9 @@ +qt_internal_add_test(tst_inspectorserver + SOURCES + tst_inspectorserver.cpp + LIBRARIES + Qt::CorePrivate + Qt::WebEngineQuickPrivate +) + + diff --git a/tests/auto/quick/inspectorserver/html/basic_page.html b/tests/auto/quick/inspectorserver/html/basic_page.html new file mode 100644 index 000000000..53726e4a6 --- /dev/null +++ b/tests/auto/quick/inspectorserver/html/basic_page.html @@ -0,0 +1,6 @@ + + + Basic Page + +

Basic page

+ diff --git a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp index bc5aed9ef..de49f143c 100644 --- a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp +++ b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp @@ -70,8 +70,6 @@ tst_InspectorServer::tst_InspectorServer() void tst_InspectorServer::prepareWebViewComponent() { static QQmlEngine* engine = new QQmlEngine(this); - engine->addImportPath(QString::fromUtf8(IMPORT_DIR)); - m_component.reset(new QQmlComponent(engine, this)); m_component->setData(QByteArrayLiteral("import QtQuick 2.0\n" @@ -119,7 +117,8 @@ QJsonArray tst_InspectorServer::fetchPageList() const void tst_InspectorServer::testPageList() { - const QUrl testPageUrl = QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")); + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadRequest))); webView()->setUrl(testPageUrl); QTRY_VERIFY(loadSpy.size() && !webView()->isLoading()); @@ -132,7 +131,8 @@ void tst_InspectorServer::testPageList() void tst_InspectorServer::testRemoteDebuggingMessage() { - const QUrl testPageUrl = QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")); + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadRequest))); webView()->setUrl(testPageUrl); QTRY_VERIFY(loadSpy.size() && !webView()->isLoading()); @@ -166,7 +166,8 @@ void tst_InspectorServer::testRemoteDebuggingMessage() void tst_InspectorServer::openRemoteDebuggingSession() { - const QUrl testPageUrl = QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")); + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadRequest))); webView()->setUrl(testPageUrl); QTRY_VERIFY(loadSpy.size() && !webView()->isLoading()); diff --git a/tests/auto/quick/publicapi/CMakeLists.txt b/tests/auto/quick/publicapi/CMakeLists.txt new file mode 100644 index 000000000..abed54a10 --- /dev/null +++ b/tests/auto/quick/publicapi/CMakeLists.txt @@ -0,0 +1,8 @@ +qt_internal_add_test(tst_publicapi + SOURCES + tst_publicapi.cpp + LIBRARIES + Qt::CorePrivate + Qt::WebEngineQuickPrivate + Qt::WebEngineWidgetsPrivate +) diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt new file mode 100644 index 000000000..9aa4ca76c --- /dev/null +++ b/tests/auto/quick/qmltests/CMakeLists.txt @@ -0,0 +1,102 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_qmltests + SOURCES + tst_qmltests.cpp + LIBRARIES + Qt::WebEngineQuick + Qt::QuickTest + Test::HttpServer + Test::Util +) + +set(testList + tst_action.qml + tst_activeFocusOnPress.qml + tst_audioMuted.qml + tst_desktopBehaviorLoadHtml.qml + tst_findText.qml + tst_focusOnNavigation.qml + tst_fullScreenRequest.qml + tst_geopermission.qml + tst_getUserMedia.qml + tst_keyboardEvents.qml + tst_keyboardModifierMapping.qml + tst_loadHtml.qml + tst_loadProgress.qml + tst_loadRecursionCrash.qml + tst_loadUrl.qml + tst_mouseMove.qml + tst_navigationRequested.qml + tst_newViewRequest.qml + tst_notification.qml + tst_profile.qml + tst_properties.qml + tst_runJavaScript.qml + tst_scrollPosition.qml + tst_settings.qml + tst_titleChanged.qml + tst_unhandledKeyEventPropagation.qml + tst_userScripts.qml + tst_viewSource.qml +) + +if(QT_FEATURE_webengine_webchannel) + list(APPEND testList tst_webchannel.qml) +endif() + +if(QT_FEATURE_ssl) + list(APPEND testList tst_certificateError.qml) +endif() + +if(QT_FEATURE_webengine_testsupport) + list(APPEND testList + tst_favicon.qml + tst_faviconDownload.qml + tst_inputMethod.qml + tst_linkHovered.qml + tst_loadFail.qml + tst_mouseClick.qml + tst_viewSoure.qml + ) +# if(TARGET Qt::QuickControls) #FIXME + list(APPEND testList tst_javaScriptDialogs.qml) +# else() +# message("\n!!! QuickControls target is missing, some tests are not executed !!! FIXME \n") +# endif() +endif() + +if(TARGET Qt::QuickControls) #FIXME + list(APPEND testList + tst_contextMenu.qml + tst_download.qml + tst_filePicker.qml + ) +else() + message("\n!!!! QuickControls target is missing, some tests are not executed !!! FIXME \n") +endif() + +if(TARGET Qt::QuickControls2) + list(APPEND testList tst_navigationHistory.qml) +else() + message("\n!!!! QuickControls2 target is missing, some tests are not executed !!! FIXME \n") +endif() + +set(content "") +foreach(test ${testList}) + set(contents "${contents}${CMAKE_CURRENT_LIST_DIR}/data/${test}\n") +endforeach() +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/webengine.qmltests ${contents}) + +set(tst_qmltests_resource_files + "resources/cert.pem" + "resources/key.pem" +) + +qt_internal_add_resource(tst_qmltests "tst_qmltests" + PREFIX + "/" + FILES + ${tst_qmltests_resource_files} +) diff --git a/tests/auto/quick/qmltests/data/tst_notification.qml b/tests/auto/quick/qmltests/data/tst_notification.qml index 773bf4a8e..6f66256f2 100644 --- a/tests/auto/quick/qmltests/data/tst_notification.qml +++ b/tests/auto/quick/qmltests/data/tst_notification.qml @@ -29,6 +29,7 @@ import QtQuick 2.2 import QtTest 1.0 import QtWebEngine 1.9 +import Test.Shared 1.0 as Shared TestWebEngineView { id: view @@ -60,7 +61,8 @@ TestWebEngineView { when: windowShown function resolverUrl(html) { - return Qt.resolvedUrl('../../../shared/data/' + html) + console.log(Shared.HttpServer.sharedDataDir()) + return Qt.resolvedUrl(Shared.HttpServer.sharedDataDir() + "/" + html) } function init() { diff --git a/tests/auto/quick/qmltests/resources/cert.pem b/tests/auto/quick/qmltests/resources/cert.pem new file mode 100644 index 000000000..3aaaf289c --- /dev/null +++ b/tests/auto/quick/qmltests/resources/cert.pem @@ -0,0 +1,64 @@ +-----BEGIN CERTIFICATE----- +MIIEpDCCAoygAwIBAgIUO90aty9AMjvBvzfUhr1WwdBrKkMwDQYJKoZIhvcNAQEL +BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM +DVNhbiBGcmFuY2lzY28xDzANBgNVBAoMBkJhZFNTTDEyMDAGA1UEAwwpQmFkU1NM +IEludGVybWVkaW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xTp902ozNnZaSk2DxAUqcsOD4 +ago0IhRdkFGe1Q7F8gOxtlUL5owNL4uhRP8BbwOja2Gopn2+kA9CNqdwPI4Ipjlr +yo61oCqzy3RAXOUct8WAvybacADmJODAxDq9O5fAZuYZScjjj1ASowmbyDH/Wb9z ++WfiKKH4BfgOIukzK3I1M9wiSDefIodCFfEVXbdNudZj8f9Gw4RrZwkUuxDLeRWG +ReDtzAWq7G0Diw3uX40S4jaj3MeS6oHp2Nrj/VyjSRiYTeN/pnA9N0M5VuCYYvXD +f50rrigjQfOgb4TmnyJAjXWVkXW7Fa+ooLsbvlfr8wP8f31y1cgWPHTVIv6Kmug7 +Bg88k3x5gLTXmutDjseORonhGMRdAxHgJVf5aKfzdRpwXZTDZJXhsAz9OdlOhNZd +UrYo680QugA0V3H5D8Egbr2AUUSMDkn133COjeOIDknFxX3qDqeTzqLZCAEBIoKn +Adpix0jvG1Ys4Ayq6K2wQFdGFjtl6LsiGC7pWWU= +-----END CERTIFICATE----- diff --git a/tests/auto/quick/qmltests/resources/key.pem b/tests/auto/quick/qmltests/resources/key.pem new file mode 100644 index 000000000..89922679a --- /dev/null +++ b/tests/auto/quick/qmltests/resources/key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAkybT/L4zJCqefpd+eYT6aQ0PtobQfFgP+n+z5wWoUxIAJnjb +5ZW47IJxka/2/ggzJOfrUBur54LkTfFQ+yX85eKYCuH0GLz+Rve50LDn0ya6qSgm +EhDG0bend2tMZY+Nl3B+5Ane1vua8hdJjv3ZO3e5UgpQwysL54eYyhEWWlbFWF11 +LhEdMYp953UGLqoV4Mlw+Li8TmFwdKQx6icgBTuloXLzk9aUU+b6NbXdadNXkmzg +09ICsb8pnMXiF2P9Xm5rK0IoiRkSHxVnU12nQXh65Ns/2Dj5DcbHmVdvallfr4wn +LeFPUotysZnvFmE7FLMSr/eQfkTG+Jlb7ZhoGwIDAQABAoIBADRXy3BL98UVo+tD +2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e5xrzY2DL8epVKb1qf6+8SE +eX34cIcSaonEZ2g67MAeIG6jtmPwxWk4EYAsO1u4XiyziABkoNyLKVH4hZg61BsV +jL7R5UrUvBbhKLFOwkcB4Kwdwu7COB/UKa5XJBTMbuw1UTyxlUeI +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/quick/qmltests/tst_qmltests.cpp b/tests/auto/quick/qmltests/tst_qmltests.cpp index 906de29ad..2cf811f91 100644 --- a/tests/auto/quick/qmltests/tst_qmltests.cpp +++ b/tests/auto/quick/qmltests/tst_qmltests.cpp @@ -36,8 +36,8 @@ #include #include #include -#include -#include "qt_webengine_quicktest.h" +#include +#include #if defined(Q_OS_LINUX) && defined(QT_DEBUG) #include @@ -151,17 +151,19 @@ int main(int argc, char **argv) QTEST_SET_MAIN_SOURCE_PATH qmlRegisterSingletonType("Test.Shared", 1, 0, "HttpServer", [&] (QQmlEngine *, QJSEngine *) { auto server = new HttpServer; - server->setResourceDirs({ TESTS_SHARED_DATA_DIR, QUICK_TEST_SOURCE_DIR }); + server->setResourceDirs( + { server->sharedDataDir(), + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + QLatin1String("/data") }); return server; }); #if QT_CONFIG(ssl) qmlRegisterSingletonType( "Test.Shared", 1, 0, "HttpsServer", - [&](QQmlEngine *, QJSEngine *) { return new HttpsServer; }); + [&](QQmlEngine *, QJSEngine *) { return new HttpsServer(":/resources/cert.pem",":/resources/key.pem"); }); #endif - int i = quick_test_main(argc, argv, "qmltests", QUICK_TEST_SOURCE_DIR); + int i = quick_test_main(argc, argv, "qmltests", qPrintable(QT_TESTCASE_BUILDDIR + QLatin1String("/webengine.qmltests"))); return i; } diff --git a/tests/auto/quick/qquickwebenginedefaultsurfaceformat/CMakeLists.txt b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/CMakeLists.txt new file mode 100644 index 000000000..07b184b89 --- /dev/null +++ b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/CMakeLists.txt @@ -0,0 +1,10 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_qquickwebenginedefaultsurfaceformat + SOURCES + tst_qquickwebenginedefaultsurfaceformat.cpp + LIBRARIES + Qt::CorePrivate + Qt::WebEngineQuickPrivate + Test::Util +) diff --git a/tests/auto/quick/qquickwebenginedefaultsurfaceformat/html/basic_page.html b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/html/basic_page.html new file mode 100644 index 000000000..53726e4a6 --- /dev/null +++ b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/html/basic_page.html @@ -0,0 +1,6 @@ + + + Basic Page + +

Basic page

+ diff --git a/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp index 016e8232f..4275ae971 100644 --- a/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp +++ b/tests/auto/quick/qquickwebenginedefaultsurfaceformat/tst_qquickwebenginedefaultsurfaceformat.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include "testwindow.h" -#include "util.h" +#include "quickutil.h" #include #include @@ -93,7 +93,7 @@ inline QQuickWebEngineView *tst_QQuickWebEngineDefaultSurfaceFormat::webEngineVi QUrl tst_QQuickWebEngineDefaultSurfaceFormat::urlFromTestPath(const char *localFilePath) { - QString testSourceDirPath = QString::fromLocal8Bit(TESTS_SOURCE_DIR); + QString testSourceDirPath = QDir(QT_TESTCASE_SOURCEDIR).canonicalPath(); if (!testSourceDirPath.endsWith(QLatin1Char('/'))) testSourceDirPath.append(QLatin1Char('/')); diff --git a/tests/auto/quick/qquickwebengineview/CMakeLists.txt b/tests/auto/quick/qquickwebengineview/CMakeLists.txt new file mode 100644 index 000000000..45c44034a --- /dev/null +++ b/tests/auto/quick/qquickwebengineview/CMakeLists.txt @@ -0,0 +1,13 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_qquickwebengineview + SOURCES + tst_qquickwebengineview.cpp + LIBRARIES + Qt::WebEngineCorePrivate + Qt::WebEngineWidgets + Qt::WebEngineQuick + Qt::GuiPrivate + Qt::WebEngineQuickPrivate + Test::Util +) diff --git a/tests/auto/quick/qquickwebengineview/html/basic_page.html b/tests/auto/quick/qquickwebengineview/html/basic_page.html new file mode 100644 index 000000000..53726e4a6 --- /dev/null +++ b/tests/auto/quick/qquickwebengineview/html/basic_page.html @@ -0,0 +1,6 @@ + + + Basic Page + +

Basic page

+ diff --git a/tests/auto/quick/qquickwebengineview/html/basic_page2.html b/tests/auto/quick/qquickwebengineview/html/basic_page2.html new file mode 100644 index 000000000..f8cff2969 --- /dev/null +++ b/tests/auto/quick/qquickwebengineview/html/basic_page2.html @@ -0,0 +1 @@ +

Basic page 2

diff --git a/tests/auto/quick/qquickwebengineview/html/direct-image-compositing.html b/tests/auto/quick/qquickwebengineview/html/direct-image-compositing.html new file mode 100644 index 000000000..53a4ca137 --- /dev/null +++ b/tests/auto/quick/qquickwebengineview/html/direct-image-compositing.html @@ -0,0 +1,66 @@ + + + + + + Testing direct image layer optimization + + + + +

Image optimization in layers

+ +

+ This test exercises direct compositing of images with hardware acceleration. The visual results + using ACCELERATED_COMPOSITING and regular TOT should be identical. Running this test manually with + the correct debug options will show which elements are directly composited. See + https://bugs.webkit.org/show_bug.cgi?id=23361 +

+ +
+ + Basic image - no style - can be directly composited +
+ +
+ + 5px blue border - can NOT be directly composited +
+ +
+ + margin - can NOT be directly composited +
+ +
+ + solid background - can be directly composited +
+ +
+ + background image - can NOT be directly composited +
+ +
+ + rotated but otherwise no style - can be directly composited +
+ + + diff --git a/tests/auto/quick/qquickwebengineview/html/inputmethod.html b/tests/auto/quick/qquickwebengineview/html/inputmethod.html new file mode 100644 index 000000000..dc9140f9d --- /dev/null +++ b/tests/auto/quick/qquickwebengineview/html/inputmethod.html @@ -0,0 +1,11 @@ + + +Basic Page For Input Method Testing + + +

Basic page

+ + +
+ + diff --git a/tests/auto/quick/qquickwebengineview/html/resources/simple_image.png b/tests/auto/quick/qquickwebengineview/html/resources/simple_image.png new file mode 100644 index 000000000..4685399ca Binary files /dev/null and b/tests/auto/quick/qquickwebengineview/html/resources/simple_image.png differ diff --git a/tests/auto/quick/qquickwebengineview/html/scroll.html b/tests/auto/quick/qquickwebengineview/html/scroll.html new file mode 100644 index 000000000..ce2193b6c --- /dev/null +++ b/tests/auto/quick/qquickwebengineview/html/scroll.html @@ -0,0 +1,29 @@ + + + + + + + +Scroll test + + +
+
+ + diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 30441ac11..d0df5ffe0 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include "testwindow.h" -#include "util.h" +#include "quickutil.h" #include #include @@ -111,7 +111,7 @@ tst_QQuickWebEngineView::tst_QQuickWebEngineView() QtWebEngine::initialize(); QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); - m_testSourceDirPath = QString::fromLocal8Bit(TESTS_SOURCE_DIR); + m_testSourceDirPath = QDir(QT_TESTCASE_SOURCEDIR).canonicalPath(); if (!m_testSourceDirPath.endsWith(QLatin1Char('/'))) m_testSourceDirPath.append(QLatin1Char('/')); @@ -1252,3 +1252,4 @@ static QByteArrayList params = QByteArrayList() W_QTEST_MAIN(tst_QQuickWebEngineView, params) #include "tst_qquickwebengineview.moc" +#include "moc_quickutil.cpp" diff --git a/tests/auto/quick/qtbug-70248/CMakeLists.txt b/tests/auto/quick/qtbug-70248/CMakeLists.txt new file mode 100644 index 000000000..cc6f120b0 --- /dev/null +++ b/tests/auto/quick/qtbug-70248/CMakeLists.txt @@ -0,0 +1,17 @@ +qt_internal_add_test(tst_qtbug-70248 + SOURCES + tst_qtbug-70248.cpp + LIBRARIES + Qt::WebEngineQuickPrivate +) + +set(test_resource_files + "test.qml" +) + +qt_add_resource(tst_qtbug-70248 "test" + PREFIX + "/" + FILES + ${test_resource_files} +) diff --git a/tests/auto/quick/shared/qt_webengine_quicktest.h b/tests/auto/quick/shared/qt_webengine_quicktest.h deleted file mode 100644 index 3adc9d459..000000000 --- a/tests/auto/quick/shared/qt_webengine_quicktest.h +++ /dev/null @@ -1,57 +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: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$ -** -****************************************************************************/ - -#ifndef QT_WEBENGINE_QUICKTEST_H -#define QT_WEBENGINE_QUICKTEST_H - -#include - -#ifdef QT_WIDGETS_LIB -#include -#else -#include -#endif - -#include "qopenglcontext.h" -#include - -QT_BEGIN_NAMESPACE - -#ifndef QUICK_TEST_SOURCE_DIR -#define QUICK_TEST_SOURCE_DIR 0 -#endif - -#ifdef QT_WIDGETS_LIB -#define Application QApplication -#else -#define Application QGuiApplication -#endif - -QT_END_NAMESPACE - -#endif // QT_WEBENGINE_QUICKTEST_H diff --git a/tests/auto/quick/shared/testwindow.h b/tests/auto/quick/shared/testwindow.h deleted file mode 100644 index b57443c69..000000000 --- a/tests/auto/quick/shared/testwindow.h +++ /dev/null @@ -1,68 +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: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$ -** -****************************************************************************/ - -#ifndef TESTWINDOW_H -#define TESTWINDOW_H - -#if 0 -#pragma qt_no_master_include -#endif - -#include -#include -#include -#include - -// TestWindow: Utility class to ignore QQuickView details. -class TestWindow : public QQuickView { -public: - inline TestWindow(QQuickItem *webEngineView); - QScopedPointer webEngineView; - -protected: - inline void resizeEvent(QResizeEvent*); -}; - -inline TestWindow::TestWindow(QQuickItem *webEngineView) - : webEngineView(webEngineView) -{ - Q_ASSERT(webEngineView); - webEngineView->setParentItem(contentItem()); - resize(300, 400); -} - -inline void TestWindow::resizeEvent(QResizeEvent *event) -{ - QQuickView::resizeEvent(event); - webEngineView->setX(0); - webEngineView->setY(0); - webEngineView->setWidth(event->size().width()); - webEngineView->setHeight(event->size().height()); -} - -#endif /* TESTWINDOW_H */ diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h deleted file mode 100644 index 34afbbb45..000000000 --- a/tests/auto/quick/shared/util.h +++ /dev/null @@ -1,191 +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: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$ -** -****************************************************************************/ - -#ifndef UTIL_H -#define UTIL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if !defined(TESTS_SOURCE_DIR) -#define TESTS_SOURCE_DIR "" -#endif - -class LoadSpy : public QEventLoop { - Q_OBJECT - -public: - LoadSpy(QQuickWebEngineView *webEngineView) - { - connect(webEngineView, &QQuickWebEngineView::loadingChanged, this, &LoadSpy::onLoadingChanged); - } - - ~LoadSpy() { } - -Q_SIGNALS: - void loadSucceeded(); - void loadFailed(); - -private Q_SLOTS: - void onLoadingChanged(const QWebEngineLoadRequest &request) - { - if (request.status() == QWebEngineLoadRequest::LoadSucceededStatus) - emit loadSucceeded(); - else if (request.status() == QWebEngineLoadRequest::LoadFailedStatus) - emit loadFailed(); - } -}; - -class LoadStartedCatcher : public QObject { - Q_OBJECT - -public: - LoadStartedCatcher(QQuickWebEngineView *webEngineView) - : m_webEngineView(webEngineView) - { - connect(m_webEngineView, &QQuickWebEngineView::loadingChanged, this, &LoadStartedCatcher::onLoadingChanged); - } - - virtual ~LoadStartedCatcher() { } - -public Q_SLOTS: - void onLoadingChanged(const QWebEngineLoadRequest &request) - { - if (request.status() == QWebEngineLoadRequest::LoadStartedStatus) - QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); - } - -Q_SIGNALS: - void finished(); - -private: - QQuickWebEngineView *m_webEngineView; -}; - -inline bool waitForLoadSucceeded(QQuickWebEngineView *webEngineView, int timeout = 10000) -{ - LoadSpy loadSpy(webEngineView); - QSignalSpy spy(&loadSpy, &LoadSpy::loadSucceeded); - return spy.wait(timeout); -} - -inline bool waitForLoadFailed(QQuickWebEngineView *webEngineView, int timeout = 20000) -{ - LoadSpy loadSpy(webEngineView); - QSignalSpy spy(&loadSpy, &LoadSpy::loadFailed); - return spy.wait(timeout); -} - -inline QVariant evaluateJavaScriptSync(QQuickWebEngineView *view, const QString &script) -{ - QQmlEngine *engine = qmlEngine(view); - engine->globalObject().setProperty("called", false); - engine->globalObject().setProperty("result", QJSValue()); - QJSValue callback = engine->evaluate( - "(function callback(r) {" - " called = true;" - " result = r;" - "})" - ); - view->runJavaScript(script, callback); - QTRY_LOOP_IMPL(engine->globalObject().property("called").toBool(), 5000, 50); - if (!engine->globalObject().property("called").toBool()) { - qWarning("JavaScript wasn't evaluated"); - return QVariant(); - } - - return engine->globalObject().property("result").toVariant(); -} - -inline QPoint elementCenter(QQuickWebEngineView *view, const QString &id) -{ - const QString jsCode( - "(function(){" - " var elem = document.getElementById('" + id + "');" - " var rect = elem.getBoundingClientRect();" - " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" - "})()"); - QVariantList rectList = evaluateJavaScriptSync(view, jsCode).toList(); - - if (rectList.count() != 2) { - qWarning("elementCenter failed."); - return QPoint(); - } - - return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); -} - -inline QString activeElementId(QQuickWebEngineView *webEngineView) -{ - qRegisterMetaType("JavaScriptConsoleMessageLevel"); - QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage); - - webEngineView->runJavaScript( - "if (document.activeElement == null)" - " console.log('');" - "else" - " console.log(document.activeElement.id);" - ); - - if (!consoleMessageSpy.wait()) - return QString(); - - QList arguments = consoleMessageSpy.takeFirst(); - if (static_cast(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel) - return QString(); - - return arguments.at(1).toString(); -} - -#define W_QTEST_MAIN(TestObject, params) \ -int main(int argc, char *argv[]) \ -{ \ - QtWebEngine::initialize(); \ - \ - QList w_argv(argc); \ - for (int i = 0; i < argc; ++i) \ - w_argv[i] = argv[i]; \ - for (int i = 0; i < params.size(); ++i) \ - w_argv.append(params[i].data()); \ - int w_argc = w_argv.size(); \ - \ - QGuiApplication app(w_argc, const_cast(w_argv.data())); \ - app.setAttribute(Qt::AA_Use96Dpi, true); \ - TestObject tc; \ - QTEST_SET_MAIN_SOURCE_PATH \ - return QTest::qExec(&tc, argc, argv); \ -} -#endif /* UTIL_H */ - diff --git a/tests/auto/shared/data/loadprogress/downloadable.tar.gz b/tests/auto/shared/data/loadprogress/downloadable.tar.gz deleted file mode 100644 index 741cb8ca6..000000000 Binary files a/tests/auto/shared/data/loadprogress/downloadable.tar.gz and /dev/null differ diff --git a/tests/auto/shared/data/loadprogress/main.html b/tests/auto/shared/data/loadprogress/main.html deleted file mode 100644 index 3b7d2034b..000000000 --- a/tests/auto/shared/data/loadprogress/main.html +++ /dev/null @@ -1,30 +0,0 @@ - -Load Progress Test Page - - page1 - - - -

Hello.

- -

body in monospace

- - - - - - diff --git a/tests/auto/shared/data/loadprogress/page1.html b/tests/auto/shared/data/loadprogress/page1.html deleted file mode 100644 index 9b11ce887..000000000 --- a/tests/auto/shared/data/loadprogress/page1.html +++ /dev/null @@ -1,8 +0,0 @@ - - - page1 - - - - - diff --git a/tests/auto/shared/data/loadprogress/page2.html b/tests/auto/shared/data/loadprogress/page2.html deleted file mode 100644 index 223817c8c..000000000 --- a/tests/auto/shared/data/loadprogress/page2.html +++ /dev/null @@ -1,15 +0,0 @@ - - - page2 - - - - -
page2 anchor
- - diff --git a/tests/auto/shared/data/loadprogress/page3.html b/tests/auto/shared/data/loadprogress/page3.html deleted file mode 100644 index d38ca31f0..000000000 --- a/tests/auto/shared/data/loadprogress/page3.html +++ /dev/null @@ -1,20 +0,0 @@ - - - page3 - - - - - -
page3 anchor
- - diff --git a/tests/auto/shared/data/loadprogress/page4.html b/tests/auto/shared/data/loadprogress/page4.html deleted file mode 100644 index 61976b4fb..000000000 --- a/tests/auto/shared/data/loadprogress/page4.html +++ /dev/null @@ -1,8 +0,0 @@ - - - page4 - - - download - - diff --git a/tests/auto/shared/data/loadprogress/page5.html b/tests/auto/shared/data/loadprogress/page5.html deleted file mode 100644 index 47709ff08..000000000 --- a/tests/auto/shared/data/loadprogress/page5.html +++ /dev/null @@ -1,20 +0,0 @@ - - - page5 - - - - - -
here is the anchor
- - diff --git a/tests/auto/shared/data/loadprogress/page6.html b/tests/auto/shared/data/loadprogress/page6.html deleted file mode 100644 index 98042701a..000000000 --- a/tests/auto/shared/data/loadprogress/page6.html +++ /dev/null @@ -1,13 +0,0 @@ - - - page6 - - - - - - diff --git a/tests/auto/shared/data/loadprogress/page7.html b/tests/auto/shared/data/loadprogress/page7.html deleted file mode 100644 index 42538c5de..000000000 --- a/tests/auto/shared/data/loadprogress/page7.html +++ /dev/null @@ -1,13 +0,0 @@ - - - page6 - - - - - - diff --git a/tests/auto/shared/data/loadprogress/page8.html b/tests/auto/shared/data/loadprogress/page8.html deleted file mode 100644 index 8ebdddf97..000000000 --- a/tests/auto/shared/data/loadprogress/page8.html +++ /dev/null @@ -1,20 +0,0 @@ - - - Page with js navigation in the end of document to anchor within the page - - - - -
here is the anchor
- - - diff --git a/tests/auto/shared/data/notification.html b/tests/auto/shared/data/notification.html deleted file mode 100644 index 1d1e9c411..000000000 --- a/tests/auto/shared/data/notification.html +++ /dev/null @@ -1,70 +0,0 @@ - - - -Desktop Notifications Demo - - - -
- Title:
- Body:
-
- -
-
- - diff --git a/tests/auto/shared/httpreqrep.cpp b/tests/auto/shared/httpreqrep.cpp deleted file mode 100644 index 96279bbc0..000000000 --- a/tests/auto/shared/httpreqrep.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include "httpreqrep.h" - -HttpReqRep::HttpReqRep(QTcpSocket *socket, QObject *parent) - : QObject(parent), m_socket(socket) -{ - m_socket->setParent(this); - connect(m_socket, &QTcpSocket::readyRead, this, &HttpReqRep::handleReadyRead); - connect(m_socket, &QTcpSocket::disconnected, this, &HttpReqRep::handleDisconnected); -} - -void HttpReqRep::sendResponse(int statusCode) -{ - if (m_state != State::REQUEST_RECEIVED) - return; - m_responseStatusCode = statusCode; - m_socket->write("HTTP/1.1 "); - m_socket->write(QByteArray::number(m_responseStatusCode)); - m_socket->write(" OK?\r\n"); - for (const auto & kv : m_responseHeaders) { - m_socket->write(kv.first); - m_socket->write(": "); - m_socket->write(kv.second); - m_socket->write("\r\n"); - } - m_socket->write("Connection: close\r\n"); - m_socket->write("\r\n"); - m_socket->write(m_responseBody); - m_state = State::DISCONNECTING; - m_socket->disconnectFromHost(); - Q_EMIT responseSent(); -} - -void HttpReqRep::close() -{ - if (m_state != State::REQUEST_RECEIVED) - return; - m_state = State::DISCONNECTING; - m_socket->disconnectFromHost(); - Q_EMIT error(QStringLiteral("missing response")); -} - -QByteArray HttpReqRep::requestHeader(const QByteArray &key) const -{ - auto it = m_requestHeaders.find(key.toLower()); - if (it != m_requestHeaders.end()) - return it->second; - return {}; -} - -void HttpReqRep::handleReadyRead() -{ - while (m_socket->canReadLine()) { - switch (m_state) { - case State::RECEIVING_REQUEST: { - const auto requestLine = m_socket->readLine(); - const auto requestLineParts = requestLine.split(' '); - if (requestLineParts.size() != 3 || !requestLineParts[2].toUpper().startsWith("HTTP/")) { - m_state = State::DISCONNECTING; - m_socket->disconnectFromHost(); - Q_EMIT error(QStringLiteral("invalid request line")); - return; - } - m_requestMethod = requestLineParts[0]; - m_requestPath = requestLineParts[1]; - m_state = State::RECEIVING_HEADERS; - break; - } - case State::RECEIVING_HEADERS: { - const auto headerLine = m_socket->readLine(); - if (headerLine == QByteArrayLiteral("\r\n")) { - m_state = State::REQUEST_RECEIVED; - Q_EMIT requestReceived(); - return; - } - int colonIndex = headerLine.indexOf(':'); - if (colonIndex < 0) { - m_state = State::DISCONNECTING; - m_socket->disconnectFromHost(); - Q_EMIT error(QStringLiteral("invalid header line")); - return; - } - auto headerKey = headerLine.left(colonIndex).trimmed().toLower(); - auto headerValue = headerLine.mid(colonIndex + 1).trimmed().toLower(); - m_requestHeaders.emplace(headerKey, headerValue); - break; - } - default: - return; - } - } -} - -void HttpReqRep::handleDisconnected() -{ - switch (m_state) { - case State::RECEIVING_REQUEST: - case State::RECEIVING_HEADERS: - case State::REQUEST_RECEIVED: - Q_EMIT error(QStringLiteral("unexpected disconnect")); - break; - case State::DISCONNECTING: - break; - case State::DISCONNECTED: - Q_UNREACHABLE(); - } - m_state = State::DISCONNECTED; - Q_EMIT closed(); -} diff --git a/tests/auto/shared/httpreqrep.h b/tests/auto/shared/httpreqrep.h deleted file mode 100644 index 84ada0160..000000000 --- a/tests/auto/shared/httpreqrep.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#ifndef HTTPREQREP_H -#define HTTPREQREP_H - -#include - -#include -#include - -// Represents an HTTP request-response exchange. -class HttpReqRep : public QObject -{ - Q_OBJECT -public: - explicit HttpReqRep(QTcpSocket *socket, QObject *parent = nullptr); - - Q_INVOKABLE void sendResponse(int statusCode = 200); - void close(); - bool isClosed() const { return m_state == State::DISCONNECTED; } - - // Request parameters (only valid after requestReceived()) - - QByteArray requestMethod() const { return m_requestMethod; } - QByteArray requestPath() const { return m_requestPath; } - QByteArray requestHeader(const QByteArray &key) const; - - // Response parameters (can be set until sendResponse()/close()). - - int responseStatus() const { return m_responseStatusCode; } - void setResponseStatus(int statusCode) - { - m_responseStatusCode = statusCode; - } - void setResponseHeader(const QByteArray &key, QByteArray value) - { - m_responseHeaders[key.toLower()] = std::move(value); - } - QByteArray responseBody() const { return m_responseBody; } - Q_INVOKABLE void setResponseBody(QByteArray content) - { - m_responseHeaders["content-length"] = QByteArray::number(content.size()); - m_responseBody = std::move(content); - } - -Q_SIGNALS: - // Emitted when the request has been correctly parsed. - void requestReceived(); - // Emitted on first call to sendResponse(). - void responseSent(); - // Emitted when something goes wrong. - void error(const QString &error); - // Emitted during or some time after sendResponse() or close(). - void closed(); - -private Q_SLOTS: - void handleReadyRead(); - void handleDisconnected(); - -private: - enum class State { - // Waiting for first line of request. - RECEIVING_REQUEST, // Next: RECEIVING_HEADERS or DISCONNECTING. - // Waiting for header lines. - RECEIVING_HEADERS, // Next: REQUEST_RECEIVED or DISCONNECTING. - // Request parsing succeeded, waiting for sendResponse() or close(). - REQUEST_RECEIVED, // Next: DISCONNECTING. - // Waiting for network. - DISCONNECTING, // Next: DISCONNECTED. - // Connection is dead. - DISCONNECTED, // Next: - - }; - QTcpSocket *m_socket = nullptr; - State m_state = State::RECEIVING_REQUEST; - QByteArray m_requestMethod; - QByteArray m_requestPath; - std::map m_requestHeaders; - int m_responseStatusCode = -1; - std::map m_responseHeaders; - QByteArray m_responseBody; -}; - -#endif // !HTTPREQREP_H diff --git a/tests/auto/shared/httpserver.cpp b/tests/auto/shared/httpserver.cpp deleted file mode 100644 index 69e8cb6cc..000000000 --- a/tests/auto/shared/httpserver.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include "httpserver.h" - -#include -#include -#include - -Q_LOGGING_CATEGORY(gHttpServerLog, "HttpServer") - -HttpServer::HttpServer(QObject *parent) : HttpServer(new QTcpServer, "http", parent) -{ -} - -HttpServer::HttpServer(QTcpServer *tcpServer, const QString &protocol, QObject *parent) - : QObject(parent), m_tcpServer(tcpServer) -{ - m_url.setHost(QStringLiteral("127.0.0.1")); - m_url.setScheme(protocol); - connect(tcpServer, &QTcpServer::newConnection, this, &HttpServer::handleNewConnection); -} - -HttpServer::~HttpServer() -{ - delete m_tcpServer; -} - -bool HttpServer::start() -{ - m_error = false; - m_expectingError = false; - m_ignoreNewConnection = false; - - if (!m_tcpServer->listen()) { - qCWarning(gHttpServerLog).noquote() << m_tcpServer->errorString(); - return false; - } - - m_url.setPort(m_tcpServer->serverPort()); - return true; -} - -bool HttpServer::stop() -{ - m_tcpServer->close(); - return m_error == m_expectingError; -} - -void HttpServer::setExpectError(bool b) -{ - m_expectingError = b; -} - -QUrl HttpServer::url(const QString &path) const -{ - auto copy = m_url; - copy.setPath(path); - return copy; -} - -void HttpServer::handleNewConnection() -{ - if (m_ignoreNewConnection) - return; - - auto rr = new HttpReqRep(m_tcpServer->nextPendingConnection(), this); - connect(rr, &HttpReqRep::requestReceived, [this, rr]() { - Q_EMIT newRequest(rr); - if (rr->isClosed()) // was explicitly answered - return; - - // if request wasn't handled or purposely ignored for default behavior - // then try to serve htmls from resources dirs if set - if (rr->requestMethod() == "GET") { - for (auto &&dir : qAsConst(m_dirs)) { - QFile f(dir + rr->requestPath()); - if (f.exists()) { - if (f.open(QFile::ReadOnly)) { - QMimeType mime = QMimeDatabase().mimeTypeForFileNameAndData(f.fileName(), &f); - rr->setResponseHeader(QByteArrayLiteral("Content-Type"), mime.name().toUtf8()); - rr->setResponseBody(f.readAll()); - rr->sendResponse(); - } else { - qWarning() << "Can't open resource" << f.fileName() << ": " << f.errorString(); - rr->sendResponse(500); // internal server error - } - break; - } - } - } - - if (!rr->isClosed()) - rr->sendResponse(404); - }); - connect(rr, &HttpReqRep::responseSent, [rr]() { - qCInfo(gHttpServerLog).noquote() << rr->requestMethod() << rr->requestPath() - << rr->responseStatus() << rr->responseBody().size(); - }); - connect(rr, &HttpReqRep::error, [this, rr](const QString &error) { - qCWarning(gHttpServerLog).noquote() << rr->requestMethod() << rr->requestPath() - << error; - m_error = true; - }); - - if (!m_tcpServer->isListening()) { - m_ignoreNewConnection = true; - connect(rr, &HttpReqRep::closed, rr, &QObject::deleteLater); - } -} diff --git a/tests/auto/shared/httpserver.h b/tests/auto/shared/httpserver.h deleted file mode 100644 index 3ec69f8ed..000000000 --- a/tests/auto/shared/httpserver.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#ifndef HTTPSERVER_H -#define HTTPSERVER_H - -#include "httpreqrep.h" - -#include -#include - -// Listens on a TCP socket and creates HttpReqReps for each connection. -// -// Usage: -// -// HttpServer server; -// connect(&server, &HttpServer::newRequest, [](HttpReqRep *rr) { -// if (rr->requestPath() == "/myPage.html") { -// rr->setResponseBody("Hello, World!"); -// rr->sendResponse(); -// } -// }); -// QVERIFY(server.start()); -// /* do stuff */ -// QVERIFY(server.stop()); -// -// HttpServer owns the HttpReqRep objects. The signal handler should not store -// references to HttpReqRep objects. -// -// Only if a handler calls sendResponse() will a response be actually sent. This -// means that multiple handlers can be connected to the signal, with different -// handlers responsible for different paths. -class HttpServer : public QObject -{ - Q_OBJECT -public: - explicit HttpServer(QObject *parent = nullptr); - explicit HttpServer(QTcpServer *server, const QString &protocol, QObject *parent = nullptr); - - ~HttpServer() override; - - // Must be called to start listening. - // - // Returns true if a TCP port has been successfully bound. - Q_INVOKABLE Q_REQUIRED_RESULT bool start(); - - // Stops listening and performs final error checks. - Q_INVOKABLE Q_REQUIRED_RESULT bool stop(); - - Q_INVOKABLE void setExpectError(bool b); - - // Full URL for given relative path - Q_INVOKABLE QUrl url(const QString &path = QStringLiteral("/")) const; - - Q_INVOKABLE void setResourceDirs(const QStringList &dirs) { m_dirs = dirs; } - - Q_INVOKABLE void setHostDomain(const QString &host) { m_url.setHost(host); } - -Q_SIGNALS: - // Emitted after a HTTP request has been successfully parsed. - void newRequest(HttpReqRep *reqRep); - -private Q_SLOTS: - void handleNewConnection(); - -private: - QTcpServer *m_tcpServer; - QUrl m_url; - QStringList m_dirs; - bool m_error = false; - bool m_ignoreNewConnection = false; - bool m_expectingError = false; -}; - -#endif // !HTTPSERVER_H diff --git a/tests/auto/shared/httpsserver.h b/tests/auto/shared/httpsserver.h deleted file mode 100644 index 219d5f7a1..000000000 --- a/tests/auto/shared/httpsserver.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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$ -** -****************************************************************************/ -#ifndef HTTPSSERVER_H -#define HTTPSSERVER_H - -#include "httpreqrep.h" -#include "httpserver.h" - -#include -#include -#include -#include -#include -#include - -struct SslTcpServer : QTcpServer -{ - SslTcpServer() { - sslconf.setLocalCertificateChain(QSslCertificate::fromPath(":/resources/cert.pem")); - sslconf.setPrivateKey(readKey(":/resources/key.pem")); - } - - void incomingConnection(qintptr d) override { - auto socket = new QSslSocket(this); - socket->setSslConfiguration(sslconf); - - if (!socket->setSocketDescriptor(d)) { - qWarning() << "Failed to setup ssl socket!"; - delete socket; - return; - } - - connect(socket, QOverload::of(&QSslSocket::errorOccurred), - [] (QSslSocket::SocketError e) { qWarning() << "! Socket Error:" << e; }); - connect(socket, QOverload &>::of(&QSslSocket::sslErrors), - [] (const QList &le) { qWarning() << "! SSL Errors:\n" << le; }); - - addPendingConnection(socket); - socket->startServerEncryption(); - } - - QSslKey readKey(const QString &path) const { - QFile file(path); - file.open(QIODevice::ReadOnly); - return QSslKey(file.readAll(), QSsl::Rsa, QSsl::Pem); - } - - QSslConfiguration sslconf; -}; - -struct HttpsServer : HttpServer -{ - HttpsServer(QObject *parent = nullptr) : HttpServer(new SslTcpServer, "https", parent) { } -}; - -#endif diff --git a/tests/auto/shared/resources/cert.pem b/tests/auto/shared/resources/cert.pem deleted file mode 100644 index 3aaaf289c..000000000 --- a/tests/auto/shared/resources/cert.pem +++ /dev/null @@ -1,64 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIEpDCCAoygAwIBAgIUO90aty9AMjvBvzfUhr1WwdBrKkMwDQYJKoZIhvcNAQEL -BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM -DVNhbiBGcmFuY2lzY28xDzANBgNVBAoMBkJhZFNTTDEyMDAGA1UEAwwpQmFkU1NM -IEludGVybWVkaWF0ZSBDZXJ0aWZpY2F0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4 -ago0IhRdkFGe1Q7F8gOxtlUL5owNL4uhRP8BbwOja2Gopn2+kA9CNqdwPI4Ipjlr -yo61oCqzy3RAXOUct8WAvybacADmJODAxDq9O5fAZuYZScjjj1ASowmbyDH/Wb9z -+WfiKKH4BfgOIukzK3I1M9wiSDefIodCFfEVXbdNudZj8f9Gw4RrZwkUuxDLeRWG -ReDtzAWq7G0Diw3uX40S4jaj3MeS6oHp2Nrj/VyjSRiYTeN/pnA9N0M5VuCYYvXD -f50rrigjQfOgb4TmnyJAjXWVkXW7Fa+ooLsbvlfr8wP8f31y1cgWPHTVIv6Kmug7 -Bg88k3x5gLTXmutDjseORonhGMRdAxHgJVf5aKfzdRpwXZTDZJXhsAz9OdlOhNZd -UrYo680QugA0V3H5D8Egbr2AUUSMDkn133COjeOIDknFxX3qDqeTzqLZCAEBIoKn -Adpix0jvG1Ys4Ayq6K2wQFdGFjtl6LsiGC7pWWU= ------END CERTIFICATE----- diff --git a/tests/auto/shared/resources/key.pem b/tests/auto/shared/resources/key.pem deleted file mode 100644 index 89922679a..000000000 --- a/tests/auto/shared/resources/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAkybT/L4zJCqefpd+eYT6aQ0PtobQfFgP+n+z5wWoUxIAJnjb -5ZW47IJxka/2/ggzJOfrUBur54LkTfFQ+yX85eKYCuH0GLz+Rve50LDn0ya6qSgm -EhDG0bend2tMZY+Nl3B+5Ane1vua8hdJjv3ZO3e5UgpQwysL54eYyhEWWlbFWF11 -LhEdMYp953UGLqoV4Mlw+Li8TmFwdKQx6icgBTuloXLzk9aUU+b6NbXdadNXkmzg -09ICsb8pnMXiF2P9Xm5rK0IoiRkSHxVnU12nQXh65Ns/2Dj5DcbHmVdvallfr4wn -LeFPUotysZnvFmE7FLMSr/eQfkTG+Jlb7ZhoGwIDAQABAoIBADRXy3BL98UVo+tD -2ClBtBFKJBy5N9ADQyvH4SZ8TLO/423L7+xqpa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g67MAeIG6jtmPwxWk4EYAsO1u4XiyziABkoNyLKVH4hZg61BsV -jL7R5UrUvBbhKLFOwkcB4Kwdwu7COB/UKa5XJBTMbuw1UTyxlUeI ------END RSA PRIVATE KEY----- diff --git a/tests/auto/util/CMakeLists.txt b/tests/auto/util/CMakeLists.txt new file mode 100644 index 000000000..fa2f84cec --- /dev/null +++ b/tests/auto/util/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.18) +project(minimal LANGUAGES CXX) + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Network) + +include(util.cmake) diff --git a/tests/auto/util/qt_webengine_quicktest.h b/tests/auto/util/qt_webengine_quicktest.h new file mode 100644 index 000000000..55ccd9f33 --- /dev/null +++ b/tests/auto/util/qt_webengine_quicktest.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QT_WEBENGINE_QUICKTEST_H +#define QT_WEBENGINE_QUICKTEST_H + +#include + +#ifdef QT_WIDGETS_LIB +#include +#else +#include +#endif + +#include "qopenglcontext.h" +#include + +QT_BEGIN_NAMESPACE + +#ifdef QT_WIDGETS_LIB +#define Application QApplication +#else +#define Application QGuiApplication +#endif + +QT_END_NAMESPACE + +#endif // QT_WEBENGINE_QUICKTEST_H diff --git a/tests/auto/util/quickutil.h b/tests/auto/util/quickutil.h new file mode 100644 index 000000000..34afbbb45 --- /dev/null +++ b/tests/auto/util/quickutil.h @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef UTIL_H +#define UTIL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(TESTS_SOURCE_DIR) +#define TESTS_SOURCE_DIR "" +#endif + +class LoadSpy : public QEventLoop { + Q_OBJECT + +public: + LoadSpy(QQuickWebEngineView *webEngineView) + { + connect(webEngineView, &QQuickWebEngineView::loadingChanged, this, &LoadSpy::onLoadingChanged); + } + + ~LoadSpy() { } + +Q_SIGNALS: + void loadSucceeded(); + void loadFailed(); + +private Q_SLOTS: + void onLoadingChanged(const QWebEngineLoadRequest &request) + { + if (request.status() == QWebEngineLoadRequest::LoadSucceededStatus) + emit loadSucceeded(); + else if (request.status() == QWebEngineLoadRequest::LoadFailedStatus) + emit loadFailed(); + } +}; + +class LoadStartedCatcher : public QObject { + Q_OBJECT + +public: + LoadStartedCatcher(QQuickWebEngineView *webEngineView) + : m_webEngineView(webEngineView) + { + connect(m_webEngineView, &QQuickWebEngineView::loadingChanged, this, &LoadStartedCatcher::onLoadingChanged); + } + + virtual ~LoadStartedCatcher() { } + +public Q_SLOTS: + void onLoadingChanged(const QWebEngineLoadRequest &request) + { + if (request.status() == QWebEngineLoadRequest::LoadStartedStatus) + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); + } + +Q_SIGNALS: + void finished(); + +private: + QQuickWebEngineView *m_webEngineView; +}; + +inline bool waitForLoadSucceeded(QQuickWebEngineView *webEngineView, int timeout = 10000) +{ + LoadSpy loadSpy(webEngineView); + QSignalSpy spy(&loadSpy, &LoadSpy::loadSucceeded); + return spy.wait(timeout); +} + +inline bool waitForLoadFailed(QQuickWebEngineView *webEngineView, int timeout = 20000) +{ + LoadSpy loadSpy(webEngineView); + QSignalSpy spy(&loadSpy, &LoadSpy::loadFailed); + return spy.wait(timeout); +} + +inline QVariant evaluateJavaScriptSync(QQuickWebEngineView *view, const QString &script) +{ + QQmlEngine *engine = qmlEngine(view); + engine->globalObject().setProperty("called", false); + engine->globalObject().setProperty("result", QJSValue()); + QJSValue callback = engine->evaluate( + "(function callback(r) {" + " called = true;" + " result = r;" + "})" + ); + view->runJavaScript(script, callback); + QTRY_LOOP_IMPL(engine->globalObject().property("called").toBool(), 5000, 50); + if (!engine->globalObject().property("called").toBool()) { + qWarning("JavaScript wasn't evaluated"); + return QVariant(); + } + + return engine->globalObject().property("result").toVariant(); +} + +inline QPoint elementCenter(QQuickWebEngineView *view, const QString &id) +{ + const QString jsCode( + "(function(){" + " var elem = document.getElementById('" + id + "');" + " var rect = elem.getBoundingClientRect();" + " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" + "})()"); + QVariantList rectList = evaluateJavaScriptSync(view, jsCode).toList(); + + if (rectList.count() != 2) { + qWarning("elementCenter failed."); + return QPoint(); + } + + return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); +} + +inline QString activeElementId(QQuickWebEngineView *webEngineView) +{ + qRegisterMetaType("JavaScriptConsoleMessageLevel"); + QSignalSpy consoleMessageSpy(webEngineView, &QQuickWebEngineView::javaScriptConsoleMessage); + + webEngineView->runJavaScript( + "if (document.activeElement == null)" + " console.log('');" + "else" + " console.log(document.activeElement.id);" + ); + + if (!consoleMessageSpy.wait()) + return QString(); + + QList arguments = consoleMessageSpy.takeFirst(); + if (static_cast(arguments.at(0).toInt()) != QQuickWebEngineView::InfoMessageLevel) + return QString(); + + return arguments.at(1).toString(); +} + +#define W_QTEST_MAIN(TestObject, params) \ +int main(int argc, char *argv[]) \ +{ \ + QtWebEngine::initialize(); \ + \ + QList w_argv(argc); \ + for (int i = 0; i < argc; ++i) \ + w_argv[i] = argv[i]; \ + for (int i = 0; i < params.size(); ++i) \ + w_argv.append(params[i].data()); \ + int w_argc = w_argv.size(); \ + \ + QGuiApplication app(w_argc, const_cast(w_argv.data())); \ + app.setAttribute(Qt::AA_Use96Dpi, true); \ + TestObject tc; \ + QTEST_SET_MAIN_SOURCE_PATH \ + return QTest::qExec(&tc, argc, argv); \ +} +#endif /* UTIL_H */ + diff --git a/tests/auto/util/testwindow.h b/tests/auto/util/testwindow.h new file mode 100644 index 000000000..b57443c69 --- /dev/null +++ b/tests/auto/util/testwindow.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef TESTWINDOW_H +#define TESTWINDOW_H + +#if 0 +#pragma qt_no_master_include +#endif + +#include +#include +#include +#include + +// TestWindow: Utility class to ignore QQuickView details. +class TestWindow : public QQuickView { +public: + inline TestWindow(QQuickItem *webEngineView); + QScopedPointer webEngineView; + +protected: + inline void resizeEvent(QResizeEvent*); +}; + +inline TestWindow::TestWindow(QQuickItem *webEngineView) + : webEngineView(webEngineView) +{ + Q_ASSERT(webEngineView); + webEngineView->setParentItem(contentItem()); + resize(300, 400); +} + +inline void TestWindow::resizeEvent(QResizeEvent *event) +{ + QQuickView::resizeEvent(event); + webEngineView->setX(0); + webEngineView->setY(0); + webEngineView->setWidth(event->size().width()); + webEngineView->setHeight(event->size().height()); +} + +#endif /* TESTWINDOW_H */ diff --git a/tests/auto/util/util.cmake b/tests/auto/util/util.cmake new file mode 100644 index 000000000..84d7f593f --- /dev/null +++ b/tests/auto/util/util.cmake @@ -0,0 +1,5 @@ +if (NOT TARGET Test::Util) + add_library(qtestutil INTERFACE) + target_include_directories(qtestutil INTERFACE ${CMAKE_CURRENT_LIST_DIR}) + add_library(Test::Util ALIAS qtestutil) +endif() diff --git a/tests/auto/util/util.h b/tests/auto/util/util.h new file mode 100644 index 000000000..537b9212b --- /dev/null +++ b/tests/auto/util/util.h @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Functions and macros that really need to be in QTestLib + +#if 0 +#pragma qt_no_master_include +#endif + +#include +#include +#include +#include +#include + +// Disconnect signal on destruction. +class ScopedConnection +{ +public: + ScopedConnection(QMetaObject::Connection connection) : m_connection(std::move(connection)) { } + ~ScopedConnection() { QObject::disconnect(m_connection); } + +private: + QMetaObject::Connection m_connection; +}; + +/** + * Just like QSignalSpy but facilitates sync and async + * signal emission. For example if you want to verify that + * page->foo() emitted a signal, it could be that the + * implementation decides to emit the signal asynchronously + * - in which case we want to spin a local event loop until + * emission - or that the call to foo() emits it right away. + */ +class SignalBarrier : private QSignalSpy +{ +public: + SignalBarrier(const QObject* obj, const char* aSignal) + : QSignalSpy(obj, aSignal) + { } + + bool ensureSignalEmitted() + { + bool result = count() > 0; + if (!result) + result = wait(); + clear(); + return result; + } +}; + +template +struct CallbackWrapper { + QPointer p; + void operator()(const T& result) { + if (p) + (*p)(result); + } +}; + +template +class CallbackSpy: public QObject { +public: + CallbackSpy() : called(false) { + timeoutTimer.setSingleShot(true); + QObject::connect(&timeoutTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); + } + + T waitForResult(int timeout = 20000) { + const int step = 1000; + int elapsed = 0; + while (elapsed < timeout && !called) { + timeoutTimer.start(step); + eventLoop.exec(); + elapsed += step; + } + return result; + } + + bool wasCalled() const { + return called; + } + + void operator()(const T &result) { + this->result = result; + called = true; + eventLoop.quit(); + } + + CallbackWrapper > ref() + { + CallbackWrapper > wrapper = {this}; + return wrapper; + } + +private: + Q_DISABLE_COPY(CallbackSpy) + bool called; + QTimer timeoutTimer; + QEventLoop eventLoop; + T result; +}; + +static inline QString toPlainTextSync(QWebEnginePage *page) +{ + CallbackSpy spy; + page->toPlainText(spy.ref()); + return spy.waitForResult(); +} + +static inline QString toHtmlSync(QWebEnginePage *page) +{ + CallbackSpy spy; + page->toHtml(spy.ref()); + return spy.waitForResult(); +} + +static inline bool findTextSync(QWebEnginePage *page, const QString &subString) +{ + CallbackSpy spy; + page->findText(subString, {}, spy.ref()); + return spy.waitForResult(); +} + +static inline QVariant evaluateJavaScriptSync(QWebEnginePage *page, const QString &script) +{ + CallbackSpy spy; + page->runJavaScript(script, spy.ref()); + return spy.waitForResult(); +} + +static inline QVariant evaluateJavaScriptSyncInWorld(QWebEnginePage *page, const QString &script, int worldId) +{ + CallbackSpy spy; + page->runJavaScript(script, worldId, spy.ref()); + return spy.waitForResult(); +} + +static inline QUrl baseUrlSync(QWebEnginePage *page) +{ + CallbackSpy spy; + page->runJavaScript("document.baseURI", spy.ref()); + return spy.waitForResult().toUrl(); +} + +static inline bool loadSync(QWebEnginePage *page, const QUrl &url, bool ok = true) +{ + QSignalSpy spy(page, &QWebEnginePage::loadFinished); + page->load(url); + return (!spy.empty() || spy.wait(20000)) && (spy.front().value(0).toBool() == ok); +} + +static inline bool loadSync(QWebEngineView *view, const QUrl &url, bool ok = true) +{ + return loadSync(view->page(), url, ok); +} + +static inline QPoint elementCenter(QWebEnginePage *page, const QString &id) +{ + const QString jsCode( + "(function(){" + " var elem = document.getElementById('" + id + "');" + " var rect = elem.getBoundingClientRect();" + " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" + "})()"); + QVariantList rectList = evaluateJavaScriptSync(page, jsCode).toList(); + + if (rectList.count() != 2) { + qWarning("elementCenter failed."); + return QPoint(); + } + + return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); +} + +static inline QRect elementGeometry(QWebEnginePage *page, const QString &id) +{ + const QString jsCode( + "(function() {" + " var elem = document.getElementById('" + id + "');" + " var rect = elem.getBoundingClientRect();" + " return [rect.left, rect.top, rect.right, rect.bottom];" + "})()"); + QVariantList coords = evaluateJavaScriptSync(page, jsCode).toList(); + + if (coords.count() != 4) { + qWarning("elementGeometry faield."); + return QRect(); + } + + return QRect(coords[0].toInt(), coords[1].toInt(), coords[2].toInt(), coords[3].toInt()); +} + + +#define W_QSKIP(a, b) QSKIP(a) + +#define W_QTEST_MAIN(TestObject, params) \ +int main(int argc, char *argv[]) \ +{ \ + QList w_argv(argc); \ + for (int i = 0; i < argc; ++i) \ + w_argv[i] = argv[i]; \ + for (int i = 0; i < params.size(); ++i) \ + w_argv.append(params[i].data()); \ + int w_argc = w_argv.size(); \ + \ + QApplication app(w_argc, const_cast(w_argv.data())); \ + app.setAttribute(Qt::AA_Use96Dpi, true); \ + QTEST_DISABLE_KEYPAD_NAVIGATION \ + TestObject tc; \ + QTEST_SET_MAIN_SOURCE_PATH \ + return QTest::qExec(&tc, argc, argv); \ +} diff --git a/tests/auto/widgets/CMakeLists.txt b/tests/auto/widgets/CMakeLists.txt new file mode 100644 index 000000000..7072329c3 --- /dev/null +++ b/tests/auto/widgets/CMakeLists.txt @@ -0,0 +1,36 @@ +if(NOT boot2qt) + add_subdirectory(defaultsurfaceformat) + add_subdirectory(devtools) + add_subdirectory(qwebenginepage) + add_subdirectory(qwebengineprofile) + add_subdirectory(qwebengineview) +endif() +add_subdirectory(faviconmanager) +add_subdirectory(loadsignals) +add_subdirectory(origins) +add_subdirectory(proxy) +add_subdirectory(proxypac) +add_subdirectory(schemes) +add_subdirectory(shutdown) +add_subdirectory(qwebenginedownloadrequest) +add_subdirectory(qwebenginehistory) +add_subdirectory(qwebenginescript) +add_subdirectory(qwebenginesettings) +if(LINUX) + add_subdirectory(offscreen) +endif() +if(NOT MACOS) + add_subdirectory(touchinput) +endif() +if(QT_FEATURE_accessibility AND NOT boot2qt) + add_subdirectory(accessibility) +endif() +if(QT_FEATURE_webengine_printing_and_pdf) + add_subdirectory(printing) +endif() +if(QT_FEATURE_ssl) + add_subdirectory(certificateerror) +endif() +if(QT_FEATURE_webengine_spellchecker AND NOT CMAKE_CROSSCOMPILING AND NOT QT_FEATURE_webengine_native_spellchecker) +# add_subdirectory(spellchecking) +endif() diff --git a/tests/auto/widgets/accessibility/CMakeLists.txt b/tests/auto/widgets/accessibility/CMakeLists.txt new file mode 100644 index 000000000..9653ef1c0 --- /dev/null +++ b/tests/auto/widgets/accessibility/CMakeLists.txt @@ -0,0 +1,9 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_accessibility + SOURCES + tst_accessibility.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::Util +) diff --git a/tests/auto/widgets/accessibility/tst_accessibility.cpp b/tests/auto/widgets/accessibility/tst_accessibility.cpp index 46d26e6c6..429a40f4d 100644 --- a/tests/auto/widgets/accessibility/tst_accessibility.cpp +++ b/tests/auto/widgets/accessibility/tst_accessibility.cpp @@ -18,7 +18,7 @@ */ #include -#include "../util.h" +#include #include #include diff --git a/tests/auto/widgets/certificateerror/CMakeLists.txt b/tests/auto/widgets/certificateerror/CMakeLists.txt new file mode 100644 index 000000000..71721e8f5 --- /dev/null +++ b/tests/auto/widgets/certificateerror/CMakeLists.txt @@ -0,0 +1,23 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_certificateerror + SOURCES + tst_certificateerror.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) + +set(tst_certificateerror_resource_files + "resources/cert.pem" + "resources/key.pem" +) + +qt_internal_add_resource(tst_certificateerror "tst_certificateerror" + PREFIX + "/" + FILES + ${tst_certificateerror_resource_files} +) diff --git a/tests/auto/widgets/certificateerror/resources/cert.pem b/tests/auto/widgets/certificateerror/resources/cert.pem new file mode 100644 index 000000000..3aaaf289c --- /dev/null +++ b/tests/auto/widgets/certificateerror/resources/cert.pem @@ -0,0 +1,64 @@ +-----BEGIN CERTIFICATE----- +MIIEpDCCAoygAwIBAgIUO90aty9AMjvBvzfUhr1WwdBrK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3SyMzHRpgwtqIG4kl94A7Pz3CbA8+q7u7DW8l1GdaNx2J2wo+R5 +rJi02V5e7TNa7ZS5S9WGYHZ2y6QOjXuT28VMAPX+3HAgxk3RMxocpLpkPp8hhD/9 +S5KxA6AQDUN6av8E3xeuuWYWmTvAXNHK5ABXDFxxTp902ozNnZaSk2DxAUqcsOD4 +ago0IhRdkFGe1Q7F8gOxtlUL5owNL4uhRP8BbwOja2Gopn2+kA9CNqdwPI4Ipjlr +yo61oCqzy3RAXOUct8WAvybacADmJODAxDq9O5fAZuYZScjjj1ASowmbyDH/Wb9z ++WfiKKH4BfgOIukzK3I1M9wiSDefIodCFfEVXbdNudZj8f9Gw4RrZwkUuxDLeRWG +ReDtzAWq7G0Diw3uX40S4jaj3MeS6oHp2Nrj/VyjSRiYTeN/pnA9N0M5VuCYYvXD +f50rrigjQfOgb4TmnyJAjXWVkXW7Fa+ooLsbvlfr8wP8f31y1cgWPHTVIv6Kmug7 +Bg88k3x5gLTXmutDjseORonhGMRdAxHgJVf5aKfzdRpwXZTDZJXhsAz9OdlOhNZd +UrYo680QugA0V3H5D8Egbr2AUUSMDkn133COjeOIDknFxX3qDqeTzqLZCAEBIoKn +Adpix0jvG1Ys4Ayq6K2wQFdGFjtl6LsiGC7pWWU= +-----END CERTIFICATE----- diff --git a/tests/auto/widgets/certificateerror/resources/key.pem b/tests/auto/widgets/certificateerror/resources/key.pem new file mode 100644 index 000000000..89922679a --- /dev/null +++ b/tests/auto/widgets/certificateerror/resources/key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAkybT/L4zJCqefpd+eYT6aQ0PtobQfFgP+n+z5wWoUxIAJnjb +5ZW47IJxka/2/ggzJOfrUBur54LkTfFQ+yX85eKYCuH0GLz+Rve50LDn0ya6qSgm +EhDG0bend2tMZY+Nl3B+5Ane1vua8hdJjv3ZO3e5UgpQwysL54eYyhEWWlbFWF11 +LhEdMYp953UGLqoV4Mlw+Li8Tm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40 +vIsAuNUruTYkQvKmuOsqohO6CXZb2hWSpZ9KZNN+3ucaCL9PDE/4QEM+W9iuQu/X +gLzy6npxAD6avtGVweq2ncjbMp7QB1ksP69pJDn74xGV8miGPuiVyNOUEMgyChtR +Oz6EnQKBgEth0w80CBg6b3NKuASoc/vC08njZQvWpe5xrzY2DL8epVKb1qf6+8SE +eX34cIcSaonEZ2g67MAeIG6jtmPwxWk4EYAsO1u4XiyziABkoNyLKVH4hZg61BsV +jL7R5UrUvBbhKLFOwkcB4Kwdwu7COB/UKa5XJBTMbuw1UTyxlUeI +-----END RSA PRIVATE KEY----- diff --git a/tests/auto/widgets/certificateerror/tst_certificateerror.cpp b/tests/auto/widgets/certificateerror/tst_certificateerror.cpp index 9865162cb..2f03c3275 100644 --- a/tests/auto/widgets/certificateerror/tst_certificateerror.cpp +++ b/tests/auto/widgets/certificateerror/tst_certificateerror.cpp @@ -86,7 +86,7 @@ void tst_CertificateError::handleError_data() void tst_CertificateError::handleError() { - HttpsServer server; + HttpsServer server(":/resources/cert.pem",":/resources/key.pem"); server.setExpectError(true); QVERIFY(server.start()); diff --git a/tests/auto/widgets/defaultsurfaceformat/CMakeLists.txt b/tests/auto/widgets/defaultsurfaceformat/CMakeLists.txt new file mode 100644 index 000000000..871c92350 --- /dev/null +++ b/tests/auto/widgets/defaultsurfaceformat/CMakeLists.txt @@ -0,0 +1,20 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_defaultsurfaceformat + SOURCES + tst_defaultsurfaceformat.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::Util +) + +set(tst_defaultsurfaceformat_resource_files + "resources/index.html" +) + +qt_add_resource(tst_defaultsurfaceformat "tst_defaultsurfaceformat" + PREFIX + "/" + FILES + ${tst_defaultsurfaceformat_resource_files} +) diff --git a/tests/auto/widgets/defaultsurfaceformat/tst_defaultsurfaceformat.cpp b/tests/auto/widgets/defaultsurfaceformat/tst_defaultsurfaceformat.cpp index 697ed3d08..7a52a372a 100644 --- a/tests/auto/widgets/defaultsurfaceformat/tst_defaultsurfaceformat.cpp +++ b/tests/auto/widgets/defaultsurfaceformat/tst_defaultsurfaceformat.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include -#include "../util.h" +#include #include #include diff --git a/tests/auto/widgets/devtools/CMakeLists.txt b/tests/auto/widgets/devtools/CMakeLists.txt new file mode 100644 index 000000000..2ef09df12 --- /dev/null +++ b/tests/auto/widgets/devtools/CMakeLists.txt @@ -0,0 +1,7 @@ +qt_internal_add_test(tst_devtools + SOURCES + tst_devtools.cpp + LIBRARIES + Qt::WebEngineWidgets +) + diff --git a/tests/auto/widgets/faviconmanager/CMakeLists.txt b/tests/auto/widgets/faviconmanager/CMakeLists.txt new file mode 100644 index 000000000..89bee5a2a --- /dev/null +++ b/tests/auto/widgets/faviconmanager/CMakeLists.txt @@ -0,0 +1,29 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_faviconmanager + SOURCES + tst_faviconmanager.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::Util +) + +set(tst_faviconmanager_resource_files + "resources/favicon-misc.html" + "resources/favicon-multi.html" + "resources/favicon-shortcut.html" + "resources/favicon-single.html" + "resources/favicon-touch.html" + "resources/favicon-unavailable.html" + "resources/icons/qt144.png" + "resources/icons/qt32.ico" + "resources/icons/qtmulti.ico" + "resources/test1.html" +) + +qt_add_resource(tst_faviconmanager "tst_faviconmanager" + PREFIX + "/" + FILES + ${tst_faviconmanager_resource_files} +) diff --git a/tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp b/tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp index 46038cdc6..8e9bb2470 100644 --- a/tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp +++ b/tests/auto/widgets/faviconmanager/tst_faviconmanager.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include -#include "../util.h" +#include #include #include @@ -97,14 +97,19 @@ void tst_FaviconManager::cleanup() void tst_FaviconManager::faviconLoad() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-single.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-single.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -113,7 +118,9 @@ void tst_FaviconManager::faviconLoad() QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(iconUrl, m_page->iconUrl()); - QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/icons/qt32.ico"))); + QCOMPARE(iconUrl, + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/qt32.ico"))); const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); @@ -150,14 +157,20 @@ void tst_FaviconManager::faviconLoadFromResources() void tst_FaviconManager::faviconLoadEncodedUrl() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QString urlString = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-single.html")).toString(); + QString urlString = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-single.html")) + .toString(); QUrl url(urlString + QLatin1String("?favicon=load should work with#whitespace!")); m_page->load(url); @@ -167,7 +180,9 @@ void tst_FaviconManager::faviconLoadEncodedUrl() QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(m_page->iconUrl(), iconUrl); - QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/icons/qt32.ico"))); + QCOMPARE(iconUrl, + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/qt32.ico"))); const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); @@ -179,14 +194,19 @@ void tst_FaviconManager::faviconLoadEncodedUrl() void tst_FaviconManager::noFavicon() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/test1.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/test1.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -216,14 +236,19 @@ void tst_FaviconManager::aboutBlank() void tst_FaviconManager::unavailableFavicon() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-unavailable.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-unavailable.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -274,8 +299,12 @@ void tst_FaviconManager::errorPageDisabled() void tst_FaviconManager::bestFavicon() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); @@ -285,7 +314,8 @@ void tst_FaviconManager::bestFavicon() QIcon icon; QSize iconSize; - url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-misc.html")); + url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-misc.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -295,7 +325,9 @@ void tst_FaviconManager::bestFavicon() iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(iconUrl, m_page->iconUrl()); // Touch icon is ignored - QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/icons/qt32.ico"))); + QCOMPARE(iconUrl, + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/qt32.ico"))); icon = m_page->icon(); QVERIFY(!icon.isNull()); @@ -308,7 +340,8 @@ void tst_FaviconManager::bestFavicon() iconUrlChangedSpy.clear(); iconChangedSpy.clear(); - url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-shortcut.html")); + url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-shortcut.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -326,7 +359,9 @@ void tst_FaviconManager::bestFavicon() } QCOMPARE(iconUrl, m_page->iconUrl()); - QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/icons/qt144.png"))); + QCOMPARE(iconUrl, + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/qt144.png"))); icon = m_page->icon(); QVERIFY(!icon.isNull()); @@ -337,14 +372,19 @@ void tst_FaviconManager::bestFavicon() void tst_FaviconManager::touchIcon() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-touch.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-touch.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -357,14 +397,19 @@ void tst_FaviconManager::touchIcon() void tst_FaviconManager::multiIcon() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-multi.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-multi.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -373,7 +418,9 @@ void tst_FaviconManager::multiIcon() QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(m_page->iconUrl(), iconUrl); - QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/icons/qtmulti.ico"))); + QCOMPARE(iconUrl, + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/qtmulti.ico"))); const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); @@ -385,14 +432,19 @@ void tst_FaviconManager::multiIcon() void tst_FaviconManager::candidateIcon() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); QSignalSpy iconUrlChangedSpy(m_page, SIGNAL(iconUrlChanged(QUrl))); QSignalSpy iconChangedSpy(m_page, SIGNAL(iconChanged(QIcon))); - QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/favicon-shortcut.html")); + QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/favicon-shortcut.html")); m_page->load(url); QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.count(), 1, 30000); @@ -401,7 +453,9 @@ void tst_FaviconManager::candidateIcon() QUrl iconUrl = iconUrlChangedSpy.at(0).at(0).toString(); QCOMPARE(m_page->iconUrl(), iconUrl); - QCOMPARE(iconUrl, QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("faviconmanager/resources/icons/qt144.png"))); + QCOMPARE(iconUrl, + QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/resources/icons/qt144.png"))); const QIcon &icon = m_page->icon(); QVERIFY(!icon.isNull()); diff --git a/tests/auto/widgets/loadsignals/CMakeLists.txt b/tests/auto/widgets/loadsignals/CMakeLists.txt new file mode 100644 index 000000000..f648cf6d3 --- /dev/null +++ b/tests/auto/widgets/loadsignals/CMakeLists.txt @@ -0,0 +1,60 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_loadsignals + SOURCES + tst_loadsignals.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) + +get_target_property(sharedData Test::HttpServer SHARED_DATA) + +set_source_files_properties("${sharedData}/loadprogress/downloadable.tar.gz" + PROPERTIES QT_RESOURCE_ALIAS "downloadable.tar.gz" +) +set_source_files_properties("${sharedData}/loadprogress/page1.html" + PROPERTIES QT_RESOURCE_ALIAS "page1.html" +) +set_source_files_properties("${sharedData}/loadprogress/page2.html" + PROPERTIES QT_RESOURCE_ALIAS "page2.html" +) +set_source_files_properties("${sharedData}/loadprogress/page3.html" + PROPERTIES QT_RESOURCE_ALIAS "page3.html" +) +set_source_files_properties("${sharedData}/loadprogress/page4.html" + PROPERTIES QT_RESOURCE_ALIAS "page4.html" +) +set_source_files_properties("${sharedData}/loadprogress/page5.html" + PROPERTIES QT_RESOURCE_ALIAS "page5.html" +) +set_source_files_properties("${sharedData}/loadprogress/page6.html" + PROPERTIES QT_RESOURCE_ALIAS "page6.html" +) +set_source_files_properties("${sharedData}/loadprogress/page7.html" + PROPERTIES QT_RESOURCE_ALIAS "page7.html" +) +set_source_files_properties("${sharedData}/loadprogress/page8.html" + PROPERTIES QT_RESOURCE_ALIAS "page8.html" +) + +set(tst_loadsignals_resource_files + "${sharedData}/loadprogress/downloadable.tar.gz" + "${sharedData}/loadprogress/page1.html" + "${sharedData}/loadprogress/page2.html" + "${sharedData}/loadprogress/page3.html" + "${sharedData}/loadprogress/page4.html" + "${sharedData}/loadprogress/page5.html" + "${sharedData}/loadprogress/page6.html" + "${sharedData}/loadprogress/page7.html" + "${sharedData}/loadprogress/page8.html" +) + +qt_add_resource(tst_loadsignals "tst_loadsignals" + PREFIX + "/resources" + FILES + ${tst_loadsignals_resource_files} +) diff --git a/tests/auto/widgets/loadsignals/tst_loadsignals.cpp b/tests/auto/widgets/loadsignals/tst_loadsignals.cpp index fe01bede4..12a497dd9 100644 --- a/tests/auto/widgets/loadsignals/tst_loadsignals.cpp +++ b/tests/auto/widgets/loadsignals/tst_loadsignals.cpp @@ -29,7 +29,7 @@ #include #include "httpserver.h" -#include "../util.h" +#include #include "qdebug.h" #include "qwebenginepage.h" #include "qwebengineprofile.h" @@ -276,7 +276,7 @@ void tst_LoadSignals::rejectNavigationRequest() void tst_LoadSignals::monotonicity() { HttpServer server; - server.setResourceDirs({ TESTS_SHARED_DATA_DIR }); + server.setResourceDirs({ server.sharedDataDir() }); connect(&server, &HttpServer::newRequest, [] (HttpReqRep *) { QTest::qWait(250); // just add delay to trigger some progress for every sub resource }); @@ -376,7 +376,7 @@ void tst_LoadSignals::numberOfStartedAndFinishedSignalsIsSame() QFETCH(QString, imageResourceUrl); HttpServer server; - server.setResourceDirs({ TESTS_SOURCE_DIR "/qwebengineprofile/resources" }); + server.setResourceDirs({ server.sharedDataDir() }); QVERIFY(server.start()); QUrl serverImage = server.url("/hedgehog.png"); diff --git a/tests/auto/widgets/offscreen/CMakeLists.txt b/tests/auto/widgets/offscreen/CMakeLists.txt new file mode 100644 index 000000000..1ba5a1e6a --- /dev/null +++ b/tests/auto/widgets/offscreen/CMakeLists.txt @@ -0,0 +1,22 @@ +qt_internal_add_test(tst_offscreen + SOURCES + tst_offscreen.cpp + LIBRARIES + Qt::WebEngineWidgets +) + +set(tst_offscreen_resource_files + "test.html" +) + +set_tests_properties(tst_offscreen PROPERTIES + ENVIRONMENT QT_QPA_PLATFORM=offscreen +) + +qt_add_resource(tst_offscreen "tst_offscreen" + PREFIX + "/" + FILES + ${tst_offscreen_resource_files} +) + diff --git a/tests/auto/widgets/origins/CMakeLists.txt b/tests/auto/widgets/origins/CMakeLists.txt new file mode 100644 index 000000000..5ba017052 --- /dev/null +++ b/tests/auto/widgets/origins/CMakeLists.txt @@ -0,0 +1,45 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_origins + SOURCES + tst_origins.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) + +set(tst_origins_resource_files + "resources/createObjectURL.html" + "resources/dedicatedWorker.html" + "resources/dedicatedWorker.js" + "resources/mixedSchemes.html" + "resources/mixedSchemesWithCsp.html" + "resources/mixedSchemes_frame.html" + "resources/mixedXHR.html" + "resources/mixedXHR.txt" + "resources/serviceWorker.html" + "resources/serviceWorker.js" + "resources/sharedWorker.html" + "resources/sharedWorker.js" + "resources/subdir/frame2.html" + "resources/subdir/index.html" + "resources/subdir_frame1.html" + "resources/viewSource.html" + "resources/websocket.html" +) + +qt_add_resource(tst_origins "tst_origins" + PREFIX + "/" + FILES + ${tst_origins_resource_files} +) + +qt_extend_target(tst_origins CONDITION QT_FEATURE_webengine_webchannel AND TARGET Qt::WebSockets + DEFINES + WEBSOCKETS + LIBRARIES + Qt::WebSockets +) diff --git a/tests/auto/widgets/origins/tst_origins.cpp b/tests/auto/widgets/origins/tst_origins.cpp index b9385516f..a834110b5 100644 --- a/tests/auto/widgets/origins/tst_origins.cpp +++ b/tests/auto/widgets/origins/tst_origins.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "../util.h" +#include #include "httpserver.h" #include @@ -47,7 +47,6 @@ #define QSL QStringLiteral #define QBAL QByteArrayLiteral -#define THIS_DIR TESTS_SOURCE_DIR "origins/" void registerSchemes() { @@ -185,7 +184,7 @@ private: return; } - QString pathPrefix = QSL(THIS_DIR); + QString pathPrefix = QDir(QT_TESTCASE_SOURCEDIR).canonicalPath(); QString pathSuffix = url.path(); QFile *file = new QFile(pathPrefix + pathSuffix, job); if (!file->open(QIODevice::ReadOnly)) { @@ -460,7 +459,8 @@ void tst_Origins::subdirWithAccess() { ScopedAttribute sa(m_page->settings(), QWebEngineSettings::LocalContentCanAccessFileUrls, true); - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/subdir/index.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/subdir/index.html")); QCOMPARE(eval(QSL("msg[0]")), QVariant(QSL("hello"))); QCOMPARE(eval(QSL("msg[1]")), QVariant(QSL("world"))); @@ -488,7 +488,8 @@ void tst_Origins::subdirWithoutAccess() QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("Uncaught SecurityError"))); QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("Uncaught SecurityError"))); - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/subdir/index.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/subdir/index.html")); QCOMPARE(eval(QSL("msg[0]")), QVariant()); QCOMPARE(eval(QSL("msg[1]")), QVariant()); @@ -513,14 +514,15 @@ void tst_Origins::fileAccessRemoteUrl() QFETCH(bool, EnableAccess); HttpServer server; - server.setResourceDirs({ THIS_DIR "resources" }); + server.setResourceDirs({ QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + "/resources" }); QVERIFY(server.start()); ScopedAttribute sa(m_page->settings(), QWebEngineSettings::LocalContentCanAccessRemoteUrls, EnableAccess); if (!EnableAccess) QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("blocked by CORS policy"))); - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/mixedXHR.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.html")); eval("sendXHR('" + server.url("/mixedXHR.txt").toString() + "')"); QTRY_COMPARE(eval("result"), (EnableAccess ? QString("ok") : QString("error"))); @@ -536,8 +538,10 @@ void tst_Origins::fileAccessRemoteUrl() // file: scheme. void tst_Origins::mixedSchemes() { - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/mixedSchemes.html"))); - eval(QSL("setIFrameUrl('file:" THIS_DIR "resources/mixedSchemes_frame.html')")); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedSchemes.html")); + eval("setIFrameUrl('file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedSchemes_frame.html')"); QTRY_COMPARE(eval(QSL("result")), QVariant(QSL("canLoadAndAccess"))); QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("Uncaught SecurityError"))); eval(QSL("setIFrameUrl('qrc:/resources/mixedSchemes_frame.html')")); @@ -548,7 +552,8 @@ void tst_Origins::mixedSchemes() QVERIFY(verifyLoad(QSL("qrc:/resources/mixedSchemes.html"))); QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("Uncaught SecurityError"))); - eval(QSL("setIFrameUrl('file:" THIS_DIR "resources/mixedSchemes_frame.html')")); + eval("setIFrameUrl('file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedSchemes_frame.html')"); QTRY_COMPARE(eval(QSL("result")), QVariant(QSL("canLoadButNotAccess"))); eval(QSL("setIFrameUrl('qrc:/resources/mixedSchemes_frame.html')")); QTRY_COMPARE(eval(QSL("result")), QVariant(QSL("canLoadAndAccess"))); @@ -558,7 +563,8 @@ void tst_Origins::mixedSchemes() QVERIFY(verifyLoad(QSL("tst:/resources/mixedSchemes.html"))); QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("Not allowed to load local resource"))); - eval(QSL("setIFrameUrl('file:" THIS_DIR "resources/mixedSchemes_frame.html')")); + eval("setIFrameUrl('file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedSchemes_frame.html')"); QTRY_COMPARE(eval(QSL("result")), QVariant(QSL("cannotLoad"))); QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("Uncaught SecurityError"))); eval(QSL("setIFrameUrl('qrc:/resources/mixedSchemes_frame.html')")); @@ -644,24 +650,32 @@ void tst_Origins::mixedXHR_data() QTest::addColumn("url"); QTest::addColumn("command"); QTest::addColumn("result"); - QTest::newRow("file->file") << QString("file:" THIS_DIR "resources/mixedXHR.html") - << QString("sendXHR('file:" THIS_DIR "resources/mixedXHR.txt')") + QTest::newRow("file->file") << QString("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.html") + << QString("sendXHR('file:" + + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.txt')") << QVariant(QString("ok")); - QTest::newRow("file->qrc") << QString("file:" THIS_DIR "resources/mixedXHR.html") + QTest::newRow("file->qrc") << QString("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.html") << QString("sendXHR('qrc:/resources/mixedXHR.txt')") << QVariant(QString("error")); - QTest::newRow("file->tst") << QString("file:" THIS_DIR "resources/mixedXHR.html") + QTest::newRow("file->tst") << QString("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.html") << QString("sendXHR('tst:/resources/mixedXHR.txt')") << QVariant(QString("error")); - QTest::newRow("file->data") << QString("file:" THIS_DIR "resources/mixedXHR.html") - << QString("sendXHR('data:,ok')") - << QVariant(QString("ok")); - QTest::newRow("file->cors") << QString("file:" THIS_DIR "resources/mixedXHR.html") + QTest::newRow("file->data") << QString("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.html") + << QString("sendXHR('data:,ok')") << QVariant(QString("ok")); + QTest::newRow("file->cors") << QString("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.html") << QString("sendXHR('cors:/resources/mixedXHR.txt')") << QVariant(QString("ok")); QTest::newRow("qrc->file") << QString("qrc:/resources/mixedXHR.html") - << QString("sendXHR('file:" THIS_DIR "resources/mixedXHR.txt')") + << QString("sendXHR('file:" + + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.txt')") << QVariant(QString("ok")); QTest::newRow("qrc->qrc") << QString("qrc:/resources/mixedXHR.html") << QString("sendXHR('qrc:/resources/mixedXHR.txt')") @@ -676,9 +690,10 @@ void tst_Origins::mixedXHR_data() << QString("sendXHR('cors:/resources/mixedXHR.txt')") << QVariant(QString("ok")); - QTest::newRow("tst->file") << QString("tst:/resources/mixedXHR.html") - << QString("sendXHR('file:" THIS_DIR "resources/mixedXHR.txt')") + << QString("sendXHR('file:" + + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/mixedXHR.txt')") << QVariant(QString("error")); QTest::newRow("tst->qrc") << QString("tst:/resources/mixedXHR.html") << QString("sendXHR('qrc:/resources/mixedXHR.txt')") @@ -760,7 +775,8 @@ void tst_Origins::webSocket() m_page->setWebChannel(&channel); QVERIFY(echoServer.listen()); - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/websocket.html"))); + QVERIFY(verifyLoad( + QSL("file:" QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() "/resources/websocket.html"))); QTRY_COMPARE(eval(QSL("result")), QVariant(QSL("ok"))); QVERIFY(verifyLoad(QSL("qrc:/resources/websocket.html"))); @@ -779,7 +795,8 @@ void tst_Origins::webSocket() // one page, there is not much need for security restrictions. void tst_Origins::dedicatedWorker() { - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/dedicatedWorker.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/dedicatedWorker.html")); QTRY_VERIFY(eval(QSL("done")).toBool()); QCOMPARE(eval(QSL("result")), QVariant(42)); @@ -810,7 +827,8 @@ void tst_Origins::sharedWorker() { { ScopedAttribute sa(m_page->settings(), QWebEngineSettings::LocalContentCanAccessFileUrls, false); - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/sharedWorker.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/sharedWorker.html")); QTRY_VERIFY_WITH_TIMEOUT(eval(QSL("done")).toBool(), 10000); QVERIFY(eval(QSL("error")).toString() .contains(QSL("cannot be accessed from origin 'null'"))); @@ -818,7 +836,8 @@ void tst_Origins::sharedWorker() { ScopedAttribute sa(m_page->settings(), QWebEngineSettings::LocalContentCanAccessFileUrls, true); - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/sharedWorker.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/sharedWorker.html")); QTRY_VERIFY_WITH_TIMEOUT(eval(QSL("done")).toBool(), 10000); QCOMPARE(eval(QSL("result")), QVariant(42)); } @@ -842,7 +861,8 @@ void tst_Origins::sharedWorker() // Service workers have to be explicitly enabled for a scheme. void tst_Origins::serviceWorker() { - QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/serviceWorker.html"))); + QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/serviceWorker.html")); QTRY_VERIFY(eval(QSL("done")).toBool()); QVERIFY(eval(QSL("error")).toString() .contains(QSL("The URL protocol of the current origin ('file://') is not supported."))); @@ -885,11 +905,16 @@ void tst_Origins::serviceWorker() // Support for view-source must be enabled explicitly. void tst_Origins::viewSource() { - QVERIFY(verifyLoad(QSL("view-source:file:" THIS_DIR "resources/viewSource.html"))); + QVERIFY(verifyLoad("view-source:file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/viewSource.html")); #ifdef Q_OS_WIN - QCOMPARE(m_page->requestedUrl().toString(), QSL("file:///" THIS_DIR "resources/viewSource.html")); + QCOMPARE(m_page->requestedUrl().toString(), + "file:///" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/viewSource.html"); #else - QCOMPARE(m_page->requestedUrl().toString(), QSL("file://" THIS_DIR "resources/viewSource.html")); + QCOMPARE(m_page->requestedUrl().toString(), + "file://" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + "/resources/viewSource.html"); #endif QVERIFY(verifyLoad(QSL("view-source:qrc:/resources/viewSource.html"))); diff --git a/tests/auto/widgets/printing/CMakeLists.txt b/tests/auto/widgets/printing/CMakeLists.txt new file mode 100644 index 000000000..4c06a1b38 --- /dev/null +++ b/tests/auto/widgets/printing/CMakeLists.txt @@ -0,0 +1,34 @@ +include(../../util/util.cmake) + +find_package(PkgConfig) +if(PkgConfig_FOUND) + pkg_check_modules(POPPLER_CPP poppler-cpp IMPORTED_TARGET) +endif() + +qt_internal_add_test(tst_printing + SOURCES + tst_printing.cpp + PUBLIC_LIBRARIES + Qt::WebEngineWidgets + LIBRARIES + Qt::CorePrivate + Qt::WebEngineCorePrivate + Test::Util +) + +qt_internal_extend_target(tst_printing + CONDITION POPPLER_CPP_FOUND + DEFINES + POPPLER_CPP + LIBRARIES + PkgConfig::POPPLER_CPP +) + +set(tst_printing_resource_files + "resources/basic_printing_page.html" +) + +qt_add_resource(tst_printing "tst_printing" + PREFIX "/" + FILES ${tst_printing_resource_files} +) diff --git a/tests/auto/widgets/printing/tst_printing.cpp b/tests/auto/widgets/printing/tst_printing.cpp index 380fb65ff..d1542af23 100644 --- a/tests/auto/widgets/printing/tst_printing.cpp +++ b/tests/auto/widgets/printing/tst_printing.cpp @@ -33,7 +33,7 @@ #include #include -#if QT_CONFIG(webengine_poppler_cpp) +#if defined(POPPLER_CPP) #include #include #endif @@ -44,7 +44,7 @@ class tst_Printing : public QObject private slots: void printToPdfBasic(); void printRequest(); -#if QT_CONFIG(webengine_poppler_cpp) && defined(Q_OS_LINUX) && defined(__GLIBCXX__) +#if defined(POPPLER_CPP) && defined(Q_OS_LINUX) && defined(__GLIBCXX__) void printToPdfPoppler(); #endif }; @@ -108,7 +108,7 @@ void tst_Printing::printRequest() QVERIFY(data.length() > 0); } -#if QT_CONFIG(webengine_poppler_cpp) && defined(Q_OS_LINUX) && defined(__GLIBCXX__) +#if defined(POPPLER_CPP) && defined(Q_OS_LINUX) && defined(__GLIBCXX__) void tst_Printing::printToPdfPoppler() { // check if generated pdf is correct by searching for a know string on the page diff --git a/tests/auto/widgets/proxy/CMakeLists.txt b/tests/auto/widgets/proxy/CMakeLists.txt new file mode 100644 index 000000000..0929c050c --- /dev/null +++ b/tests/auto/widgets/proxy/CMakeLists.txt @@ -0,0 +1,9 @@ +include(../../httpserver/httpserver.cmake) + +qt_internal_add_test(tst_proxy + SOURCES + tst_proxy.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer +) diff --git a/tests/auto/widgets/proxy/proxy_server.cpp b/tests/auto/widgets/proxy/proxy_server.cpp deleted file mode 100644 index 3e52de4f2..000000000 --- a/tests/auto/widgets/proxy/proxy_server.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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$ -** -****************************************************************************/ - -#include "proxy_server.h" -#include -#include -#include - -ProxyServer::ProxyServer(QObject *parent) : QObject(parent) -{ - connect(&m_server, &QTcpServer::newConnection, this, &ProxyServer::handleNewConnection); -} - -void ProxyServer::setCredentials(const QByteArray &user, const QByteArray password) -{ - m_auth.append(user); - m_auth.append(':'); - m_auth.append(password); - m_auth = m_auth.toBase64(); - m_authenticate = true; -} - -void ProxyServer::setCookie(const QByteArray &cookie) -{ - m_cookie.append(QByteArrayLiteral("Cookie: ")); - m_cookie.append(cookie); -} - - -bool ProxyServer::isListening() -{ - return m_server.isListening(); -} - -void ProxyServer::run() -{ - if (!m_server.listen(QHostAddress::LocalHost, 5555)) - qFatal("Could not start the test server"); -} - -void ProxyServer::handleNewConnection() -{ - // do one connection at the time - Q_ASSERT(m_data.isEmpty()); - QTcpSocket *socket = m_server.nextPendingConnection(); - Q_ASSERT(socket); - connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater); - connect(socket, &QAbstractSocket::readyRead, this, &ProxyServer::handleReadReady); -} - -void ProxyServer::handleReadReady() -{ - QTcpSocket *socket = qobject_cast(sender()); - Q_ASSERT(socket); - - m_data.append(socket->readAll()); - - if (!m_data.endsWith("\r\n\r\n")) - return; - - if (m_authenticate && !m_data.contains(QByteArrayLiteral("Proxy-Authorization: Basic"))) { - socket->write("HTTP/1.1 407 Proxy Authentication Required\nProxy-Authenticate: " - "Basic realm=\"Proxy requires authentication\"\r\n" - "content-length: 0\r\n" - "\r\n"); - return; - } - - if (m_authenticate && m_data.contains(m_auth)) { - emit authenticationSuccess(); - } - - if (m_data.contains(m_cookie)) { - emit cookieMatch(); - } - m_data.clear(); -} diff --git a/tests/auto/widgets/proxy/proxy_server.h b/tests/auto/widgets/proxy/proxy_server.h deleted file mode 100644 index 7bc7b100b..000000000 --- a/tests/auto/widgets/proxy/proxy_server.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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$ -** -****************************************************************************/ - -#ifndef PROXY_SERVER_H -#define PROXY_SERVER_H - -#include -#include - -class ProxyServer : public QObject -{ - Q_OBJECT - -public: - explicit ProxyServer(QObject *parent = nullptr); - void setCredentials(const QByteArray &user, const QByteArray password); - void setCookie(const QByteArray &cookie); - bool isListening(); - -public slots: - void run(); - -private slots: - void handleNewConnection(); - void handleReadReady(); - -signals: - void authenticationSuccess(); - void cookieMatch(); - -private: - QByteArray m_data; - QTcpServer m_server; - QByteArray m_auth; - QByteArray m_cookie; - bool m_authenticate = false; -}; - -#endif // PROXY_SERVER_H diff --git a/tests/auto/widgets/proxypac/CMakeLists.txt b/tests/auto/widgets/proxypac/CMakeLists.txt new file mode 100644 index 000000000..25d754cf7 --- /dev/null +++ b/tests/auto/widgets/proxypac/CMakeLists.txt @@ -0,0 +1,46 @@ +include(../../httpserver/httpserver.cmake) + +qt_internal_add_test(tst_proxypac_file + SOURCES + tst_proxypac.cpp + LIBRARIES + Qt::WebEngineCore + Test::HttpServer +) + +if(WIN32) + set(fileEnvArg "--proxy-pac-url=\"file:///${CMAKE_CURRENT_LIST_DIR}/proxy.pac\"") +elseif(boot2qt) + set(fileEnvArg "--single-process --no-sandbox --proxy-pac-url=\"file://${CMAKE_CURRENT_LIST_DIR}/proxy.pac\"") +else() + set(fileEnvArg "--proxy-pac-url=\"file://${CMAKE_CURRENT_LIST_DIR}/proxy.pac\"") +endif() + +set_tests_properties(tst_proxypac_file PROPERTIES + ENVIRONMENT QTWEBENGINE_CHROMIUM_FLAGS=${fileEnvArg} +) + +qt_internal_add_test(tst_proxypac_qrc + SOURCES + tst_proxypac.cpp + LIBRARIES + Qt::WebEngineCore + Test::HttpServer +) + +if(boot2qt) + set(qrcEnvArg "--single-process --no-sandbox --proxy-pac-url=\"qrc:///proxy.pac\"") +else() + set(qrcEnvArg "--proxy-pac-url=\"qrc:///proxy.pac\"") +endif() + +set_tests_properties(tst_proxypac_qrc PROPERTIES + ENVIRONMENT QTWEBENGINE_CHROMIUM_FLAGS=${qrcEnvArg} +) + +qt_add_resource(tst_proxypac_qrc "proxypac" + PREFIX + "/" + FILES + "proxy.pac" +) diff --git a/tests/auto/widgets/proxypac/tst_proxypac.cpp b/tests/auto/widgets/proxypac/tst_proxypac.cpp index 26f9b8aa3..223c995e0 100644 --- a/tests/auto/widgets/proxypac/tst_proxypac.cpp +++ b/tests/auto/widgets/proxypac/tst_proxypac.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "proxyserver.h" +#include "proxy_server.h" #include #include #include @@ -47,17 +47,17 @@ void tst_ProxyPac::proxypac() { const QString fromEnv = qEnvironmentVariable("QTWEBENGINE_CHROMIUM_FLAGS"); if (!fromEnv.contains("--proxy-pac-url")) - qFatal("--proxy-pac-url argument is not passed."); + qFatal("--proxy-pac-url argument is not passed. Use ctest or set QTWEBENGINE_CHROMIUM_FLAGS"); ProxyServer proxyServer1; + QSignalSpy proxySpy1(&proxyServer1, &ProxyServer::requestReceived); proxyServer1.setPort(5551); proxyServer1.run(); - QSignalSpy proxySpy1(&proxyServer1, &ProxyServer::requestReceived); ProxyServer proxyServer2; + QSignalSpy proxySpy2(&proxyServer2, &ProxyServer::requestReceived); proxyServer2.setPort(5552); proxyServer2.run(); - QSignalSpy proxySpy2(&proxyServer2, &ProxyServer::requestReceived); QTRY_VERIFY2(proxyServer1.isListening(), "Could not setup proxy server 1"); QTRY_VERIFY2(proxyServer2.isListening(), "Could not setup proxy server 2"); diff --git a/tests/auto/widgets/qwebenginedownloadrequest/CMakeLists.txt b/tests/auto/widgets/qwebenginedownloadrequest/CMakeLists.txt new file mode 100644 index 000000000..3a8244c0f --- /dev/null +++ b/tests/auto/widgets/qwebenginedownloadrequest/CMakeLists.txt @@ -0,0 +1,11 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebenginedownloadrequest + SOURCES + tst_qwebenginedownloadrequest.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) diff --git a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp index a69ceaed0..f95c4ab33 100644 --- a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp +++ b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "../util.h" +#include #include #include diff --git a/tests/auto/widgets/qwebenginehistory/CMakeLists.txt b/tests/auto/widgets/qwebenginehistory/CMakeLists.txt new file mode 100644 index 000000000..b91281a45 --- /dev/null +++ b/tests/auto/widgets/qwebenginehistory/CMakeLists.txt @@ -0,0 +1,26 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebenginehistory + SOURCES + tst_qwebenginehistory.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::Util +) + +set(tst_qwebenginehistory_resource_files + "resources/page1.html" + "resources/page2.html" + "resources/page3.html" + "resources/page4.html" + "resources/page5.html" + "resources/page6.html" +) + +qt_internal_add_resource(tst_qwebenginehistory "tst_qwebenginehistory" + PREFIX + "/" + FILES + ${tst_qwebenginehistory_resource_files} +) + diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index 72a45379b..f67c2e03d 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -20,7 +20,7 @@ #include #include -#include "../util.h" +#include #include "qwebenginepage.h" #include "qwebengineview.h" #include "qwebenginehistory.h" diff --git a/tests/auto/widgets/qwebenginepage/CMakeLists.txt b/tests/auto/widgets/qwebenginepage/CMakeLists.txt new file mode 100644 index 000000000..bb31d9a97 --- /dev/null +++ b/tests/auto/widgets/qwebenginepage/CMakeLists.txt @@ -0,0 +1,61 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebenginepage + SOURCES + tst_qwebenginepage.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) + +get_target_property(sharedData Test::HttpServer SHARED_DATA) + +set(tst_qwebenginepage_resource_files + "resources/redirect.html" + "resources/bar.txt" + "resources/content.html" + "resources/dynamicFrame.html" + "resources/foo.txt" + "resources/frame_a.html" + "resources/frame_c.html" + "resources/framedindex.html" + "resources/fullscreen.html" + "resources/iframe.html" + "resources/iframe2.html" + "resources/iframe3.html" + "resources/image.png" + "resources/index.html" + "resources/lifecycle.html" + "resources/pasteimage.html" + "resources/path with spaces.txt" + "resources/reload.html" + "resources/script.html" + "resources/style.css" + "resources/test1.html" + "resources/test2.html" + "resources/testiframe.html" + "resources/testiframe2.html" + "resources/user.css" +) + +qt_internal_add_resource(tst_qwebenginepage "tst_qwebenginepage" + PREFIX + "/" + FILES + ${tst_qwebenginepage_resource_files} +) +set_source_files_properties("${sharedData}/notification.html" + PROPERTIES QT_RESOURCE_ALIAS "notification.html" +) +set(tst_qwebenginepage1_resource_files + "${sharedData}/notification.html" +) + +qt_internal_add_resource(tst_qwebenginepage "tst_qwebenginepage1" + PREFIX + "/shared" + FILES + ${tst_qwebenginepage1_resource_files} +) diff --git a/tests/auto/widgets/qwebenginepage/resources/image2.png b/tests/auto/widgets/qwebenginepage/resources/image2.png new file mode 100644 index 000000000..8d703640c Binary files /dev/null and b/tests/auto/widgets/qwebenginepage/resources/image2.png differ diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index a8d0e1ac8..fecda7c47 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -19,7 +19,7 @@ Boston, MA 02110-1301, USA. */ -#include "../util.h" +#include #include #include #include @@ -2245,10 +2245,15 @@ void tst_QWebEnginePage::setHtmlWithBaseURL() // This tests if baseUrl is indeed affecting the relative paths from resources. // As we are using a local file as baseUrl, its security origin should be able to load local resources. - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); - QDir::setCurrent(TESTS_SOURCE_DIR); + QDir::setCurrent(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()); + qDebug()<

hello world

"); @@ -2257,7 +2262,9 @@ void tst_QWebEnginePage::setHtmlWithBaseURL() // in few seconds, the image should be completey loaded QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); - page.setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR)); + page.setHtml(html, + QUrl::fromLocalFile( + QString("%1/foo.html").arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()))); QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished); QVERIFY(spyFinished.wait()); QCOMPARE(spy.count(), 1); @@ -3187,7 +3194,8 @@ void tst_QWebEnginePage::viewSourceURL_data() QTest::newRow("view-source:") << QUrl("view-source:") << true << QUrl("view-source:") << QUrl("about:blank") << QString("view-source:"); QTest::newRow("view-source:about:blank") << QUrl("view-source:about:blank") << true << QUrl("view-source:about:blank") << QUrl("about:blank") << QString("view-source:about:blank"); - QString localFilePath = QString("%1qwebenginepage/resources/test1.html").arg(TESTS_SOURCE_DIR); + QString localFilePath = + QString("%1/resources/test1.html").arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()); QUrl testLocalUrl = QUrl(QString("view-source:%1").arg(QUrl::fromLocalFile(localFilePath).toString())); QUrl testLocalUrlWithoutScheme = QUrl(QString("view-source:%1").arg(localFilePath)); QTest::newRow(testLocalUrl.toString().toStdString().c_str()) << testLocalUrl << true << testLocalUrl << QUrl::fromLocalFile(localFilePath) << QString("test1.html"); @@ -3203,8 +3211,12 @@ void tst_QWebEnginePage::viewSourceURL_data() void tst_QWebEnginePage::viewSourceURL() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); QFETCH(QUrl, userInputUrl); QFETCH(bool, loadSucceed); diff --git a/tests/auto/widgets/qwebengineprofile/CMakeLists.txt b/tests/auto/widgets/qwebengineprofile/CMakeLists.txt new file mode 100644 index 000000000..744f44405 --- /dev/null +++ b/tests/auto/widgets/qwebengineprofile/CMakeLists.txt @@ -0,0 +1,11 @@ +include(../../httpserver/httpserver.cmake) +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebengineprofile + SOURCES + tst_qwebengineprofile.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::HttpServer + Test::Util +) diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index eb692f351..64c763693 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "../util.h" +#include #include #include #include @@ -198,7 +198,7 @@ public: private: void onNewRequest(HttpReqRep *rr) { - const QDir resourceDir(TESTS_SOURCE_DIR "qwebengineprofile/resources"); + const QDir resourceDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + "/resources"); QString path = rr->requestPath(); path.remove(0, 1); diff --git a/tests/auto/widgets/qwebenginescript/CMakeLists.txt b/tests/auto/widgets/qwebenginescript/CMakeLists.txt new file mode 100644 index 000000000..2e93894d9 --- /dev/null +++ b/tests/auto/widgets/qwebenginescript/CMakeLists.txt @@ -0,0 +1,26 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebenginescript + SOURCES + tst_qwebenginescript.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::Util +) + +set(tst_qwebenginescript_resource_files + "resources/test_iframe_inner.html" + "resources/test_iframe_main.html" + "resources/test_iframe_outer.html" + "resources/test_window_open.html" + "resources/title_a.html" + "resources/title_b.html" + "resources/webChannelWithBadString.html" +) + +qt_add_resource(tst_qwebenginescript "tst_qwebenginescript" + PREFIX + "/" + FILES + ${tst_qwebenginescript_resource_files} +) diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index c141c0754..ca2f0cab9 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -25,7 +25,7 @@ #include #include #include -#include "../util.h" +#include #if QT_CONFIG(webengine_webchannel) #include #endif diff --git a/tests/auto/widgets/qwebenginesettings/CMakeLists.txt b/tests/auto/widgets/qwebenginesettings/CMakeLists.txt new file mode 100644 index 000000000..f5ec3441e --- /dev/null +++ b/tests/auto/widgets/qwebenginesettings/CMakeLists.txt @@ -0,0 +1,9 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebenginesettings + SOURCES + tst_qwebenginesettings.cpp + LIBRARIES + Qt::WebEngineWidgets + Test::Util +) diff --git a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp index a7c3ccb3c..77e46b0bf 100644 --- a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp +++ b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp @@ -17,7 +17,7 @@ Boston, MA 02110-1301, USA. */ -#include "../util.h" +#include #include diff --git a/tests/auto/widgets/qwebengineview/CMakeLists.txt b/tests/auto/widgets/qwebengineview/CMakeLists.txt new file mode 100644 index 000000000..0f4fe9327 --- /dev/null +++ b/tests/auto/widgets/qwebengineview/CMakeLists.txt @@ -0,0 +1,29 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_qwebengineview + SOURCES + tst_qwebengineview.cpp + LIBRARIES + Qt::WebEngineWidgets + Qt::WebEngineCorePrivate + Qt::GuiPrivate + Qt::QuickWidgets + Test::Util +) + +set(tst_qwebengineview_resource_files + "resources/dummy.html" + "resources/frame_a.html" + "resources/image2.png" + "resources/index.html" + "resources/input_types.html" + "resources/keyboardEvents.html" + "resources/scrolltest_page.html" +) + +qt_add_resource(tst_qwebengineview "tst_qwebengineview" + PREFIX + "/" + FILES + ${tst_qwebengineview_resource_files} +) diff --git a/tests/auto/widgets/qwebengineview/resources/test.swf b/tests/auto/widgets/qwebengineview/resources/test.swf new file mode 100644 index 000000000..895298271 Binary files /dev/null and b/tests/auto/widgets/qwebengineview/resources/test.swf differ diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 284f84d9f..2673c0d33 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -18,10 +18,9 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +#include #include -#include "../util.h" - +#include #include #include #include @@ -363,17 +362,21 @@ void tst_QWebEngineView::reusePage_data() void tst_QWebEngineView::reusePage() { - if (!QDir(TESTS_SOURCE_DIR).exists()) - W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); + if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists()) + W_QSKIP(QString("This test requires access to resources found in '%1'") + .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()) + .toLatin1() + .constData(), + SkipAll); - QDir::setCurrent(TESTS_SOURCE_DIR); + QDir::setCurrent(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()); QFETCH(QString, html); QWebEngineView* view1 = new QWebEngineView; QPointer page = new QWebEnginePage; view1->setPage(page.data()); page.data()->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true); - page->setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR)); + page->setHtml(html, QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath())); if (html.contains("")) { // some reasonable time for the PluginStream to feed test.swf to flash and start painting QSignalSpy spyFinished(view1, &QWebEngineView::loadFinished); @@ -3193,8 +3196,10 @@ void tst_QWebEngineView::webUIURLs_data() QTest::newRow("usb-internals") << QUrl("chrome://usb-internals") << false; QTest::newRow("user-actions") << QUrl("chrome://user-actions") << true; QTest::newRow("version") << QUrl("chrome://version") << false; +#if QT_CONFIG(webengine_webrtc) QTest::newRow("webrtc-internals") << QUrl("chrome://webrtc-internals") << true; QTest::newRow("webrtc-logs") << QUrl("chrome://webrtc-logs") << true; +#endif } void tst_QWebEngineView::webUIURLs() diff --git a/tests/auto/widgets/resources/image2.png b/tests/auto/widgets/resources/image2.png deleted file mode 100644 index 8d703640c..000000000 Binary files a/tests/auto/widgets/resources/image2.png and /dev/null differ diff --git a/tests/auto/widgets/resources/test.swf b/tests/auto/widgets/resources/test.swf deleted file mode 100644 index 895298271..000000000 Binary files a/tests/auto/widgets/resources/test.swf and /dev/null differ diff --git a/tests/auto/widgets/schemes/CMakeLists.txt b/tests/auto/widgets/schemes/CMakeLists.txt new file mode 100644 index 000000000..446ae5751 --- /dev/null +++ b/tests/auto/widgets/schemes/CMakeLists.txt @@ -0,0 +1,7 @@ +qt_internal_add_test(tst_schemes + SOURCES + tst_schemes.cpp + LIBRARIES + Qt::WebEngineWidgets +) + diff --git a/tests/auto/widgets/shutdown/CMakeLists.txt b/tests/auto/widgets/shutdown/CMakeLists.txt new file mode 100644 index 000000000..12ca27c3d --- /dev/null +++ b/tests/auto/widgets/shutdown/CMakeLists.txt @@ -0,0 +1,6 @@ +qt_internal_add_test(tst_shutdown + SOURCES + tst_shutdown.cpp + LIBRARIES + Qt::WebEngineWidgets +) diff --git a/tests/auto/widgets/touchinput/CMakeLists.txt b/tests/auto/widgets/touchinput/CMakeLists.txt new file mode 100644 index 000000000..82e3fca4a --- /dev/null +++ b/tests/auto/widgets/touchinput/CMakeLists.txt @@ -0,0 +1,10 @@ +include(../../util/util.cmake) + +qt_internal_add_test(tst_touchinput + SOURCES + tst_touchinput.cpp + LIBRARIES + Qt::WebEngineWidgets + Qt::GuiPrivate + Test::Util +) diff --git a/tests/auto/widgets/touchinput/tst_touchinput.cpp b/tests/auto/widgets/touchinput/tst_touchinput.cpp index 359b11eb2..d60fd1d7b 100644 --- a/tests/auto/widgets/touchinput/tst_touchinput.cpp +++ b/tests/auto/widgets/touchinput/tst_touchinput.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "../util.h" +#include #include #include diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h deleted file mode 100644 index 3be9a91b9..000000000 --- a/tests/auto/widgets/util.h +++ /dev/null @@ -1,242 +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: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$ -** -****************************************************************************/ - -// Functions and macros that really need to be in QTestLib - -#if 0 -#pragma qt_no_master_include -#endif - -#include -#include -#include -#include -#include - -#if !defined(TESTS_SOURCE_DIR) -#define TESTS_SOURCE_DIR "" -#endif - -// Disconnect signal on destruction. -class ScopedConnection -{ -public: - ScopedConnection(QMetaObject::Connection connection) : m_connection(std::move(connection)) { } - ~ScopedConnection() { QObject::disconnect(m_connection); } - -private: - QMetaObject::Connection m_connection; -}; - -/** - * Just like QSignalSpy but facilitates sync and async - * signal emission. For example if you want to verify that - * page->foo() emitted a signal, it could be that the - * implementation decides to emit the signal asynchronously - * - in which case we want to spin a local event loop until - * emission - or that the call to foo() emits it right away. - */ -class SignalBarrier : private QSignalSpy -{ -public: - SignalBarrier(const QObject* obj, const char* aSignal) - : QSignalSpy(obj, aSignal) - { } - - bool ensureSignalEmitted() - { - bool result = count() > 0; - if (!result) - result = wait(); - clear(); - return result; - } -}; - -template -struct CallbackWrapper { - QPointer p; - void operator()(const T& result) { - if (p) - (*p)(result); - } -}; - -template -class CallbackSpy: public QObject { -public: - CallbackSpy() : called(false) { - timeoutTimer.setSingleShot(true); - QObject::connect(&timeoutTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); - } - - T waitForResult(int timeout = 20000) { - const int step = 1000; - int elapsed = 0; - while (elapsed < timeout && !called) { - timeoutTimer.start(step); - eventLoop.exec(); - elapsed += step; - } - return result; - } - - bool wasCalled() const { - return called; - } - - void operator()(const T &result) { - this->result = result; - called = true; - eventLoop.quit(); - } - - CallbackWrapper > ref() - { - CallbackWrapper > wrapper = {this}; - return wrapper; - } - -private: - Q_DISABLE_COPY(CallbackSpy) - bool called; - QTimer timeoutTimer; - QEventLoop eventLoop; - T result; -}; - -static inline QString toPlainTextSync(QWebEnginePage *page) -{ - CallbackSpy spy; - page->toPlainText(spy.ref()); - return spy.waitForResult(); -} - -static inline QString toHtmlSync(QWebEnginePage *page) -{ - CallbackSpy spy; - page->toHtml(spy.ref()); - return spy.waitForResult(); -} - -static inline bool findTextSync(QWebEnginePage *page, const QString &subString) -{ - CallbackSpy spy; - page->findText(subString, {}, spy.ref()); - return spy.waitForResult(); -} - -static inline QVariant evaluateJavaScriptSync(QWebEnginePage *page, const QString &script) -{ - CallbackSpy spy; - page->runJavaScript(script, spy.ref()); - return spy.waitForResult(); -} - -static inline QVariant evaluateJavaScriptSyncInWorld(QWebEnginePage *page, const QString &script, int worldId) -{ - CallbackSpy spy; - page->runJavaScript(script, worldId, spy.ref()); - return spy.waitForResult(); -} - -static inline QUrl baseUrlSync(QWebEnginePage *page) -{ - CallbackSpy spy; - page->runJavaScript("document.baseURI", spy.ref()); - return spy.waitForResult().toUrl(); -} - -static inline bool loadSync(QWebEnginePage *page, const QUrl &url, bool ok = true) -{ - QSignalSpy spy(page, &QWebEnginePage::loadFinished); - page->load(url); - return (!spy.empty() || spy.wait(20000)) && (spy.front().value(0).toBool() == ok); -} - -static inline bool loadSync(QWebEngineView *view, const QUrl &url, bool ok = true) -{ - return loadSync(view->page(), url, ok); -} - -static inline QPoint elementCenter(QWebEnginePage *page, const QString &id) -{ - const QString jsCode( - "(function(){" - " var elem = document.getElementById('" + id + "');" - " var rect = elem.getBoundingClientRect();" - " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];" - "})()"); - QVariantList rectList = evaluateJavaScriptSync(page, jsCode).toList(); - - if (rectList.count() != 2) { - qWarning("elementCenter failed."); - return QPoint(); - } - - return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt()); -} - -static inline QRect elementGeometry(QWebEnginePage *page, const QString &id) -{ - const QString jsCode( - "(function() {" - " var elem = document.getElementById('" + id + "');" - " var rect = elem.getBoundingClientRect();" - " return [rect.left, rect.top, rect.right, rect.bottom];" - "})()"); - QVariantList coords = evaluateJavaScriptSync(page, jsCode).toList(); - - if (coords.count() != 4) { - qWarning("elementGeometry faield."); - return QRect(); - } - - return QRect(coords[0].toInt(), coords[1].toInt(), coords[2].toInt(), coords[3].toInt()); -} - - -#define W_QSKIP(a, b) QSKIP(a) - -#define W_QTEST_MAIN(TestObject, params) \ -int main(int argc, char *argv[]) \ -{ \ - QList w_argv(argc); \ - for (int i = 0; i < argc; ++i) \ - w_argv[i] = argv[i]; \ - for (int i = 0; i < params.size(); ++i) \ - w_argv.append(params[i].data()); \ - int w_argc = w_argv.size(); \ - \ - QApplication app(w_argc, const_cast(w_argv.data())); \ - app.setAttribute(Qt::AA_Use96Dpi, true); \ - QTEST_DISABLE_KEYPAD_NAVIGATION \ - TestObject tc; \ - QTEST_SET_MAIN_SOURCE_PATH \ - return QTest::qExec(&tc, argc, argv); \ -} -- cgit v1.2.3