diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-20 15:44:34 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-24 09:16:16 +0100 |
commit | 57613ac99f6b1058c3e39ed15e6749351a9b5deb (patch) | |
tree | 5f811c35baa697e04c9bdcec4845fb3065291074 /sources/pyside2/tests | |
parent | 81914251b0aa8215a680adac76ffb372af9bd4f4 (diff) |
Add functions with callback of QWebEnginePage
Provide them as user-added functions using C++ lambdas.
Fixes: PYSIDE-946
Task-number: PYSIDE-1241
Change-Id: I9733bc98b3fc8b3bcf40ab4ce91ffdb84e385b93
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r-- | sources/pyside2/tests/QtWebEngineWidgets/fox.html | 7 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py | 49 |
2 files changed, 49 insertions, 7 deletions
diff --git a/sources/pyside2/tests/QtWebEngineWidgets/fox.html b/sources/pyside2/tests/QtWebEngineWidgets/fox.html new file mode 100644 index 000000000..da873b1cc --- /dev/null +++ b/sources/pyside2/tests/QtWebEngineWidgets/fox.html @@ -0,0 +1,7 @@ +<html> +<title>Title</title> +<meta name="description" content="PySide Test METADATA." /> +<body> +<p>The quick <b>brown</b> fox <i>jumps</i> over the lazy dog.</p> +</body> +</html> diff --git a/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py b/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py index a40e29887..c650a21d0 100644 --- a/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py +++ b/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py @@ -28,24 +28,59 @@ from __future__ import print_function +from functools import partial import os import sys import unittest -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) + +sys.path.append(os.path.dirname(TEST_DIR)) from init_paths import init_test_paths init_test_paths(False) -from PySide2 import QtWidgets -from PySide2 import QtWebEngineWidgets +from PySide2.QtCore import QCoreApplication, QSize, QUrl, Qt +from PySide2.QtWidgets import QApplication, QVBoxLayout, QWidget +from PySide2.QtWebEngineWidgets import QWebEnginePage, QWebEngineView + class MainTest(unittest.TestCase): def test_WebEngineView_findText_exists(self): - qApp = (QtWidgets.QApplication.instance() or - QtWidgets.QApplication([])) - view = QtWebEngineWidgets.QWebEngineView() - view.findText("nothing") + QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) + app = QApplication.instance() or QApplication() + top_level = QWidget() + layout = QVBoxLayout(top_level) + self._view = QWebEngineView() + self._view.loadFinished.connect(self.loaded) + self._view.load(QUrl.fromLocalFile(os.path.join(TEST_DIR, "fox.html"))) + self._view.setMinimumSize(QSize(400, 300)) + self._callback_count = 0 + layout.addWidget(self._view) + top_level.show() + app.exec_() + + def found_callback(self, found): + self.assertTrue(found) + self._callback_count += 1 + if self._callback_count == 2: + QCoreApplication.quit() + + def javascript_callback(self, result): + self.assertEqual(result, "Title") + self._callback_count += 1 + if self._callback_count == 2: + QCoreApplication.quit() + + def loaded(self, ok): + self.assertTrue(ok) + if not ok: + QCoreApplication.quit() + self._view.page().runJavaScript("document.title", 1, + partial(self.javascript_callback)) + self._view.findText("fox", QWebEnginePage.FindFlags(), + partial(self.found_callback)) + if __name__ == '__main__': unittest.main() |