aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-01-16 16:40:13 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-19 11:11:02 +0100
commitbab2eaf3da299c471dd898c89cf356984b077412 (patch)
treed7c3bd0cef1e5b28635e71137b62fbca51d070d1 /tests
parent9a08d3e79fee46b33a75d17f76f0ff63687a648e (diff)
Don't load embedded images from the current working directory.
Override QTextImageHandler's image loading as it will attempt to resolve relative paths and load the image itself if the document returns an invalid image from loadResource, which we don't want as it bypasses the pixmap cache and resolves against the application and current working directory instead of the Text items context. Change-Id: Ia1d3633036f96d902e1ac03dae5d5b203fba7ff1 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp1
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocal.qml6
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalError.qml6
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemote.qml6
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteError.qml6
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/http/exists.pngbin0 -> 2738 bytes
-rw-r--r--tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp46
7 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
index 0e8eab18be..fa9549afc7 100644
--- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
#include <qtest.h>
+#include <QtTest/QSignalSpy>
#include <QTextDocument>
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
diff --git a/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocal.qml b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocal.qml
new file mode 100644
index 0000000000..150f7bd898
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocal.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+TextEdit {
+ textFormat: TextEdit.RichText
+ text: "<img src='http/exists.png'>"
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalError.qml b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalError.qml
new file mode 100644
index 0000000000..067b6d72da
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalError.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+TextEdit {
+ textFormat: TextEdit.RichText
+ text: "<img src='http/notexists.png'>"
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemote.qml b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemote.qml
new file mode 100644
index 0000000000..a823882692
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemote.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+TextEdit {
+ textFormat: TextEdit.RichText
+ text: "<img src='http://127.0.0.1:42332/exists.png'>"
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteError.qml b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteError.qml
new file mode 100644
index 0000000000..c6172b68dc
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteError.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+TextEdit {
+ textFormat: TextEdit.RichText
+ text: "<img src='http://127.0.0.1:42332/notexists.png'>"
+}
diff --git a/tests/auto/qtquick2/qquicktextedit/data/http/exists.png b/tests/auto/qtquick2/qquicktextedit/data/http/exists.png
new file mode 100644
index 0000000000..399bd0b1d9
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/http/exists.png
Binary files differ
diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
index b35d955e2d..272ec19924 100644
--- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
@@ -51,6 +51,7 @@
#include <QtGui/qguiapplication.h>
#include <private/qquicktextedit_p.h>
#include <private/qquicktextedit_p_p.h>
+#include <private/qquicktext_p_p.h>
#include <QFontMetrics>
#include <QtQuick/QQuickView>
#include <QDir>
@@ -174,6 +175,9 @@ private slots:
void undo_keypressevents_data();
void undo_keypressevents();
+ void embeddedImages();
+ void embeddedImages_data();
+
void emptytags_QTBUG_22058();
private:
@@ -3654,6 +3658,48 @@ void tst_qquicktextedit::undo_keypressevents()
QVERIFY(textEdit->text().isEmpty());
}
+void tst_qquicktextedit::embeddedImages_data()
+{
+ QTest::addColumn<QUrl>("qmlfile");
+ QTest::addColumn<QString>("error");
+ QTest::newRow("local") << testFileUrl("embeddedImagesLocal.qml") << "";
+ QTest::newRow("local-error") << testFileUrl("embeddedImagesLocalError.qml")
+ << testFileUrl("embeddedImagesLocalError.qml").toString()+":3:1: QML TextEdit: Cannot open: " + testFileUrl("http/notexists.png").toString();
+ QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << "";
+ QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml")
+ << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading http://127.0.0.1:42332/notexists.png - server replied: Not found";
+}
+
+void tst_qquicktextedit::embeddedImages()
+{
+ QFETCH(QUrl, qmlfile);
+ QFETCH(QString, error);
+
+ TestHTTPServer server(42332);
+ server.serveDirectory(testFile("http"));
+
+ if (!error.isEmpty())
+ QTest::ignoreMessage(QtWarningMsg, error.toLatin1());
+
+ QDeclarativeComponent textComponent(&engine, qmlfile);
+ QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QTRY_COMPARE(QQuickTextEditPrivate::get(textObject)->document->resourcesLoading(), 0);
+
+ QPixmap pm(testFile("http/exists.png"));
+ if (error.isEmpty()) {
+ QCOMPARE(textObject->width(), double(pm.width()));
+ QCOMPARE(textObject->height(), double(pm.height()));
+ } else {
+ QVERIFY(16 != pm.width()); // check test is effective
+ QCOMPARE(textObject->width(), 16.0); // default size of QTextDocument broken image icon
+ QCOMPARE(textObject->height(), 16.0);
+ }
+
+ delete textObject;
+}
+
void tst_qquicktextedit::emptytags_QTBUG_22058()
{
QQuickView canvas(testFileUrl("qtbug-22058.qml"));