From e3d88532cbe38ebe4c14105d1a45088d36320b06 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 6 Oct 2009 12:07:18 +1000 Subject: Test basic properties. --- tests/auto/declarative/qfxwebview/data/basic.html | 12 ++++ tests/auto/declarative/qfxwebview/data/basic.qml | 5 ++ .../auto/declarative/qfxwebview/data/creation.qml | 3 - .../auto/declarative/qfxwebview/tst_qfxwebview.cpp | 67 +++++++++++++++++----- 4 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 tests/auto/declarative/qfxwebview/data/basic.html create mode 100644 tests/auto/declarative/qfxwebview/data/basic.qml delete mode 100644 tests/auto/declarative/qfxwebview/data/creation.qml diff --git a/tests/auto/declarative/qfxwebview/data/basic.html b/tests/auto/declarative/qfxwebview/data/basic.html new file mode 100644 index 0000000..254317c --- /dev/null +++ b/tests/auto/declarative/qfxwebview/data/basic.html @@ -0,0 +1,12 @@ + +Basic + + + + + + + +
This is a basic test.
+ + diff --git a/tests/auto/declarative/qfxwebview/data/basic.qml b/tests/auto/declarative/qfxwebview/data/basic.qml new file mode 100644 index 0000000..5394837 --- /dev/null +++ b/tests/auto/declarative/qfxwebview/data/basic.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +WebView { + url: "basic.html" +} diff --git a/tests/auto/declarative/qfxwebview/data/creation.qml b/tests/auto/declarative/qfxwebview/data/creation.qml deleted file mode 100644 index bb49143..0000000 --- a/tests/auto/declarative/qfxwebview/data/creation.qml +++ /dev/null @@ -1,3 +0,0 @@ -import Qt 4.6 - -WebView { } diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp index 974a4b7..f63ac11 100644 --- a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include class tst_qfxwebview : public QObject { @@ -13,14 +15,37 @@ public: tst_qfxwebview() {} private slots: - void testQmlFiles_data(); - void testQmlFiles(); + void testBasicProperties(); + void cleanupTestCase(); + private: void checkNoErrors(const QmlComponent& component); QmlEngine engine; + QString tmpDir() const + { + static QString tmpd = QDir::tempPath()+"/tst_sql_output-" + + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); + return tmpd; + } }; +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); +} + +void tst_qfxwebview::cleanupTestCase() +{ + removeRecursive(tmpDir()); +} void tst_qfxwebview::checkNoErrors(const QmlComponent& component) { @@ -37,21 +62,37 @@ void tst_qfxwebview::checkNoErrors(const QmlComponent& component) QVERIFY(!component.isError()); } -void tst_qfxwebview::testQmlFiles_data() +void tst_qfxwebview::testBasicProperties() { - QTest::addColumn("qmlfile"); // The input file - - QTest::newRow("creation") << QUrl::fromLocalFile(SRCDIR "/data/creation.qml"); -} - -void tst_qfxwebview::testQmlFiles() -{ - QFETCH(QUrl, qmlfile); - - QmlComponent component(&engine, qmlfile); + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/basic.qml")); checkNoErrors(component); + QWebSettings::enablePersistentStorage(tmpDir()); + QFxWebView *wv = qobject_cast(component.create()); QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + QCOMPARE(wv->title(),QString("Basic")); + wv->icon().save("test.png"); + //QCOMPARE(wv->icon(),QPixmap(SRCDIR "/data/basic.ico")); + QCOMPARE(wv->statusText(),QString("")); + QFile htmlfile(SRCDIR "/data/basic.html"); + QVERIFY(htmlfile.open(QIODevice::ReadOnly)); + QString actualhtml____ = wv->html(); // "____" is to make errors line up for easier reading + QString expectedhtml = htmlfile.readAll(); + actualhtml____.replace(QRegExp("\\s+"),""); + expectedhtml.replace(QRegExp("\\s+"),""); + QCOMPARE(actualhtml____,expectedhtml); // same, ignoring whitespace + QCOMPARE(wv->width(), 123.0); + QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); + QCOMPARE(wv->status(), QFxWebView::Ready); + QVERIFY(wv->reloadAction()); + QVERIFY(wv->reloadAction()->isEnabled()); + QVERIFY(wv->backAction()); + QVERIFY(!wv->backAction()->isEnabled()); + QVERIFY(wv->forwardAction()); + QVERIFY(!wv->forwardAction()->isEnabled()); + QVERIFY(wv->stopAction()); + QVERIFY(!wv->stopAction()->isEnabled()); } QTEST_MAIN(tst_qfxwebview) -- cgit v0.12