diff options
Diffstat (limited to 'tests/auto/wasm')
-rw-r--r-- | tests/auto/wasm/fetchapi/tst_fetchapi.cpp | 2 | ||||
-rw-r--r-- | tests/auto/wasm/selenium/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/wasm/selenium/qwasmwindow.py | 57 | ||||
-rw-r--r-- | tests/auto/wasm/selenium/run.bat | 2 | ||||
-rw-r--r-- | tests/auto/wasm/selenium/tst_qwasmwindow_harness.cpp | 43 |
5 files changed, 98 insertions, 8 deletions
diff --git a/tests/auto/wasm/fetchapi/tst_fetchapi.cpp b/tests/auto/wasm/fetchapi/tst_fetchapi.cpp index 3dcd8dd916..e37316b2db 100644 --- a/tests/auto/wasm/fetchapi/tst_fetchapi.cpp +++ b/tests/auto/wasm/fetchapi/tst_fetchapi.cpp @@ -69,11 +69,9 @@ void tst_FetchApi::sendRequestOnMainThread() void tst_FetchApi::sendRequestOnBackgroundThread() { - QSKIP("Skip this test until we fix fetching from background threads."); QEventLoop mainEventLoop; BackgroundThread *backgroundThread = new BackgroundThread(); connect(backgroundThread, &BackgroundThread::finished, &mainEventLoop, &QEventLoop::quit); - connect(backgroundThread, &BackgroundThread::finished, backgroundThread, &QObject::deleteLater); backgroundThread->start(); mainEventLoop.exec(); diff --git a/tests/auto/wasm/selenium/CMakeLists.txt b/tests/auto/wasm/selenium/CMakeLists.txt index 335b6d23d9..445030878e 100644 --- a/tests/auto/wasm/selenium/CMakeLists.txt +++ b/tests/auto/wasm/selenium/CMakeLists.txt @@ -1,3 +1,5 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.16) project(tst_qwasmwindow_harness LANGUAGES CXX) diff --git a/tests/auto/wasm/selenium/qwasmwindow.py b/tests/auto/wasm/selenium/qwasmwindow.py index 260e9d2d24..df2d39f516 100644 --- a/tests/auto/wasm/selenium/qwasmwindow.py +++ b/tests/auto/wasm/selenium/qwasmwindow.py @@ -28,6 +28,24 @@ class WidgetTestCase(unittest.TestCase): self.addTypeEqualityFunc(Color, assert_colors_equal) self.addTypeEqualityFunc(Rect, assert_rects_equal) + # + # This is a manual test + # The reason is that the color readback works + # even if the display is incorrect + # + def test_native_widgets(self): + screen = Screen(self._driver, ScreenPosition.FIXED, + x=0, y=0, width=600, height=1200) + + w0 = Widget(self._driver, "w0", 1) + w0.show() + #time.sleep(3600) + color = w0.color_at(100, 150) + self.assertEqual(color.r, 255) + self.assertEqual(color.g, 255) + self.assertEqual(color.b, 255) + self.assertEqual(w0.hasFocus(), True) + def test_hasFocus_returnsFalse_whenSetNoFocusShowWasCalled(self): screen = Screen(self._driver, ScreenPosition.FIXED, x=0, y=0, width=600, height=1200) @@ -607,15 +625,30 @@ def clearWidgets(driver): ) class Widget: - def __init__(self, driver, name): + def __init__(self, driver, name, isNative=0): self.name=name self.driver=driver - self.driver.execute_script( - f''' - instance.createWidget('{self.name}'); - ''' - ) + if isNative == 0: + self.driver.execute_script( + f''' + instance.createWidget('{self.name}'); + ''' + ) + if isNative == 1: + self.driver.execute_script( + f''' + instance.createNativeWidget('{self.name}'); + ''' + ) + + if isNative == 1: + information = self.__window_information() + self.screen = Screen(self.driver, screen_name=information['screen']['name']) + + self._window_id = self.__window_information()['id'] + self.element = self.screen.find_element( + By.CSS_SELECTOR, f'#qt-window-{self._window_id}') def setNoFocusShow(self): self.driver.execute_script( @@ -641,6 +674,18 @@ class Widget: ''' ) + def color_at(self, x, y): + raw = self.driver.execute_script( + f''' + return arguments[0].querySelector('canvas') + .getContext('2d').getImageData({x}, {y}, 1, 1).data; + ''', self.element) + return Color(r=raw[0], g=raw[1], b=raw[2]) + + def __window_information(self): + information = call_instance_function(self.driver, 'windowInformation') + return next(filter(lambda e: e['title'] == "Dialog", information)) + class Window: def __init__(self, parent=None, rect=None, title=None, element=None, visible=True, opengl=0): diff --git a/tests/auto/wasm/selenium/run.bat b/tests/auto/wasm/selenium/run.bat index 031e0b13ab..56305c72c3 100644 --- a/tests/auto/wasm/selenium/run.bat +++ b/tests/auto/wasm/selenium/run.bat @@ -1,3 +1,5 @@ +:: Copyright (C) 2024 The Qt Company Ltd. +:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 :: :: The highest version of python that can be used is 3.11 :: Download from here: https://www.python.org/downloads/release/python-3118/ diff --git a/tests/auto/wasm/selenium/tst_qwasmwindow_harness.cpp b/tests/auto/wasm/selenium/tst_qwasmwindow_harness.cpp index 365fc74a34..75e23cecda 100644 --- a/tests/auto/wasm/selenium/tst_qwasmwindow_harness.cpp +++ b/tests/auto/wasm/selenium/tst_qwasmwindow_harness.cpp @@ -16,6 +16,10 @@ #include <QApplication> #include <QDialog> #include <QSysInfo> +#include <QTreeView> +#include <QFileSystemModel> +#include <QScrollArea> +#include <QVBoxLayout> #include <QOpenGLWindow> #include <QOpenGLFunctions> @@ -389,6 +393,7 @@ public: void make(const std::string &name) { auto widget = std::make_shared<TestWidget>(); + widget->setWindowTitle("Dialog"); auto *lineEdit = new QLineEdit(widget.get()); widget->setMinimumSize(200, 200); @@ -401,6 +406,38 @@ public: m_widgets[name] = widget; m_lineEdits[name] = lineEdit; } + void makeNative(const std::string &name) + { + auto widget = std::make_shared<TestWidget>(); + widget->setWindowTitle("Dialog"); + auto *lineEdit = new QLineEdit(); + + widget->setMinimumSize(200, 200); + widget->setMaximumSize(200, 200); + widget->setGeometry(0, m_widgetY, 200, 200); + m_widgetY += 200; + + lineEdit->setText("Hello world"); + + m_widgets[name] = widget; + m_lineEdits[name] = lineEdit; + + QFileSystemModel *model = new QFileSystemModel; + model->setRootPath(QDir::currentPath()); + + auto *scrollArea = new QScrollArea(); + auto *layout = new QVBoxLayout(widget.get()); + auto *treeView = new QTreeView(scrollArea); + treeView->setModel(model); + + layout->addWidget(lineEdit); + layout->addWidget(scrollArea); + + treeView->setAttribute(Qt::WA_NativeWindow); + scrollArea->setAttribute(Qt::WA_NativeWindow); + lineEdit->setAttribute(Qt::WA_NativeWindow); + widget->setAttribute(Qt::WA_NativeWindow); + } private: using TestWidgetPtr = std::shared_ptr<TestWidget>; @@ -503,6 +540,11 @@ void createWidget(const std::string &name) WidgetStorage::getInstance()->make(name); } +void createNativeWidget(const std::string &name) +{ + WidgetStorage::getInstance()->makeNative(name); +} + void setWidgetNoFocusShow(const std::string &name) { auto w = WidgetStorage::getInstance()->findWidget(name); @@ -678,6 +720,7 @@ EMSCRIPTEN_BINDINGS(qwasmwindow) emscripten::function("getOpenGLColorAt_0_0", &getOpenGLColorAt_0_0); emscripten::function("createWidget", &createWidget); + emscripten::function("createNativeWidget", &createNativeWidget); emscripten::function("setWidgetNoFocusShow", &setWidgetNoFocusShow); emscripten::function("showWidget", &showWidget); emscripten::function("activateWidget", &activateWidget); |