diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-02-20 13:41:44 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-02-24 10:23:09 +0100 |
commit | a9e08e71152095403be8fb63d3223fdf10e9da9c (patch) | |
tree | 7b50a53cf6a6d1045b96f69d5e6ec9359f79b1fd | |
parent | d579912b31d7cfa7b0b216916fbbf3eb632a9d9d (diff) |
Fix web_engine_custom_scheme.py
Introduce a flag to distinguish timeouts from successful loading.
Register the scheme properly and set "Path" syntax, fixing the warning:
Please register the custom scheme 'testpy' via QWebEngineUrlScheme::registerScheme() before installing the custom scheme handler.
Add required initializations of QWebEngine and embed
the view into a top level widget, as using a QWebEngineView as a top
level on Windows hangs.
Change-Id: Id39a6b14606795216994928ad82f60435f4caaca
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py b/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py index 1117b553e..7fc879fa9 100644 --- a/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py +++ b/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py @@ -34,10 +34,12 @@ import unittest sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) -from PySide2.QtCore import QBuffer, QTimer -from PySide2.QtWidgets import QApplication +from PySide2.QtCore import QBuffer, Qt, QTimer +from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout +from PySide2.QtWebEngine import QtWebEngine from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile -from PySide2.QtWebEngineCore import QWebEngineUrlSchemeHandler +from PySide2.QtWebEngineCore import (QWebEngineUrlScheme, + QWebEngineUrlSchemeHandler) import py3kcompat as py3k class TestSchemeHandler(QWebEngineUrlSchemeHandler): @@ -51,19 +53,44 @@ class TestSchemeHandler(QWebEngineUrlSchemeHandler): self.buffer.aboutToClose.connect(self.buffer.deleteLater) request.reply(py3k.b("text/plain;charset=utf-8"), self.buffer) + class MainTest(unittest.TestCase): def test_SchemeHandlerRedirect(self): + self._loaded = False + QApplication.setAttribute(Qt.AA_ShareOpenGLContexts); + QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) + QtWebEngine.initialize() app = QApplication([]) + + scheme_name = py3k.b("testpy") + scheme = QWebEngineUrlScheme(scheme_name) + scheme.setSyntax(QWebEngineUrlScheme.Syntax.Path) + QWebEngineUrlScheme.registerScheme(scheme) handler = TestSchemeHandler() profile = QWebEngineProfile.defaultProfile() - profile.installUrlSchemeHandler(py3k.b("testpy"), handler) + profile.installUrlSchemeHandler(scheme_name, handler) + + top_level_widget = QWidget() + top_level_widget.setWindowTitle('web_engine_custom_scheme.py') + top_level_widget.resize(400, 400) + layout = QVBoxLayout(top_level_widget) view = QWebEngineView() - view.loadFinished.connect(app.quit) + layout.addWidget(view) + + view.loadFinished.connect(self._slot_loaded) QTimer.singleShot(5000, app.quit) - view.show() + + top_level_widget.show() view.load("testpy:hello") app.exec_() + + self.assertTrue(self._loaded) self.assertEqual(view.url(), "testpy:goodbye") + def _slot_loaded(self): + self._loaded = True + QApplication.quit() + + if __name__ == '__main__': unittest.main() |