From ba04130a9ece05644f35ebda12d319e86d71d020 Mon Sep 17 00:00:00 2001 From: Shyamnath Premnadh Date: Wed, 4 May 2022 13:33:57 +0200 Subject: webenginecore: QWebEngineCookieStore setCookieFilter - added tests for the setCookieFilter(...) Task-number: PYSIDE-1912 Change-Id: I484725072195846e7777fc577d167ff9ed374d59 Reviewed-by: Friedemann Kleint (cherry picked from commit 96715550f3d980dc5554c67a3660e94b6a9a3e76) Reviewed-by: Qt Cherry-pick Bot --- .../pyside6/PySide6/QtWebEngineCore/CMakeLists.txt | 1 + .../QtWebEngineCore/typesystem_webenginecore.xml | 8 ++- sources/pyside6/PySide6/glue/qtwebenginecore.cpp | 55 +++++++++++++++++ .../pyside6/tests/QtWebEngineCore/CMakeLists.txt | 1 + .../QtWebEngineCore/qwebenginecookiestore_test.py | 71 ++++++++++++++++++++++ .../tests/QtWebEngineCore/resources/index.html | 12 ++++ 6 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 sources/pyside6/PySide6/glue/qtwebenginecore.cpp create mode 100644 sources/pyside6/tests/QtWebEngineCore/qwebenginecookiestore_test.py create mode 100644 sources/pyside6/tests/QtWebEngineCore/resources/index.html diff --git a/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt b/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt index f6a3fb35c..0da2c6c7b 100644 --- a/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt +++ b/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt @@ -4,6 +4,7 @@ set(QtWebEngineCore_SRC ${QtWebEngineCore_GEN_DIR}/qwebenginecertificateerror_wrapper.cpp ${QtWebEngineCore_GEN_DIR}/qwebenginecontextmenurequest_wrapper.cpp ${QtWebEngineCore_GEN_DIR}/qwebenginecookiestore_wrapper.cpp +${QtWebEngineCore_GEN_DIR}/qwebenginecookiestore_filterrequest_wrapper.cpp ${QtWebEngineCore_GEN_DIR}/qwebenginedownloadrequest_wrapper.cpp ${QtWebEngineCore_GEN_DIR}/qwebenginefullscreenrequest_wrapper.cpp ${QtWebEngineCore_GEN_DIR}/qwebenginehistory_wrapper.cpp diff --git a/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml b/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml index 22ff8b777..478621736 100644 --- a/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml +++ b/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml @@ -46,7 +46,13 @@ - + + + + + + diff --git a/sources/pyside6/PySide6/glue/qtwebenginecore.cpp b/sources/pyside6/PySide6/glue/qtwebenginecore.cpp new file mode 100644 index 000000000..41fe99440 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtwebenginecore.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// @snippet qwebenginecookiestore-setcookiefilter +auto callable = %PYARG_1; +auto callback = [callable](const QWebEngineCookieStore::FilterRequest& filterRequest) -> bool +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, + %CONVERTTOPYTHON[QWebEngineCookieStore::FilterRequest](filterRequest)); + Py_INCREF(callable); + PyObject* ret = PyObject_CallObject(callable, arglist); + Py_DECREF(callable); + return ret; + +}; +%CPPSELF.%FUNCTION_NAME(callback); +// @snippet qwebenginecookiestore-setcookiefilter diff --git a/sources/pyside6/tests/QtWebEngineCore/CMakeLists.txt b/sources/pyside6/tests/QtWebEngineCore/CMakeLists.txt index 06a9e9cdf..e7cdb732e 100644 --- a/sources/pyside6/tests/QtWebEngineCore/CMakeLists.txt +++ b/sources/pyside6/tests/QtWebEngineCore/CMakeLists.txt @@ -27,3 +27,4 @@ ############################################################################# PYSIDE_TEST(web_engine_custom_scheme.py) +PYSIDE_TEST(qwebenginecookiestore_test.py) diff --git a/sources/pyside6/tests/QtWebEngineCore/qwebenginecookiestore_test.py b/sources/pyside6/tests/QtWebEngineCore/qwebenginecookiestore_test.py new file mode 100644 index 000000000..36e0f328d --- /dev/null +++ b/sources/pyside6/tests/QtWebEngineCore/qwebenginecookiestore_test.py @@ -0,0 +1,71 @@ +############################################################################# +## +## Copyright (C) 2022 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import QUrl +from PySide6.QtWidgets import QApplication +from PySide6.QtWebEngineWidgets import QWebEngineView + +from helper.usesqapplication import UsesQApplication + + +class TestQWebEngineCookieStore(UsesQApplication): + def testBasicFilter(self): + src_dir = Path(__file__).resolve().parent + html_path = src_dir / "resources" / "index.html" + view = QWebEngineView() + cookie_store = view.page().profile().cookieStore() + firstPartyUrlPaths = [] + + def cookie_filter(request): + nonlocal firstPartyUrlPaths + firstPartyUrlPaths.append(Path(request.firstPartyUrl.toLocalFile())) + return False + + cookie_store.setCookieFilter(cookie_filter) + view.loadFinished.connect(self._slot_loaded) + view.load(QUrl.fromLocalFile(html_path)) + view.show() + self.app.exec() + + self.assertEqual(len(firstPartyUrlPaths), 2) + self.assertListEqual(firstPartyUrlPaths, [html_path, html_path]) + + def _slot_loaded(self): + QApplication.quit() + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWebEngineCore/resources/index.html b/sources/pyside6/tests/QtWebEngineCore/resources/index.html new file mode 100644 index 000000000..4c020b714 --- /dev/null +++ b/sources/pyside6/tests/QtWebEngineCore/resources/index.html @@ -0,0 +1,12 @@ + + + + + + + -- cgit v1.2.3