aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-05-04 13:33:57 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-05-17 16:46:59 +0200
commit96715550f3d980dc5554c67a3660e94b6a9a3e76 (patch)
tree7b6dcbb197fe7de94daea3eb716eaacbf344a4c6 /sources
parent9a2a9bae00003f7dc0cea782bb10775aa25c8933 (diff)
webenginecore: QWebEngineCookieStore setCookieFilter
- added tests for the setCookieFilter(...) Task-number: PYSIDE-1912 Pick-to: 6.3 Change-Id: I484725072195846e7777fc577d167ff9ed374d59 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt1
-rw-r--r--sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml8
-rw-r--r--sources/pyside6/PySide6/glue/qtwebenginecore.cpp55
-rw-r--r--sources/pyside6/tests/QtWebEngineCore/CMakeLists.txt1
-rw-r--r--sources/pyside6/tests/QtWebEngineCore/qwebenginecookiestore_test.py71
-rw-r--r--sources/pyside6/tests/QtWebEngineCore/resources/index.html12
6 files changed, 147 insertions, 1 deletions
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 @@
<load-typesystem name="QtPrintSupport/typesystem_printsupport.xml" generate="no"/>
<load-typesystem name="QtWebChannel/typesystem_webchannel.xml" generate="no"/>
- <object-type name="QWebEngineCookieStore"/>
+ <object-type name="QWebEngineCookieStore">
+ <value-type name="FilterRequest" />
+ <add-function signature="setCookieFilter(PyCallable* @filterCallback@)">
+ <inject-code class="target" position="beginning" file="../glue/qtwebenginecore.cpp"
+ snippet="qwebenginecookiestore-setcookiefilter"/>
+ </add-function>
+ </object-type>
<value-type name="QWebEngineCertificateError">
<enum-type name="Type"/>
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 @@
+<html>
+ <head>
+ <script type="text/javascript">
+function setCookie() {
+ document.cookie = "test1"
+ document.cookie = "test2"
+}
+</script>
+ </head>
+ <body onload="setCookie()">
+ </body>
+</html>