summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-12-19 17:19:54 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-08 17:06:37 +0000
commit7473a43beff891c93a245620b6307f3a073dba28 (patch)
tree0dcf61d2cca0ee495a73f4f85f5df83b110e423c /tests/auto
parent8ef9f9faf09b7bae9ba548443434eb84b07c883c (diff)
Cleanup core API tests
Use in-memory profile and do not use qwebengineviews when all we need are qwebenginepages. Change-Id: I5798c761bccfc0b4bf2cf623e7db35f033bdfd84 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp35
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp54
2 files changed, 47 insertions, 42 deletions
diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
index 65d4ec295..930c208ee 100644
--- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
+++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -32,7 +32,6 @@
#include <QtWebEngineCore/qwebenginecookiestore.h>
#include <QtWebEngineWidgets/qwebenginepage.h>
#include <QtWebEngineWidgets/qwebengineprofile.h>
-#include <QtWebEngineWidgets/qwebengineview.h>
class tst_QWebEngineCookieStore : public QObject
{
@@ -52,6 +51,9 @@ private Q_SLOTS:
void cookieSignals();
void setAndDeleteCookie();
void batchCookieTasks();
+
+private:
+ QWebEngineProfile m_profile;
};
tst_QWebEngineCookieStore::tst_QWebEngineCookieStore()
@@ -68,6 +70,7 @@ void tst_QWebEngineCookieStore::init()
void tst_QWebEngineCookieStore::cleanup()
{
+ m_profile.cookieStore()->deleteAllCookies();
}
void tst_QWebEngineCookieStore::initTestCase()
@@ -80,15 +83,15 @@ void tst_QWebEngineCookieStore::cleanupTestCase()
void tst_QWebEngineCookieStore::cookieSignals()
{
- QWebEngineView view;
- QWebEngineCookieStore *client = view.page()->profile()->cookieStore();
- client->deleteAllCookies();
+ QWebEnginePage page(&m_profile);
+
+ QWebEngineCookieStore *client = m_profile.cookieStore();
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
- view.load(QUrl("qrc:///resources/index.html"));
+ page.load(QUrl("qrc:///resources/index.html"));
QTRY_COMPARE(loadSpy.count(), 1);
QVariant success = loadSpy.takeFirst().takeFirst();
@@ -110,11 +113,10 @@ void tst_QWebEngineCookieStore::cookieSignals()
void tst_QWebEngineCookieStore::setAndDeleteCookie()
{
- QWebEngineView view;
- QWebEngineCookieStore *client = view.page()->profile()->cookieStore();
- client->deleteAllCookies();
+ QWebEnginePage page(&m_profile);
+ QWebEngineCookieStore *client = m_profile.cookieStore();
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
@@ -130,7 +132,7 @@ void tst_QWebEngineCookieStore::setAndDeleteCookie()
QTRY_COMPARE(cookieAddedSpy.count(),2);
client->deleteCookie(cookie1);
- view.load(QUrl("qrc:///resources/content.html"));
+ page.load(QUrl("qrc:///resources/content.html"));
QTRY_COMPARE(loadSpy.count(), 1);
QVariant success = loadSpy.takeFirst().takeFirst();
@@ -151,11 +153,10 @@ void tst_QWebEngineCookieStore::setAndDeleteCookie()
void tst_QWebEngineCookieStore::batchCookieTasks()
{
- QWebEngineView view;
- QWebEngineCookieStore *client = view.page()->profile()->cookieStore();
- client->deleteAllCookies();
+ QWebEnginePage page(&m_profile);
+ QWebEngineCookieStore *client = m_profile.cookieStore();
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
@@ -167,7 +168,7 @@ void tst_QWebEngineCookieStore::batchCookieTasks()
client->setCookie(cookie2);
QTRY_COMPARE(cookieAddedSpy.count(), 2);
- view.load(QUrl("qrc:///resources/index.html"));
+ page.load(QUrl("qrc:///resources/index.html"));
QTRY_COMPARE(loadSpy.count(), 1);
QVariant success = loadSpy.takeFirst().takeFirst();
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index daf4d811e..926c3e042 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -32,7 +32,6 @@
#include <QtWebEngineWidgets/qwebenginepage.h>
#include <QtWebEngineWidgets/qwebengineprofile.h>
#include <QtWebEngineWidgets/qwebenginesettings.h>
-#include <QtWebEngineWidgets/qwebengineview.h>
class tst_QWebEngineUrlRequestInterceptor : public QObject
{
@@ -104,20 +103,22 @@ public:
void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
{
- QWebEngineView view;
+ QWebEngineProfile profile;
+ profile.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
TestRequestInterceptor interceptor(/* intercept */ true);
- view.page()->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+ profile.setRequestInterceptor(&interceptor);
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
- view.page()->profile()->setRequestInterceptor(&interceptor);
- view.load(QUrl("qrc:///resources/index.html"));
+ QWebEnginePage page(&profile);
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+
+ page.load(QUrl("qrc:///resources/index.html"));
QTRY_COMPARE(loadSpy.count(), 1);
QVariant success = loadSpy.takeFirst().takeFirst();
QVERIFY(success.toBool());
loadSpy.clear();
QVariant ok;
- view.page()->runJavaScript("post();", [&ok](const QVariant result){ ok = result; });
+ page.runJavaScript("post();", [&ok](const QVariant result){ ok = result; });
QTRY_VERIFY(ok.toBool());
QTRY_COMPARE(loadSpy.count(), 1);
success = loadSpy.takeFirst().takeFirst();
@@ -125,7 +126,7 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
QVERIFY(!success.toBool());
loadSpy.clear();
- view.load(QUrl("qrc:///resources/__placeholder__"));
+ page.load(QUrl("qrc:///resources/__placeholder__"));
QTRY_COMPARE(loadSpy.count(), 1);
success = loadSpy.takeFirst().takeFirst();
// The redirection for __placeholder__ should succeed.
@@ -135,8 +136,8 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
// Make sure that registering an observer does not modify the request.
TestRequestInterceptor observer(/* intercept */ false);
- view.page()->profile()->setRequestInterceptor(&observer);
- view.load(QUrl("qrc:///resources/__placeholder__"));
+ profile.setRequestInterceptor(&observer);
+ page.load(QUrl("qrc:///resources/__placeholder__"));
QTRY_COMPARE(loadSpy.count(), 1);
success = loadSpy.takeFirst().takeFirst();
// Since we do not intercept, loading an invalid path should not succeed.
@@ -163,18 +164,18 @@ public:
void tst_QWebEngineUrlRequestInterceptor::ipv6HostEncoding()
{
- QWebEngineView view;
- QWebEnginePage *page = view.page();
+ QWebEngineProfile profile;
LocalhostContentProvider contentProvider;
- QSignalSpy spyLoadFinished(page, SIGNAL(loadFinished(bool)));
+ profile.setRequestInterceptor(&contentProvider);
- page->profile()->setRequestInterceptor(&contentProvider);
+ QWebEnginePage page(&profile);
+ QSignalSpy spyLoadFinished(&page, SIGNAL(loadFinished(bool)));
- page->setHtml("<p>Hi", QUrl::fromEncoded("http://[::1]/index.html"));
+ page.setHtml("<p>Hi", QUrl::fromEncoded("http://[::1]/index.html"));
QTRY_COMPARE(spyLoadFinished.count(), 1);
QCOMPARE(contentProvider.requestedUrls.count(), 0);
- evaluateJavaScriptSync(page, "var r = new XMLHttpRequest();"
+ evaluateJavaScriptSync(&page, "var r = new XMLHttpRequest();"
"r.open('GET', 'http://[::1]/test.xml', false);"
"r.send(null);"
);
@@ -185,12 +186,13 @@ void tst_QWebEngineUrlRequestInterceptor::ipv6HostEncoding()
void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
{
- QWebEnginePage page;
- page.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+ QWebEngineProfile profile;
+ profile.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+ TestRequestInterceptor interceptor(/* intercept */ true);
+ profile.setRequestInterceptor(&interceptor);
+ QWebEnginePage page(&profile);
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
- TestRequestInterceptor interceptor(/* intercept */ true);
- page.profile()->setRequestInterceptor(&interceptor);
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
QVERIFY(spy.wait());
@@ -214,10 +216,11 @@ void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl()
{
- QWebEnginePage page;
+ QWebEngineProfile profile;
TestRequestInterceptor interceptor(/* intercept */ true);
- page.profile()->setRequestInterceptor(&interceptor);
+ profile.setRequestInterceptor(&interceptor);
+ QWebEnginePage page(&profile);
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
@@ -244,10 +247,11 @@ void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl()
void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl()
{
- QWebEnginePage page;
+ QWebEngineProfile profile;
TestRequestInterceptor interceptor(/* intercept */ false);
- page.profile()->setRequestInterceptor(&interceptor);
+ profile.setRequestInterceptor(&interceptor);
+ QWebEnginePage page(&profile);
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setUrl(QUrl("qrc:///resources/firstparty.html"));