diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-01-17 10:42:26 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-19 11:11:02 +0100 |
commit | de0a5f28bc565c971989e68a19c8621a2309ed91 (patch) | |
tree | c1508783394682a2aab90fba81d7871a9c9a6036 /tests | |
parent | bab2eaf3da299c471dd898c89cf356984b077412 (diff) |
Add a baseUrl property to Text and TextEdit.
Specifies the base URL which embedded links in rich text are resolved
against. By default this is the URL of the item.
Task-number: QTBUG-23655
Change-Id: Ib51b8503a18d9ac4e1801c77b77b3595d8f4912a
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
6 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquicktext/data/embeddedImagesLocalRelative.qml b/tests/auto/qtquick2/qquicktext/data/embeddedImagesLocalRelative.qml new file mode 100644 index 0000000000..8de7364d08 --- /dev/null +++ b/tests/auto/qtquick2/qquicktext/data/embeddedImagesLocalRelative.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +Text { + textFormat: Text.RichText + text: "<img src='exists.png'>" + baseUrl: "http/" +} diff --git a/tests/auto/qtquick2/qquicktext/data/embeddedImagesRemoteRelative.qml b/tests/auto/qtquick2/qquicktext/data/embeddedImagesRemoteRelative.qml new file mode 100644 index 0000000000..cee19740f9 --- /dev/null +++ b/tests/auto/qtquick2/qquicktext/data/embeddedImagesRemoteRelative.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +Text { + textFormat: Text.RichText + text: "<img src='exists.png'>" + baseUrl: "http://127.0.0.1:14453/text.html" +} diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp index fa9549afc7..60dab3380a 100644 --- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp @@ -75,6 +75,7 @@ private slots: void alignments_data(); void alignments(); + void baseUrl(); void embeddedImages_data(); void embeddedImages(); @@ -1282,6 +1283,32 @@ void tst_qquicktext::clickLink() } } +void tst_qquicktext::baseUrl() +{ + QUrl localUrl("file:///tests/text.qml"); + QUrl remoteUrl("http://qt.nokia.com/test.qml"); + + QDeclarativeComponent textComponent(&engine); + textComponent.setData("import QtQuick 2.0\n Text {}", localUrl); + QQuickText *textObject = qobject_cast<QQuickText *>(textComponent.create()); + + QCOMPARE(textObject->baseUrl(), localUrl); + + QSignalSpy spy(textObject, SIGNAL(baseUrlChanged())); + + textObject->setBaseUrl(localUrl); + QCOMPARE(textObject->baseUrl(), localUrl); + QCOMPARE(spy.count(), 0); + + textObject->setBaseUrl(remoteUrl); + QCOMPARE(textObject->baseUrl(), remoteUrl); + QCOMPARE(spy.count(), 1); + + textObject->resetBaseUrl(); + QCOMPARE(textObject->baseUrl(), localUrl); + QCOMPARE(spy.count(), 2); +} + void tst_qquicktext::embeddedImages_data() { QTest::addColumn<QUrl>("qmlfile"); @@ -1289,9 +1316,11 @@ void tst_qquicktext::embeddedImages_data() QTest::newRow("local") << testFileUrl("embeddedImagesLocal.qml") << ""; QTest::newRow("local-error") << testFileUrl("embeddedImagesLocalError.qml") << testFileUrl("embeddedImagesLocalError.qml").toString()+":3:1: QML Text: Cannot open: " + testFileUrl("http/notexists.png").toString(); + QTest::newRow("local") << testFileUrl("embeddedImagesLocalRelative.qml") << ""; QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading http://127.0.0.1:14453/notexists.png - server replied: Not found"; + QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } void tst_qquicktext::embeddedImages() diff --git a/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalRelative.qml b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalRelative.qml new file mode 100644 index 0000000000..200ded196d --- /dev/null +++ b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesLocalRelative.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +TextEdit { + textFormat: TextEdit.RichText + text: "<img src='exists.png'>" + baseUrl: "http/" +} diff --git a/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteRelative.qml b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteRelative.qml new file mode 100644 index 0000000000..ee39e089ea --- /dev/null +++ b/tests/auto/qtquick2/qquicktextedit/data/embeddedImagesRemoteRelative.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +TextEdit { + textFormat: TextEdit.RichText + text: "<img src='exists.png'>" + baseUrl: "http://127.0.0.1:42332/text.html" +} diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp index 272ec19924..4a5bb01d1c 100644 --- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp @@ -175,6 +175,7 @@ private slots: void undo_keypressevents_data(); void undo_keypressevents(); + void baseUrl(); void embeddedImages(); void embeddedImages_data(); @@ -3658,6 +3659,32 @@ void tst_qquicktextedit::undo_keypressevents() QVERIFY(textEdit->text().isEmpty()); } +void tst_qquicktextedit::baseUrl() +{ + QUrl localUrl("file:///tests/text.qml"); + QUrl remoteUrl("http://qt.nokia.com/test.qml"); + + QDeclarativeComponent textComponent(&engine); + textComponent.setData("import QtQuick 2.0\n TextEdit {}", localUrl); + QQuickTextEdit *textObject = qobject_cast<QQuickTextEdit *>(textComponent.create()); + + QCOMPARE(textObject->baseUrl(), localUrl); + + QSignalSpy spy(textObject, SIGNAL(baseUrlChanged())); + + textObject->setBaseUrl(localUrl); + QCOMPARE(textObject->baseUrl(), localUrl); + QCOMPARE(spy.count(), 0); + + textObject->setBaseUrl(remoteUrl); + QCOMPARE(textObject->baseUrl(), remoteUrl); + QCOMPARE(spy.count(), 1); + + textObject->resetBaseUrl(); + QCOMPARE(textObject->baseUrl(), localUrl); + QCOMPARE(spy.count(), 2); +} + void tst_qquicktextedit::embeddedImages_data() { QTest::addColumn<QUrl>("qmlfile"); @@ -3665,9 +3692,11 @@ void tst_qquicktextedit::embeddedImages_data() 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("local") << testFileUrl("embeddedImagesLocalRelative.qml") << ""; 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"; + QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } void tst_qquicktextedit::embeddedImages() |