File indexing completed on 2024-05-19 05:01:16
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2018 Stefano Crocco <stefano.crocco@alice.it> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #ifndef TESTWEBENGINEPARTCOOKIEJARKIO_H 0009 #define TESTWEBENGINEPARTCOOKIEJARKIO_H 0010 0011 #include <QObject> 0012 #include <QDateTime> 0013 #include <QDBusError> 0014 0015 class QWebEngineCookieStore; 0016 class WebEnginePartCookieJarKIO; 0017 class QNetworkCookie; 0018 class QWebEngineProfile; 0019 class QDBusInterface; 0020 0021 class TestWebEnginePartCookieJarKIO : public QObject 0022 { 0023 Q_OBJECT 0024 0025 private: 0026 0027 struct CookieData { 0028 QString name; 0029 QString value; 0030 QString domain; 0031 QString path; 0032 QString host; 0033 QDateTime expiration; 0034 bool secure; 0035 0036 QNetworkCookie cookie() const; 0037 }; 0038 0039 private Q_SLOTS: 0040 0041 void init(); 0042 void initTestCase(); 0043 void cleanup(); 0044 void testCookieAddedToStoreAreAddedToKCookieServer_data(); 0045 void testCookieAddedToStoreAreAddedToKCookieServer(); 0046 void testCookieRemovedFromStoreAreRemovedFromKCookieServer_data(); 0047 void testCookieRemovedFromStoreAreRemovedFromKCookieServer(); 0048 void testPersistentCookiesAreAddedToStoreOnCreation(); 0049 void testSessionCookiesAreNotAddedToStoreOnCreation(); 0050 0051 private: 0052 0053 /** 0054 * @brief Adds a cookie to KCookieServer 0055 * 0056 * The cookie is supposed to be in `QWebEngineStore` "format", that is its domain must not be empty; 0057 * a domain not starting with a dot means that the domain field wasn't given in the `Set-Cookie` header. 0058 * 0059 * @param _cookie the cookie to add 0060 * @param host the host where the cookie come from 0061 * @return QDBusError the error returned by DBus when adding the cookie. If no error occurred, this object 0062 * will be invalid 0063 */ 0064 QDBusError addCookieToKCookieServer(const QNetworkCookie &_cookie, const QString &host); 0065 void deleteCookies(const QList<CookieData> &cookies); 0066 QList<CookieData> findTestCookies(); 0067 0068 QString m_cookieName; 0069 QWebEngineCookieStore *m_store; 0070 WebEnginePartCookieJarKIO *m_jar; 0071 QWebEngineProfile *m_profile; 0072 QDBusInterface *m_server; 0073 }; 0074 0075 #endif // TESTWEBENGINEPARTCOOKIEJARKIO_H