From a14337a9e9812bb485ba5774a8bccc977e1e9519 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 5 Oct 2009 15:39:34 +1000 Subject: Trivial WebView autotest --- .../auto/declarative/qfxwebview/data/creation.qml | 3 ++ tests/auto/declarative/qfxwebview/qfxwebview.pro | 6 +++ .../auto/declarative/qfxwebview/tst_qfxwebview.cpp | 59 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/auto/declarative/qfxwebview/data/creation.qml create mode 100644 tests/auto/declarative/qfxwebview/qfxwebview.pro create mode 100644 tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp diff --git a/tests/auto/declarative/qfxwebview/data/creation.qml b/tests/auto/declarative/qfxwebview/data/creation.qml new file mode 100644 index 0000000..bb49143 --- /dev/null +++ b/tests/auto/declarative/qfxwebview/data/creation.qml @@ -0,0 +1,3 @@ +import Qt 4.6 + +WebView { } diff --git a/tests/auto/declarative/qfxwebview/qfxwebview.pro b/tests/auto/declarative/qfxwebview/qfxwebview.pro new file mode 100644 index 0000000..ee78950 --- /dev/null +++ b/tests/auto/declarative/qfxwebview/qfxwebview.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qfxwebview.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp new file mode 100644 index 0000000..974a4b7 --- /dev/null +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -0,0 +1,59 @@ +#include +#include "../../../shared/util.h" +#include +#include +#include +#include +#include + +class tst_qfxwebview : public QObject +{ + Q_OBJECT +public: + tst_qfxwebview() {} + +private slots: + void testQmlFiles_data(); + void testQmlFiles(); + +private: + void checkNoErrors(const QmlComponent& component); + QmlEngine engine; +}; + + +void tst_qfxwebview::checkNoErrors(const QmlComponent& component) +{ + if (component.isError()) { + QList errors = component.errors(); + for (int ii = 0; ii < errors.count(); ++ii) { + const QmlError &error = errors.at(ii); + QByteArray errorStr = QByteArray::number(error.line()) + ":" + + QByteArray::number(error.column()) + ":" + + error.description().toUtf8(); + qWarning() << errorStr; + } + } + QVERIFY(!component.isError()); +} + +void tst_qfxwebview::testQmlFiles_data() +{ + 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); + checkNoErrors(component); + QFxWebView *wv = qobject_cast(component.create()); + QVERIFY(wv != 0); +} + +QTEST_MAIN(tst_qfxwebview) + +#include "tst_qfxwebview.moc" -- cgit v0.12 From e220005f1c093520078f3642905b3ddba783a739 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 6 Oct 2009 12:02:25 +1000 Subject: Fix following API changes. --- demos/declarative/contacts/Contact.qml | 4 ++-- examples/declarative/velocity/Day.qml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demos/declarative/contacts/Contact.qml b/demos/declarative/contacts/Contact.qml index 91510c7..e12cd3b 100644 --- a/demos/declarative/contacts/Contact.qml +++ b/demos/declarative/contacts/Contact.qml @@ -82,8 +82,8 @@ Item { } Column { id: layout - width: contents.width - height:contents.height + width: childrenRect.width + height: childrenRect.height anchors.centerIn: parent spacing: 5 ContactField { diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 4001a3e..052f690 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -22,7 +22,7 @@ Rectangle { font.bold: true width: 370 text: day - style: Outline + style: "Outline" styleColor: "#dedede" } Repeater { -- cgit v0.12 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 From 8ca8d4b8b234d6d57e9f963d3c1e7f7522bcaf98 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 6 Oct 2009 12:09:22 +1000 Subject: typo --- tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp index f63ac11..834c07f 100644 --- a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -24,7 +24,7 @@ private: QmlEngine engine; QString tmpDir() const { - static QString tmpd = QDir::tempPath()+"/tst_sql_output-" + static QString tmpd = QDir::tempPath()+"/tst_qfxwebview-" + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); return tmpd; } -- cgit v0.12 From 47db21ecd772a980e0a4a5f91c63cdffafdff8c0 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 6 Oct 2009 12:16:48 +1000 Subject: Use QDesktopServices::storageLocation() in place of placeform-specific code. --- src/declarative/qml/qmlengine.cpp | 42 ++++------------------------------ tests/auto/declarative/sql/tst_sql.cpp | 27 ++++++++++++++++------ 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 72603ed..f34d790 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -114,43 +114,9 @@ QScriptValue desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e) return e->newVariant(QVariant(ret)); } -// XXX Something like this should be exported by Qt. static QString userLocalDataPath(const QString& app) { - QString result; - -#ifdef Q_OS_WIN -#ifndef Q_OS_WINCE - QLibrary library(QLatin1String("shell32")); -#else - QLibrary library(QLatin1String("coredll")); -#endif // Q_OS_WINCE - typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); - GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW"); - if (SHGetSpecialFolderPath) { - wchar_t path[MAX_PATH]; - SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE); - result = QString::fromWCharArray(path); - } -#endif // Q_OS_WIN - -#ifdef Q_OS_MAC - result = QLatin1String(qgetenv("HOME")); - result += "/Library/Application Support"; -#else - if (result.isEmpty()) { - // Fallback: UNIX style - result = QLatin1String(qgetenv("XDG_DATA_HOME")); - if (result.isEmpty()) { - result = QLatin1String(qgetenv("HOME")); - result += QLatin1String("/.local/share"); - } - } -#endif - - result += QLatin1Char('/'); - result += app; - return result; + return QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/") + app; } QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) @@ -166,7 +132,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("DesktopServices"), desktopObject); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); - offlineStoragePath = userLocalDataPath(QLatin1String("Nokia/Qt/QML/OfflineStorage")); + offlineStoragePath = userLocalDataPath(QLatin1String("QML/OfflineStorage")); qt_add_qmlxmlhttprequest(&scriptEngine); qt_add_qmlsqldatabase(&scriptEngine); @@ -1602,7 +1568,7 @@ public: if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return)) return true; if (s->urls.count() == 1 && !s->isBuiltin[0] && !s->isLibrary[0] && url_return) { - *url_return = QUrl(s->urls[0]+"/").resolved(QUrl(QLatin1String(unqualifiedtype + ".qml"))); + *url_return = QUrl(s->urls[0]+QLatin1String("/")).resolved(QUrl(QLatin1String(unqualifiedtype + ".qml"))); return true; } } @@ -1697,7 +1663,7 @@ void QmlEngine::addImportPath(const QString& path) QFxWebView and the SQL databases created with openDatabase() are stored here. - The default is Nokia/Qt/QML/Databases/ in the platform-standard + The default is QML/OfflineStorage/ in the platform-standard user application data directory. */ void QmlEngine::setOfflineStoragePath(const QString& dir) diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index 10ce6d8..22e9ba4 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -14,7 +14,18 @@ class tst_sql : public QObject { Q_OBJECT public: - tst_sql() {} + tst_sql() + { + qApp->setApplicationName("tst_sql"); + qApp->setOrganizationName("Nokia"); + qApp->setOrganizationDomain("nokia.com"); + engine = new QmlEngine; + } + + ~tst_sql() + { + delete engine; + } private slots: void initTestCase(); @@ -31,7 +42,7 @@ private slots: private: QString dbDir() const; - QmlEngine engine; + QmlEngine *engine; }; class QWebPageWithJavaScriptConsoleMessages : public QWebPage { @@ -67,14 +78,16 @@ void tst_sql::cleanupTestCase() QString tst_sql::dbDir() const { - return QString(SRCDIR)+"/output"; + static QString tmpd = QDir::tempPath()+"/tst_sql_output-" + + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); + return tmpd; } void tst_sql::checkDatabasePath() { // Check default storage path (we can't use it since we don't want to mess with user's data) - QVERIFY(engine.offlineStoragePath().contains("Nokia")); - QVERIFY(engine.offlineStoragePath().contains("OfflineStorage")); + QVERIFY(engine->offlineStoragePath().contains("Nokia")); + QVERIFY(engine->offlineStoragePath().contains("OfflineStorage")); } void tst_sql::testQml_data() @@ -142,8 +155,8 @@ void tst_sql::testQml() "import Qt 4.6\n" "Text { Script { source: \""+jsfile+"\" } text: test() }"; - engine.setOfflineStoragePath(dbDir()); - QmlComponent component(&engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports + engine->setOfflineStoragePath(dbDir()); + QmlComponent component(engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports QFxText *text = qobject_cast(component.create()); QVERIFY(text != 0); QCOMPARE(text->text(),result); -- cgit v0.12