From 652e43ddbc4bf32b8c5f634a47a883f7029fd890 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 13 Nov 2009 10:44:15 +1000 Subject: XMLHttpRequest tests --- src/declarative/qml/qmlxmlhttprequest.cpp | 11 ++--- .../auto/declarative/xmlhttprequest/data/text.qml | 56 ++++++++++++++++++++++ .../auto/declarative/xmlhttprequest/data/text.xml | 1 + .../xmlhttprequest/tst_xmlhttprequest.cpp | 14 ++++++ 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 tests/auto/declarative/xmlhttprequest/data/text.qml create mode 100644 tests/auto/declarative/xmlhttprequest/data/text.xml diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index a6cdfb1..1e9ad50 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -465,12 +465,11 @@ QScriptValue Node::create(QScriptEngine *engine, NodeImpl *data) case NodeImpl::Entity: case NodeImpl::EntityReference: case NodeImpl::Notation: + case NodeImpl::ProcessingInstruction: + return QScriptValue(); case NodeImpl::CDATA: instance.setPrototype(CDATA::prototype(engine)); break; - case NodeImpl::ProcessingInstruction: - instance.setPrototype(Node::prototype(engine)); - break; case NodeImpl::Text: instance.setPrototype(Text::prototype(engine)); break; @@ -556,8 +555,7 @@ QScriptValue Text::isElementContentWhitespace(QScriptContext *context, QScriptEn Node node = qscriptvalue_cast(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - // ### implement - return QScriptValue(false); + return node.d->data.trimmed().isEmpty(); } QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine) @@ -565,8 +563,7 @@ QScriptValue Text::wholeText(QScriptContext *context, QScriptEngine *engine) Node node = qscriptvalue_cast(context->thisObject()); if (node.isNull()) return engine->undefinedValue(); - // ### implement - return QScriptValue(QString()); + return node.d->data; } QScriptValue Text::prototype(QScriptEngine *engine) diff --git a/tests/auto/declarative/xmlhttprequest/data/text.qml b/tests/auto/declarative/xmlhttprequest/data/text.qml new file mode 100644 index 0000000..b64f80b --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/text.qml @@ -0,0 +1,56 @@ +import Qt 4.6 + +Object { + property bool xmlTest: false + property bool dataOK: false + + Script { + function checkText(text, whitespacetext) + { + if (text.wholeText != "Hello world!") + return; + + if (text.isElementContentWhitespace != false) + return; + + if (whitespacetext.wholeText != " ") + return; + + if (whitespacetext.isElementContentWhitespace != true) + return; + + xmlTest = true; + } + + function checkXML(document) + { + checkText(document.documentElement.childNodes[0].childNodes[0], + document.documentElement.childNodes[1].childNodes[0]); + + } + } + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "text.xml"); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + + dataOK = true; + + if (x.responseXML != null) + checkXML(x.responseXML); + + } + } + + x.send() + } +} + + + + diff --git a/tests/auto/declarative/xmlhttprequest/data/text.xml b/tests/auto/declarative/xmlhttprequest/data/text.xml new file mode 100644 index 0000000..e741688 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/text.xml @@ -0,0 +1 @@ +Hello world! diff --git a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp index 0af7b18..cf1ffd3 100644 --- a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp +++ b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp @@ -88,6 +88,7 @@ private slots: void document(); void element(); void attr(); + void text(); // Crashes // void outstanding_request_at_shutdown(); @@ -1017,6 +1018,19 @@ void tst_xmlhttprequest::attr() delete object; } +void tst_xmlhttprequest::text() +{ + QmlComponent component(&engine, TEST_FILE("text.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + TRY_WAIT(object->property("dataOK").toBool() == true); + + QCOMPARE(object->property("xmlTest").toBool(), true); + + delete object; +} + QTEST_MAIN(tst_xmlhttprequest) #include "tst_xmlhttprequest.moc" -- cgit v0.12