summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-08-24 06:21:51 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-08-25 06:55:49 (GMT)
commit185fabb154e387dce7e331558008f7ecaeb1ed50 (patch)
tree316584d835b704ba0c5206d674dfcb310fe8b1b6 /tests/auto/declarative
parenta662c0014a55ac3bf57c6e861334a125f6af07aa (diff)
downloadQt-185fabb154e387dce7e331558008f7ecaeb1ed50.zip
Qt-185fabb154e387dce7e331558008f7ecaeb1ed50.tar.gz
Qt-185fabb154e387dce7e331558008f7ecaeb1ed50.tar.bz2
Fix responseText to check the charset encoding field and also to not
assume that the data is xml. The change also follows the w3c spec more closely (e.g. check the mime type field as well for encoding, for both responseText and responseXML). Task-number: QTBUG-13117
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html1
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml5
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp38
3 files changed, 32 insertions, 12 deletions
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html
new file mode 100644
index 0000000..b640733
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.html
@@ -0,0 +1 @@
+უ Σ
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml
index a54ef4a..85bff29 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml
@@ -3,13 +3,14 @@ import Qt 4.7
QtObject {
property bool dataOK: false
+ property string fileName
property string responseText
property string responseXmlRootNodeValue
- Component.onCompleted: {
+ function startRequest() {
var x = new XMLHttpRequest;
- x.open("GET", "utf16.xml");
+ x.open("GET", fileName);
// Test to the end
x.onreadystatechange = function() {
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
index 8141fcb..ecce349 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
@@ -104,6 +104,7 @@ private slots:
void invalidMethodUsage();
void redirects();
void nonUtf8();
+ void nonUtf8_data();
// Attributes
void document();
@@ -919,26 +920,43 @@ void tst_qdeclarativexmlhttprequest::responseText_data()
void tst_qdeclarativexmlhttprequest::nonUtf8()
{
+ QFETCH(QString, fileName);
+ QFETCH(QString, responseText);
+ QFETCH(QString, xmlRootNodeValue);
+
QDeclarativeComponent component(&engine, TEST_FILE("utf16.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
+ object->setProperty("fileName", fileName);
+ QMetaObject::invokeMethod(object, "startRequest");
+
+ TRY_WAIT(object->property("dataOK").toBool() == true);
+
+ QCOMPARE(object->property("responseText").toString(), responseText);
+
+ if (!xmlRootNodeValue.isEmpty()) {
+ QString rootNodeValue = object->property("responseXmlRootNodeValue").toString();
+ QCOMPARE(rootNodeValue, xmlRootNodeValue);
+ }
+
+ delete object;
+}
+
+void tst_qdeclarativexmlhttprequest::nonUtf8_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QString>("responseText");
+ QTest::addColumn<QString>("xmlRootNodeValue");
+
QString uc;
uc.resize(3);
uc[0] = QChar(0x10e3);
uc[1] = QChar(' ');
uc[2] = QChar(0x03a3);
- QString xml = "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\n";
- TRY_WAIT(object->property("dataOK").toBool() == true);
-
- QString responseText = object->property("responseText").toString();
- QCOMPARE(responseText, xml);
-
- QString responseXmlText = object->property("responseXmlRootNodeValue").toString();
- QCOMPARE(responseXmlText, '\n' + uc + '\n');
-
- delete object;
+ QTest::newRow("responseText") << "utf16.html" << uc + '\n' << "";
+ QTest::newRow("responseXML") << "utf16.xml" << "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\n" << QString('\n' + uc + '\n');
}
// Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object