forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Libsqlite tests] Resources for sqlite tests
- Loading branch information
1 parent
cf215db
commit 2057c3f
Showing
5 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<html> | ||
<script> | ||
var db, res = "none"; | ||
var request = window.indexedDB.open("testDataBase", 3); | ||
request.onerror = function (event) { | ||
res = "Failed Database Creation"; | ||
}; | ||
|
||
request.onsuccess = function (event) { | ||
res = "Database Success"; | ||
db = request.result; | ||
}; | ||
|
||
request.onupgradeneeded = function (event) { | ||
var db = event.target.result; | ||
var objectStore = db.createObjectStore("testTable", { keyPath: "id" }); | ||
} | ||
|
||
function read(id) { | ||
var transaction = db.transaction(["testTable"]); | ||
var objectStore = transaction.objectStore("testTable"); | ||
var request = objectStore.get(id); | ||
|
||
request.onerror = function (event) { | ||
res = `Unable to get ${id}`; | ||
}; | ||
|
||
request.onsuccess = function (event) { | ||
if (request.result) res = request.result.name; | ||
else res = `Unable to get ${id}`; | ||
}; | ||
} | ||
|
||
function add(id, name) { | ||
var request = db.transaction(["testTable"], "readwrite") | ||
.objectStore("testTable") | ||
.add({ id: id, name: name }); | ||
} | ||
|
||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include(../tests.pri) | ||
exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (C) 2020 Rajagopalan-Gangadharan <g.raju2000@gmail.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <QtTest/QtTest> | ||
#include "../util.h" | ||
|
||
#include <QDir> | ||
#include <qwebpage.h> | ||
#include <qwebframe.h> | ||
|
||
static void removeRecursive(const QString &dirname) | ||
{ | ||
QDir dir(dirname); | ||
QFileInfoList entries(dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)); | ||
for (int i = 0; i < entries.count(); ++i) | ||
if (entries[i].isDir()) | ||
removeRecursive(entries[i].filePath()); | ||
else | ||
dir.remove(entries[i].fileName()); | ||
QDir().rmdir(dirname); | ||
} | ||
|
||
|
||
class tst_Sqlite : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
tst_Sqlite(); | ||
~tst_Sqlite(); | ||
|
||
public Q_SLOTS: | ||
void initTestCase(); | ||
void cleanupTestCase(); | ||
private Q_SLOTS: | ||
void indexedDBTest(); | ||
|
||
private: | ||
QString tmpDirPath() const | ||
{ | ||
static QString tmpd = QDir::tempPath() + "/tst_sqlite-" | ||
+ QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); | ||
return tmpd; | ||
} | ||
}; | ||
|
||
tst_Sqlite::tst_Sqlite() | ||
{ | ||
} | ||
|
||
tst_Sqlite::~tst_Sqlite() | ||
{ | ||
} | ||
|
||
void tst_Sqlite::initTestCase() | ||
{ | ||
} | ||
|
||
void tst_Sqlite::cleanupTestCase() | ||
{ | ||
removeRecursive(tmpDirPath()); | ||
} | ||
|
||
void tst_Sqlite::indexedDBTest() | ||
{ | ||
QString path = tmpDirPath(); | ||
QWebPage page; | ||
|
||
page.settings()->setOfflineStoragePath(path); | ||
QVERIFY(page.settings()->offlineStoragePath() == path); | ||
|
||
QWebSettings::setOfflineStorageDefaultQuota(1024 * 1024); | ||
QVERIFY(QWebSettings::offlineStorageDefaultQuota() == 1024 * 1024); | ||
|
||
page.settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); | ||
|
||
QString dbFileName = path + "Databases.db"; | ||
|
||
if (QFile::exists(dbFileName)) | ||
QFile::remove(dbFileName); | ||
|
||
QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); | ||
page.mainFrame()->load(QUrl("qrc:///test.html")); | ||
|
||
waitForSignal(&page, SIGNAL(loadFinished(bool))); | ||
QCOMPARE(loadSpy.count(), 1); | ||
|
||
waitForSignal(&page, SIGNAL(loadFinished(bool)), 2000); | ||
|
||
QVariant res = page.mainFrame()->evaluateJavaScript("res"); | ||
QCOMPARE(res.toString(), QStringLiteral("Database Success")); | ||
|
||
page.mainFrame()->evaluateJavaScript("add('1','Name1')"); | ||
waitForSignal(&page, SIGNAL(loadFinished(bool)), 1000); | ||
|
||
page.mainFrame()->evaluateJavaScript("read('1')"); | ||
waitForSignal(&page, SIGNAL(loadFinished(bool)), 1000); | ||
|
||
res = page.mainFrame()->evaluateJavaScript("res"); | ||
QCOMPARE(res.toString(), QStringLiteral("Name1")); | ||
} | ||
|
||
QTEST_MAIN(tst_Sqlite) | ||
#include "tst_sqlite.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!DOCTYPE RCC><RCC version="1.0"> | ||
<qresource prefix="/"> | ||
<file alias="test.html">resources/test.html</file> | ||
</qresource> | ||
</RCC> |