diff options
Diffstat (limited to 'tests')
23 files changed, 773 insertions, 2 deletions
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index bcf908d..ec2c7d0 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -18,6 +18,7 @@ SUBDIRS += \ qmldom \ # Cover qmleasefollow \ # Cover qmlecmascript \ # Cover + qmlengine \ # Cover qmlerror \ # Cover qmlfontloader \ # Cover qmlgraphicsborderimage \ # Cover diff --git a/tests/auto/declarative/qmlbinding/data/test-binding.qml b/tests/auto/declarative/qmlbinding/data/test-binding.qml index d2a22f5..e9101e4 100644 --- a/tests/auto/declarative/qmlbinding/data/test-binding.qml +++ b/tests/auto/declarative/qmlbinding/data/test-binding.qml @@ -10,7 +10,7 @@ Rectangle { Rectangle { id: r1; width: 1; height: 1; color: "yellow" } Rectangle { id: r2; width: 1; height: 1; color: "red" } - Binding { target: screen; property: "text"; value: s1.text } + Binding { target: screen; property: "text"; value: s1.text; objectName: "binding1" } Binding { target: screen; property: "color"; value: r1.color } Binding { target: screen; property: "color"; when: screen.changeColor == true; value: r2.color } } diff --git a/tests/auto/declarative/qmlbinding/tst_qmlbinding.cpp b/tests/auto/declarative/qmlbinding/tst_qmlbinding.cpp index e5aacc7..0a8508a 100644 --- a/tests/auto/declarative/qmlbinding/tst_qmlbinding.cpp +++ b/tests/auto/declarative/qmlbinding/tst_qmlbinding.cpp @@ -77,6 +77,12 @@ void tst_qmlbinding::binding() rect->setProperty("changeColor", true); QCOMPARE(rect->color(), QColor("red")); + QmlBind *binding = qobject_cast<QmlBind*>(rect->findChild<QmlBind*>("binding1")); + QVERIFY(binding != 0); + QCOMPARE(binding->object(), rect); + QCOMPARE(binding->property(), QLatin1String("text")); + QCOMPARE(binding->value().toString(), QLatin1String("Hello")); + delete rect; } diff --git a/tests/auto/declarative/qmlengine/qmlengine.pro b/tests/auto/declarative/qmlengine/qmlengine.pro new file mode 100644 index 0000000..21d55a4 --- /dev/null +++ b/tests/auto/declarative/qmlengine/qmlengine.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative webkit network +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlengine.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp new file mode 100644 index 0000000..ef1eee5 --- /dev/null +++ b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QmlEngine> +#include <QmlContext> +#include <QNetworkAccessManager> +#include <QPointer> +#include <QDir> +#include <QDesktopServices> +#include <QDebug> + +class tst_qmlengine : public QObject +{ + Q_OBJECT +public: + tst_qmlengine() {} + +private slots: + void rootContext(); + void networkAccessManager(); + void baseUrl(); + void contextForObject(); + void offlineStoragePath(); +}; + +void tst_qmlengine::rootContext() +{ + QmlEngine engine; + + QVERIFY(engine.rootContext()); + + QCOMPARE(engine.rootContext()->engine(), &engine); + QVERIFY(engine.rootContext()->parentContext() == 0); +} + +void tst_qmlengine::networkAccessManager() +{ + QmlEngine *engine = new QmlEngine; + + // Test QmlEngine created manager + QPointer<QNetworkAccessManager> manager = engine->networkAccessManager(); + QVERIFY(manager != 0); + + // Test non-QmlEngine owner manager + QNetworkAccessManager localManager; + engine->setNetworkAccessManager(&localManager); + QVERIFY(manager == 0); + QVERIFY(engine->networkAccessManager() == &localManager); + + // Test QmlEngine owned manager + QPointer<QNetworkAccessManager> ownedManager = new QNetworkAccessManager(engine); + QVERIFY(ownedManager != 0); + engine->setNetworkAccessManager(ownedManager); + QVERIFY(engine->networkAccessManager() == ownedManager); + engine->setNetworkAccessManager(&localManager); + QVERIFY(ownedManager == 0); + QVERIFY(engine->networkAccessManager() == &localManager); + + // Test setting a null manager + engine->setNetworkAccessManager(0); + QVERIFY(engine->networkAccessManager() != 0); +} + +void tst_qmlengine::baseUrl() +{ + QmlEngine engine; + + QUrl cwd = QUrl::fromLocalFile(QDir::currentPath() + QDir::separator()); + + QCOMPARE(engine.baseUrl(), cwd); + QCOMPARE(engine.rootContext()->resolvedUrl(QUrl("main.qml")), cwd.resolved(QUrl("main.qml"))); + + QDir dir = QDir::current(); + dir.cdUp(); + QVERIFY(dir != QDir::current()); + QDir::setCurrent(dir.path()); + QVERIFY(QDir::current() == dir); + + QUrl cwd2 = QUrl::fromLocalFile(QDir::currentPath() + QDir::separator()); + QCOMPARE(engine.baseUrl(), cwd2); + QCOMPARE(engine.rootContext()->resolvedUrl(QUrl("main.qml")), cwd2.resolved(QUrl("main.qml"))); + + engine.setBaseUrl(cwd); + QCOMPARE(engine.baseUrl(), cwd); + QCOMPARE(engine.rootContext()->resolvedUrl(QUrl("main.qml")), cwd.resolved(QUrl("main.qml"))); +} + +void tst_qmlengine::contextForObject() +{ + QmlEngine *engine = new QmlEngine; + + // Test null-object + QVERIFY(QmlEngine::contextForObject(0) == 0); + + // Test an object with no context + QObject object; + QVERIFY(QmlEngine::contextForObject(&object) == 0); + + // Test setting null-object + QmlEngine::setContextForObject(0, engine->rootContext()); + + // Test setting null-context + QmlEngine::setContextForObject(&object, 0); + + // Test setting context + QmlEngine::setContextForObject(&object, engine->rootContext()); + QVERIFY(QmlEngine::contextForObject(&object) == engine->rootContext()); + + QmlContext context(engine->rootContext()); + + // Try changing context + QTest::ignoreMessage(QtWarningMsg, "QmlEngine::setContextForObject(): Object already has a QmlContext"); + QmlEngine::setContextForObject(&object, &context); + QVERIFY(QmlEngine::contextForObject(&object) == engine->rootContext()); + + // Delete context + delete engine; engine = 0; + QVERIFY(QmlEngine::contextForObject(&object) == 0); +} + +void tst_qmlengine::offlineStoragePath() +{ + QmlEngine engine; + + QDir dir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); + dir.cd("QML"); + dir.cd("OfflineStorage"); + + QCOMPARE(engine.offlineStoragePath(), dir.path()); + + engine.setOfflineStoragePath(QDir::homePath()); + QCOMPARE(engine.offlineStoragePath(), QDir::homePath()); +} + +QTEST_MAIN(tst_qmlengine) + +#include "tst_qmlengine.moc" diff --git a/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp b/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp index 2648463..008dfb3 100644 --- a/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp +++ b/tests/auto/declarative/qmlsystempalette/tst_qmlsystempalette.cpp @@ -103,6 +103,7 @@ void tst_qmlsystempalette::inactivePalette() QmlSystemPalette *object = qobject_cast<QmlSystemPalette*>(component.create()); QVERIFY(object != 0); + QVERIFY(object->colorGroup() == QmlSystemPalette::Inactive); QPalette palette; palette.setCurrentColorGroup(QPalette::Inactive); @@ -131,6 +132,7 @@ void tst_qmlsystempalette::disabledPalette() QmlSystemPalette *object = qobject_cast<QmlSystemPalette*>(component.create()); QVERIFY(object != 0); + QVERIFY(object->colorGroup() == QmlSystemPalette::Disabled); QPalette palette; palette.setCurrentColorGroup(QPalette::Disabled); diff --git a/tests/auto/declarative/states/data/explicit.qml b/tests/auto/declarative/states/data/explicit.qml index 271115a..ca7e274 100644 --- a/tests/auto/declarative/states/data/explicit.qml +++ b/tests/auto/declarative/states/data/explicit.qml @@ -7,6 +7,7 @@ Rectangle { states: State { name: "blue" PropertyChanges { + objectName: "changes" target: MyRectangle; explicit: true color: sourceColor } diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 3d8f303..fe90191 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -42,6 +42,7 @@ #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> #include <private/qmlgraphicsrectangle_p.h> +#include <private/qmlpropertychanges_p.h> class tst_states : public QObject { @@ -61,6 +62,7 @@ private slots: void script(); void restoreEntryValues(); void explicitChanges(); + void propertyErrors(); }; void tst_states::basicChanges() @@ -544,6 +546,10 @@ void tst_states::explicitChanges() QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); QVERIFY(rect != 0); + QmlPropertyChanges *changes = qobject_cast<QmlPropertyChanges*>(rect->findChild<QmlPropertyChanges*>("changes")); + QVERIFY(changes != 0); + QVERIFY(changes->isExplicit()); + QCOMPARE(rect->color(),QColor("red")); rect->setState("blue"); @@ -561,6 +567,20 @@ void tst_states::explicitChanges() QCOMPARE(rect->color(),QColor("yellow")); } +void tst_states::propertyErrors() +{ + QmlEngine engine; + QmlComponent rectComponent(&engine, SRCDIR "/data/propertyErrors.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + QTest::ignoreMessage(QtWarningMsg, "QML QmlPropertyChanges (file://" SRCDIR "/data/propertyErrors.qml:8:9) Cannot assign to non-existant property \"colr\""); + QTest::ignoreMessage(QtWarningMsg, "QML QmlPropertyChanges (file://" SRCDIR "/data/propertyErrors.qml:8:9) Cannot assign to read-only property \"wantsFocus\""); + rect->setState("blue"); +} + QTEST_MAIN(tst_states) #include "tst_states.moc" diff --git a/tests/auto/declarative/xmlhttprequest/data/document.qml b/tests/auto/declarative/xmlhttprequest/data/document.qml index 7601a10..ce9e35f 100644 --- a/tests/auto/declarative/xmlhttprequest/data/document.qml +++ b/tests/auto/declarative/xmlhttprequest/data/document.qml @@ -25,6 +25,9 @@ Object { if (document.nodeValue != null) return; + if (document.parentNode != null) + return; + // ### Test other node properties // ### test encoding (what is a valid qt encoding?) xmlTest = true; diff --git a/tests/auto/declarative/xmlhttprequest/data/element.qml b/tests/auto/declarative/xmlhttprequest/data/element.qml index 79620bf..228db18 100644 --- a/tests/auto/declarative/xmlhttprequest/data/element.qml +++ b/tests/auto/declarative/xmlhttprequest/data/element.qml @@ -32,6 +32,15 @@ Object { if (e.childNodes[childTagNames.length + 1] != null) return; + // Check writing fails + e.childNodes[0] = null; + if (e.childNodes[0] == null) + return; + + e.childNodes[10] = 10; + if (e.childNodes[10] != null) + return; + if (e.firstChild.tagName != e.childNodes[0].tagName) return; @@ -70,6 +79,19 @@ Object { if (attrIdx2 != null) return; + // Check writing fails + e.attributes[0] = null; + if (e.attributes[0] == null) + return; + + e.attributes["attr"] = null; + if (e.attributes["attr"] == null) + return; + + e.attributes["attr3"] = 10; + if (e.attributes["attr3"] != null) + return; + // Check person and fruit sub elements if (person.parentNode.nodeName != "root") return; diff --git a/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_args.qml b/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_args.qml new file mode 100644 index 0000000..c2cf898 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_args.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Object { + property bool exceptionThrown: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "testdocument.html"); + x.send(); + + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + try { + x.getAllResponseHeaders("Test-header"); + } catch (e) { + if (e.code == DOMException.SYNTAX_ERR) + exceptionThrown = true; + } + } + } + } +} diff --git a/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_sent.qml b/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_sent.qml new file mode 100644 index 0000000..9583f9d --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_sent.qml @@ -0,0 +1,20 @@ +import Qt 4.6 + +Object { + property bool test: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "testdocument.html"); + x.send(); + + try { + x.getAllResponseHeaders(); + } catch (e) { + if (e.code == DOMException.INVALID_STATE_ERR) + test = true; + } + } +} + diff --git a/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_unsent.qml b/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_unsent.qml new file mode 100644 index 0000000..fac5259 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/getAllResponseHeaders_unsent.qml @@ -0,0 +1,16 @@ +import Qt 4.6 + +Object { + property bool test: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + try { + x.getAllResponseHeaders(); + } catch (e) { + if (e.code == DOMException.INVALID_STATE_ERR) + test = true; + } + } +} diff --git a/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_args.qml b/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_args.qml new file mode 100644 index 0000000..ca7aed8 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_args.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Object { + property bool exceptionThrown: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "testdocument.html"); + x.send(); + + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + try { + x.getResponseHeader(); + } catch (e) { + if (e.code == DOMException.SYNTAX_ERR) + exceptionThrown = true; + } + } + } + } +} diff --git a/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_sent.qml b/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_sent.qml new file mode 100644 index 0000000..148a19c --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_sent.qml @@ -0,0 +1,20 @@ +import Qt 4.6 + +Object { + property bool test: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "testdocument.html"); + x.send(); + + try { + x.getResponseHeader("Test-header"); + } catch (e) { + if (e.code == DOMException.INVALID_STATE_ERR) + test = true; + } + } +} + diff --git a/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_unsent.qml b/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_unsent.qml new file mode 100644 index 0000000..5abdf0a --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/getResponseHeader_unsent.qml @@ -0,0 +1,16 @@ +import Qt 4.6 + +Object { + property bool test: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + try { + x.getResponseHeader("Test-header"); + } catch (e) { + if (e.code == DOMException.INVALID_STATE_ERR) + test = true; + } + } +} diff --git a/tests/auto/declarative/xmlhttprequest/data/invalidMethodUsage.qml b/tests/auto/declarative/xmlhttprequest/data/invalidMethodUsage.qml new file mode 100644 index 0000000..893eb8b --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/invalidMethodUsage.qml @@ -0,0 +1,160 @@ +import Qt 4.6 + +Object { + property bool onreadystatechange: false + property bool readyState: false + property bool status: false + property bool statusText: false + property bool responseText: false + property bool responseXML: false + + property bool open: false + property bool setRequestHeader: false + property bool send: false + property bool abort: false + property bool getResponseHeader: false + property bool getAllResponseHeaders: false + + Component.onCompleted: { + var o = 10; + + try { + XMLHttpRequest.prototype.onreadystatechange + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + onreadystatechange = true; + } + try { + XMLHttpRequest.prototype.readyState + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + readyState = true; + } + try { + XMLHttpRequest.prototype.status + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + status = true; + } + try { + XMLHttpRequest.prototype.statusText + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + statusText = true; + } + try { + XMLHttpRequest.prototype.responseText + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + responseText = true; + } + try { + XMLHttpRequest.prototype.responseXML + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + responseXML = true; + } + + try { + XMLHttpRequest.prototype.open.call(o); + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + open = true; + } + + try { + XMLHttpRequest.prototype.setRequestHeader.call(o); + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + setRequestHeader = true; + } + + try { + XMLHttpRequest.prototype.send.call(o); + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + send = true; + } + + try { + XMLHttpRequest.prototype.abort.call(o); + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + abort = true; + } + + try { + XMLHttpRequest.prototype.getResponseHeader.call(o); + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + getResponseHeader = true; + } + + try { + XMLHttpRequest.prototype.getAllResponseHeaders.call(o); + } catch (e) { + if (!(e instanceof ReferenceError)) + return; + + if (e.message != "Not an XMLHttpRequest object") + return; + + getAllResponseHeaders = true; + } + } +} diff --git a/tests/auto/declarative/xmlhttprequest/data/open_user.qml b/tests/auto/declarative/xmlhttprequest/data/open_user.qml new file mode 100644 index 0000000..cc90433 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/open_user.qml @@ -0,0 +1,53 @@ +import Qt 4.6 + +Object { + property string url + + property bool readyState: false + property bool openedState: false + + property bool status: false + property bool statusText: false + property bool responseText: false + property bool responseXML: false + + property bool dataOK: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + if (x.readyState == XMLHttpRequest.UNSENT) + readyState = true; + + x.open("GET", url, true, "username", "password"); + + if (x.readyState == XMLHttpRequest.OPENED) + openedState = true; + + try { + var a = x.status; + } catch (error) { + if (error.code == DOMException.INVALID_STATE_ERR) + status = true; + } + try { + var a = x.statusText; + } catch (error) { + if (error.code == DOMException.INVALID_STATE_ERR) + statusText = true; + } + responseText = (x.responseText == ""); + responseXML = (x.responseXML == null); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + dataOK = (x.responseText == "QML Rocks!\n"); + } + } + + + x.send() + } +} + diff --git a/tests/auto/declarative/xmlhttprequest/data/send_data.4.qml b/tests/auto/declarative/xmlhttprequest/data/send_data.4.qml index 375f2fa..4705007 100644 --- a/tests/auto/declarative/xmlhttprequest/data/send_data.4.qml +++ b/tests/auto/declarative/xmlhttprequest/data/send_data.4.qml @@ -21,4 +21,3 @@ Object { } } - diff --git a/tests/auto/declarative/xmlhttprequest/data/send_data.7.qml b/tests/auto/declarative/xmlhttprequest/data/send_data.7.qml new file mode 100644 index 0000000..3a2ba56 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/send_data.7.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Object { + property string url + + property bool dataOK: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + x.open("POST", url); + x.setRequestHeader("Content-Type", "text/plain"); + + // Test to the end + x.onreadystatechange = function() { + if (x.readyState == XMLHttpRequest.DONE) { + dataOK = (x.responseText == "QML Rocks!\n"); + } + } + + x.send("My Sent Data"); + } +} + diff --git a/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_args.qml b/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_args.qml new file mode 100644 index 0000000..6824af2 --- /dev/null +++ b/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_args.qml @@ -0,0 +1,18 @@ +import Qt 4.6 + +Object { + property bool exceptionThrown: false + + Component.onCompleted: { + var x = new XMLHttpRequest; + + x.open("GET", "testdocument.html"); + + try { + x.setRequestHeader("Test-header"); + } catch (e) { + if (e.code == DOMException.SYNTAX_ERR) + exceptionThrown = true; + } + } +} diff --git a/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_illegalName.qml b/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_illegalName.qml index cf5ebcc..8029bc4 100644 --- a/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_illegalName.qml +++ b/tests/auto/declarative/xmlhttprequest/data/setRequestHeader_illegalName.qml @@ -22,6 +22,8 @@ Object { x.open("GET", url); + x.setRequestHeader(header, "Value"); + if (x.readyState == XMLHttpRequest.OPENED) openedState = true; diff --git a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp index 100a11b..e74d1c5 100644 --- a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp +++ b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp @@ -71,6 +71,7 @@ private slots: void setRequestHeader_illegalName_data(); void setRequestHeader_illegalName(); void setRequestHeader_sent(); + void setRequestHeader_args(); void send_unsent(); void send_alreadySent(); void send_ignoreData(); @@ -79,7 +80,13 @@ private slots: void abort_unsent(); void abort_opened(); void getResponseHeader(); + void getResponseHeader_unsent(); + void getResponseHeader_sent(); + void getResponseHeader_args(); void getAllResponseHeaders(); + void getAllResponseHeaders_unsent(); + void getAllResponseHeaders_sent(); + void getAllResponseHeaders_args(); void status(); void statusText(); void responseText(); @@ -283,6 +290,34 @@ void tst_xmlhttprequest::open() delete object; } + + // User/pass + { + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("open_network.expect"), + TEST_FILE("open_network.reply"), + TEST_FILE("testdocument.html"))); + + QmlComponent component(&engine, TEST_FILE("open_user.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + component.completeCreate(); + + QCOMPARE(object->property("readyState").toBool(), true); + QCOMPARE(object->property("openedState").toBool(), true); + QCOMPARE(object->property("status").toBool(), true); + QCOMPARE(object->property("statusText").toBool(), true); + QCOMPARE(object->property("responseText").toBool(), true); + QCOMPARE(object->property("responseXML").toBool(), true); + + TRY_WAIT(object->property("dataOK").toBool() == true); + + // ### Check that the username/password were sent to the server + + delete object; + } } // Test that calling XMLHttpRequest.open() with an invalid method raises an exception @@ -445,6 +480,18 @@ void tst_xmlhttprequest::setRequestHeader_sent() delete object; } +// Invalid arg count throws exception +void tst_xmlhttprequest::setRequestHeader_args() +{ + QmlComponent component(&engine, TEST_FILE("setRequestHeader_args.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("exceptionThrown").toBool(), true); + + delete object; +} + // Test that calling send() in UNSENT state throws an exception void tst_xmlhttprequest::send_unsent() { @@ -628,6 +675,25 @@ void tst_xmlhttprequest::send_withdata() delete object; } + + // Correct content-type - no charset + { + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + QVERIFY(server.wait(TEST_FILE("send_data.1.expect"), + TEST_FILE("send_data.reply"), + TEST_FILE("testdocument.html"))); + + QmlComponent component(&engine, TEST_FILE("send_data.7.qml")); + QObject *object = component.beginCreate(engine.rootContext()); + QVERIFY(object != 0); + object->setProperty("url", "http://127.0.0.1:14445/testdocument.html"); + component.completeCreate(); + + TRY_WAIT(object->property("dataOK").toBool() == true); + + delete object; + } } // Test abort() has no effect in unsent state @@ -736,6 +802,42 @@ void tst_xmlhttprequest::getResponseHeader() delete object; } +// Test getResponseHeader throws an exception in an invalid state +void tst_xmlhttprequest::getResponseHeader_unsent() +{ + QmlComponent component(&engine, TEST_FILE("getResponseHeader_unsent.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), true); + + delete object; +} + +// Test getResponseHeader throws an exception in an invalid state +void tst_xmlhttprequest::getResponseHeader_sent() +{ + QmlComponent component(&engine, TEST_FILE("getResponseHeader_sent.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), true); + + delete object; +} + +// Invalid arg count throws exception +void tst_xmlhttprequest::getResponseHeader_args() +{ + QmlComponent component(&engine, TEST_FILE("getResponseHeader_args.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + TRY_WAIT(object->property("exceptionThrown").toBool() == true); + + delete object; +} + void tst_xmlhttprequest::getAllResponseHeaders() { QmlEngine engine; // Avoid cookie contamination @@ -768,6 +870,42 @@ void tst_xmlhttprequest::getAllResponseHeaders() delete object; } +// Test getAllResponseHeaders throws an exception in an invalid state +void tst_xmlhttprequest::getAllResponseHeaders_unsent() +{ + QmlComponent component(&engine, TEST_FILE("getAllResponseHeaders_unsent.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), true); + + delete object; +} + +// Test getAllResponseHeaders throws an exception in an invalid state +void tst_xmlhttprequest::getAllResponseHeaders_sent() +{ + QmlComponent component(&engine, TEST_FILE("getAllResponseHeaders_sent.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test").toBool(), true); + + delete object; +} + +// Invalid arg count throws exception +void tst_xmlhttprequest::getAllResponseHeaders_args() +{ + QmlComponent component(&engine, TEST_FILE("getAllResponseHeaders_args.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + TRY_WAIT(object->property("exceptionThrown").toBool() == true); + + delete object; +} + void tst_xmlhttprequest::status() { { @@ -966,8 +1104,29 @@ void tst_xmlhttprequest::responseText() } } +// Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object +// throws an exception void tst_xmlhttprequest::invalidMethodUsage() { + QmlComponent component(&engine, TEST_FILE("invalidMethodUsage.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("onreadystatechange").toBool(), true); + QCOMPARE(object->property("readyState").toBool(), true); + QCOMPARE(object->property("status").toBool(), true); + QCOMPARE(object->property("statusText").toBool(), true); + QCOMPARE(object->property("responseText").toBool(), true); + QCOMPARE(object->property("responseXML").toBool(), true); + + QCOMPARE(object->property("open").toBool(), true); + QCOMPARE(object->property("setRequestHeader").toBool(), true); + QCOMPARE(object->property("send").toBool(), true); + QCOMPARE(object->property("abort").toBool(), true); + QCOMPARE(object->property("getResponseHeader").toBool(), true); + QCOMPARE(object->property("getAllResponseHeaders").toBool(), true); + + delete object; } void tst_xmlhttprequest::responseXML_invalid() |