diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-08-28 15:04:56 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-08-28 15:33:41 +0200 |
commit | 311a0ebf28bb7603073a7735b50ea74f866c0567 (patch) | |
tree | f1d87be82ee9b944780c1ff8fb3240b242f9bea3 | |
parent | 95aae99dee1dfd96ef6b41e4916aa1b4d3baff1f (diff) |
Fix test for Windows.
Create the cache location in case it does not exist.
Use a temporary file to prevent leaks and clashes.
Use QUrl::fromLocalFile().
Change-Id: I0dec5eadd1eac54818d8971b9f4236955651b8af
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
-rw-r--r-- | tests/auto/webview/qwebview/tst_qwebview.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tests/auto/webview/qwebview/tst_qwebview.cpp b/tests/auto/webview/qwebview/tst_qwebview.cpp index 87b39a2..498c88d 100644 --- a/tests/auto/webview/qwebview/tst_qwebview.cpp +++ b/tests/auto/webview/qwebview/tst_qwebview.cpp @@ -36,35 +36,53 @@ #include <QtTest/QtTest> #include <QtCore/qstandardpaths.h> +#include <QtCore/qdir.h> +#include <QtCore/qtemporarydir.h> +#include <QtCore/qfileinfo.h> #include <QtWebView/private/qwebview_p.h> class tst_QWebView : public QObject { Q_OBJECT +public: + tst_QWebView() : m_cacheLocation(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) {} + private slots: + void initTestCase(); void load(); + +private: + const QString m_cacheLocation; }; +void tst_QWebView::initTestCase() +{ + if (!QFileInfo(m_cacheLocation).isDir()) { + QDir dir; + QVERIFY(dir.mkpath(m_cacheLocation)); + } +} + void tst_QWebView::load() { - QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - QString fileName(cacheLocation + QStringLiteral("/file.html")); + QTemporaryFile file(m_cacheLocation + QStringLiteral("/XXXXXXfile.html")); + QVERIFY2(file.open(), + qPrintable(QStringLiteral("Cannot create temporary file:") + file.errorString())); - { - QFile file(fileName); - QVERIFY(file.open(QIODevice::WriteOnly)); - file.write("<html><head><title>FooBar</title></head><body />"); - } + file.write("<html><head><title>FooBar</title></head><body />"); + const QString fileName = file.fileName(); + file.close(); QWebView view; QCOMPARE(view.loadProgress(), 0); - view.setUrl(QUrl(QStringLiteral("file://") + fileName)); + const QUrl url = QUrl::fromLocalFile(fileName); + view.setUrl(url); QTRY_COMPARE(view.loadProgress(), 100); QTRY_VERIFY(!view.isLoading()); QCOMPARE(view.title(), QStringLiteral("FooBar")); QVERIFY(!view.canGoBack()); QVERIFY(!view.canGoForward()); - QCOMPARE(view.url(), QUrl(QStringLiteral("file://") + fileName)); + QCOMPARE(view.url(), url); } QTEST_MAIN(tst_QWebView) |