summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp33
-rw-r--r--tests/quicktestbrowser/BrowserWindow.qml8
-rw-r--r--tests/quicktestbrowser/main.cpp22
3 files changed, 62 insertions, 1 deletions
diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
index 930c208ee..913614df2 100644
--- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
+++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
@@ -51,6 +51,7 @@ private Q_SLOTS:
void cookieSignals();
void setAndDeleteCookie();
void batchCookieTasks();
+ void basicFilter();
private:
QWebEngineProfile m_profile;
@@ -186,5 +187,37 @@ void tst_QWebEngineCookieStore::batchCookieTasks()
QTRY_COMPARE(cookieRemovedSpy.count(), 4);
}
+void tst_QWebEngineCookieStore::basicFilter()
+{
+ QWebEnginePage page(&m_profile);
+ QWebEngineCookieStore *client = m_profile.cookieStore();
+
+ QAtomicInt accessTested = 0;
+ client->setCookieFilter([&](QWebEngineCookieStore::FilterRequest &){ ++accessTested; });
+
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
+ QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
+
+ page.load(QUrl("qrc:///resources/index.html"));
+
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
+ QTRY_COMPARE(cookieAddedSpy.count(), 2);
+ QTRY_COMPARE(accessTested.loadAcquire(), 2);
+
+ client->deleteAllCookies();
+ QTRY_COMPARE(cookieRemovedSpy.count(), 2);
+
+ client->setCookieFilter([&](QWebEngineCookieStore::FilterRequest &request){ ++accessTested; request.accepted = false; });
+ page.triggerAction(QWebEnginePage::ReloadAndBypassCache);
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
+ QTRY_COMPARE(accessTested.loadAcquire(), 4);
+ // Test cookies are NOT added:
+ QTest::qWait(100);
+ QCOMPARE(cookieAddedSpy.count(), 2);
+}
+
QTEST_MAIN(tst_QWebEngineCookieStore)
#include "tst_qwebenginecookiestore.moc"
diff --git a/tests/quicktestbrowser/BrowserWindow.qml b/tests/quicktestbrowser/BrowserWindow.qml
index 2d8807e8c..22f98e1c5 100644
--- a/tests/quicktestbrowser/BrowserWindow.qml
+++ b/tests/quicktestbrowser/BrowserWindow.qml
@@ -66,6 +66,7 @@ ApplicationWindow {
property alias javaScriptEnabled: javaScriptEnabled.checked;
property alias errorPageEnabled: errorPageEnabled.checked;
property alias pluginsEnabled: pluginsEnabled.checked;
+ property alias thirdPartyCookiesEnabled: thirdPartyCookiesEnabled.checked;
}
// Make sure the Qt.WindowFullscreenButtonHint is set on OS X.
@@ -241,6 +242,13 @@ ApplicationWindow {
checked: true
}
MenuItem {
+ id: thirdPartyCookiesEnabled
+ text: "Third party cookies enabled"
+ checkable: true
+ checked: true
+ onToggled: applicationRoot.thirdPartyCookiesEnabled = checked
+ }
+ MenuItem {
id: offTheRecordEnabled
text: "Off The Record"
checkable: true
diff --git a/tests/quicktestbrowser/main.cpp b/tests/quicktestbrowser/main.cpp
index 3f513f6a6..d56841974 100644
--- a/tests/quicktestbrowser/main.cpp
+++ b/tests/quicktestbrowser/main.cpp
@@ -70,7 +70,27 @@ int main(int argc, char **argv)
Utils utils;
appEngine.rootContext()->setContextProperty("utils", &utils);
appEngine.load(QUrl("qrc:/ApplicationRoot.qml"));
- QMetaObject::invokeMethod(appEngine.rootObjects().first(), "load", Q_ARG(QVariant, startupUrl()));
+
+ QObject *rootObject = appEngine.rootObjects().first();
+
+ QQuickWebEngineProfile *profile = new QQuickWebEngineProfile(rootObject);
+
+ const QMetaObject *rootMeta = rootObject->metaObject();
+ int index = rootMeta->indexOfProperty("thirdPartyCookiesEnabled");
+ Q_ASSERT(index != -1);
+ QMetaProperty thirdPartyCookiesProperty = rootMeta->property(index);
+ profile->cookieStore()->setCookieFilter(
+ [rootObject,&thirdPartyCookiesProperty](QWebEngineCookieStore::FilterRequest &request)
+ {
+ request.accepted = !request.thirdParty || thirdPartyCookiesProperty.read(rootObject).toBool();
+ });
+
+ index = rootMeta->indexOfProperty("testProfile");
+ Q_ASSERT(index != -1);
+ QMetaProperty profileProperty = rootMeta->property(index);
+ profileProperty.write(rootObject, qVariantFromValue(profile));
+
+ QMetaObject::invokeMethod(rootObject, "load", Q_ARG(QVariant, startupUrl()));
return app.exec();
}