summaryrefslogtreecommitdiffstats
path: root/tests/quicktestbrowser/main.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-09-25 13:27:58 +0200
committerKai Koehne <kai.koehne@theqtcompany.com>2015-10-19 08:37:17 +0000
commit38a426f21c0d6e47bdc05e5541b79c48cf967a0c (patch)
tree34769fbf91f69a27316fa09a9183f137e874c008 /tests/quicktestbrowser/main.cpp
parentd9d1cc3ec8931cecc0b0dcb5d5d184cdb53ff434 (diff)
Do not require to subclass/install QWebEngineCookieStoreClient
The class has only setters and getters, except for the virtual acceptCookie method. By replacing this method with a setCookieFilter callback we can avoid the need of users to subclass the client. Change-Id: Id78c01fc103b8d9cc267594527239b598e8975f1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'tests/quicktestbrowser/main.cpp')
-rw-r--r--tests/quicktestbrowser/main.cpp29
1 files changed, 8 insertions, 21 deletions
diff --git a/tests/quicktestbrowser/main.cpp b/tests/quicktestbrowser/main.cpp
index 166da4d5b..167f67dc3 100644
--- a/tests/quicktestbrowser/main.cpp
+++ b/tests/quicktestbrowser/main.cpp
@@ -69,24 +69,6 @@ static QUrl startupUrl()
return QUrl(QStringLiteral("http://qt.io/"));
}
-class CookieClient: public QWebEngineCookieStoreClient
-{
- QMetaProperty m_settingProperty;
- const QObject *m_object;
-public:
- CookieClient(const QObject *object)
- : m_object(object)
- {
- const QMetaObject *rootMeta = object->metaObject();
- int index = rootMeta->indexOfProperty("thirdPartyCookiesEnabled");
- Q_ASSERT(index != -1);
- m_settingProperty = rootMeta->property(index);
- }
- virtual bool acceptCookieFromUrl(const QByteArray &, const QUrl &) {
- return m_settingProperty.read(m_object).toBool();
- }
-};
-
int main(int argc, char **argv)
{
Application app(argc, argv);
@@ -110,10 +92,15 @@ int main(int argc, char **argv)
"}")
, QUrl());
QObject *profile = component.create();
- CookieClient client(rootObject);
- QMetaObject::invokeMethod(profile, "setCookieStoreClient", Q_ARG(QWebEngineCookieStoreClient*, &client));
const QMetaObject *rootMeta = rootObject->metaObject();
- int index = rootMeta->indexOfProperty("testProfile");
+ QWebEngineCookieStoreClient *client = 0;
+ QMetaObject::invokeMethod(profile, "cookieStoreClient", Q_RETURN_ARG(QWebEngineCookieStoreClient*, client));
+ int index = rootMeta->indexOfProperty("thirdPartyCookiesEnabled");
+ Q_ASSERT(index != -1);
+ QMetaProperty thirdPartyCookiesProperty = rootMeta->property(index);
+ client->setCookieFilter([rootObject,&thirdPartyCookiesProperty](const QWebEngineCookieStoreClient::FilterRequest&){ return thirdPartyCookiesProperty.read(rootObject).toBool(); });
+
+ index = rootMeta->indexOfProperty("testProfile");
Q_ASSERT(index != -1);
QMetaProperty profileProperty = rootMeta->property(index);
profileProperty.write(rootObject, qVariantFromValue(profile));