summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebengineprofile
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2015-12-10 07:05:29 -0800
committerSzabolcs David <davidsz@inf.u-szeged.hu>2016-01-06 08:06:33 +0000
commitf5ed13b1e2d20ca49adb6fa378faee14bece16a0 (patch)
tree70dbd031d4a59a8b5031fc93795f5a08ac715c65 /tests/auto/widgets/qwebengineprofile
parent1ae9e7cc00a366fddcb4909df375829e9727c7fa (diff)
Add function to clear data from the cache
It marks the entries of the current cache backend for deletion and starts to remove them. Task-number: QTBUG-48177 Change-Id: I85ec25048ff5429976f1b2dcacd74666bdbe6624 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets/qwebengineprofile')
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 09929d33..d24a43b4 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -37,6 +37,7 @@
#include "../util.h"
#include <QtTest/QtTest>
#include <qwebengineprofile.h>
+#include <qwebenginepage.h>
class tst_QWebEngineProfile : public QObject
{
@@ -45,6 +46,7 @@ class tst_QWebEngineProfile : public QObject
private Q_SLOTS:
void defaultProfile();
void profileConstructors();
+ void clearDataFromCache();
};
void tst_QWebEngineProfile::defaultProfile()
@@ -69,7 +71,45 @@ void tst_QWebEngineProfile::profileConstructors()
QCOMPARE(diskProfile.httpCacheType(), QWebEngineProfile::DiskHttpCache);
QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
QCOMPARE(diskProfile.persistentCookiesPolicy(), QWebEngineProfile::AllowPersistentCookies);
+}
+
+void tst_QWebEngineProfile::clearDataFromCache()
+{
+ QWebEnginePage page;
+
+ QDir cacheDir("./tst_QWebEngineProfile_cacheDir");
+ cacheDir.makeAbsolute();
+ if (cacheDir.exists())
+ cacheDir.removeRecursively();
+ cacheDir.mkpath(cacheDir.path());
+
+ QWebEngineProfile *profile = page.profile();
+ profile->setCachePath(cacheDir.path());
+ profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
+
+ QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
+ page.load(QUrl("http://qt-project.org"));
+ if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
+ QSKIP("Couldn't load page from network, skipping test.");
+
+ cacheDir.refresh();
+ QVERIFY(cacheDir.entryList().contains("Cache"));
+ cacheDir.cd("./Cache");
+ int filesBeforeClear = cacheDir.entryList().count();
+
+ QFileSystemWatcher fileSystemWatcher;
+ fileSystemWatcher.addPath(cacheDir.path());
+ QSignalSpy directoryChangedSpy(&fileSystemWatcher, SIGNAL(directoryChanged(const QString &)));
+
+ // It deletes most of the files, but not all of them.
+ profile->clearHttpCache();
+ QTest::qWait(1000);
+ QTRY_VERIFY(directoryChangedSpy.count() > 0);
+
+ cacheDir.refresh();
+ QVERIFY(filesBeforeClear > cacheDir.entryList().count());
+ cacheDir.removeRecursively();
}
QTEST_MAIN(tst_QWebEngineProfile)