diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-04-16 14:02:02 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-19 19:46:07 +0200 |
commit | a6156d1aedaba720fe4618828609dbae931af313 (patch) | |
tree | 7eca8e57f846ce835eabeee0d62a32667835630e | |
parent | af100dbd7e23076f8873f9ee8847d1ac90bb1700 (diff) |
Add test case for checking ConnectInBackground is set
ConnectInBackground should be set when opening a network session
due to a background request. This test checks that.
Unfortunately, none of the bearer plugins currently in Qt Base support
this attribute, so the test result is inconclusive.
(testing with a debugger shows the attribute is set correctly, but
it can't be read back as the set is discarded by the plugin
implementation)
Change-Id: Idcf777fe489a62d4ff5007ffd291a84ba052311b
Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
-rw-r--r-- | tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index aede0d290b..726e986e99 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -407,7 +407,8 @@ private Q_SLOTS: void backgroundRequest(); void backgroundRequestInterruption_data(); void backgroundRequestInterruption(); - + void backgroundRequestConnectInBackground_data(); + void backgroundRequestConnectInBackground(); // NOTE: This test must be last! void parentingRepliesToTheApp(); @@ -6956,6 +6957,68 @@ void tst_QNetworkReply::backgroundRequestInterruption() #endif } +void tst_QNetworkReply::backgroundRequestConnectInBackground_data() +{ + QTest::addColumn<QUrl>("url"); + QTest::addColumn<bool>("background"); + + QUrl httpurl("http://" + QtNetworkSettings::serverName()); + QUrl ftpurl("ftp://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"); + + QTest::newRow("http, fg") << httpurl << false; + QTest::newRow("http, bg") << httpurl << true; + + QTest::newRow("ftp, fg") << ftpurl << false; + QTest::newRow("ftp, bg") << ftpurl << true; +} + +//test purpose: check that backgroundness is propagated to the network session +void tst_QNetworkReply::backgroundRequestConnectInBackground() +{ +#ifdef QT_BUILD_INTERNAL +#ifndef QT_NO_BEARERMANAGEMENT + QFETCH(QUrl, url); + QFETCH(bool, background); + + QNetworkRequest request(url); + + if (background) + request.setAttribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(true)); + + QWeakPointer<const QNetworkSession> session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + //force QNAM to reopen the session. + if (session && session.data()->isOpen()) { + const_cast<QNetworkSession *>(session.data())->close(); + QCoreApplication::processEvents(); //let signals propagate inside QNAM + } + + //this preconstructs the session so we can change policies in advance + manager.setConfiguration(networkConfiguration); + + session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + QVERIFY(session); + QNetworkSession::UsagePolicies original = session.data()->usagePolicies(); + QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), QNetworkSession::NoPolicy); + + QNetworkReplyPtr reply(manager.get(request)); + + QVERIFY(waitForFinish(reply) != Timeout); + session = QNetworkAccessManagerPrivate::getNetworkSession(&manager); + if (session) { + QVariant cib = session.data()->sessionProperty(QStringLiteral("ConnectInBackground")); + if (!cib.isValid()) + QSKIP("inconclusive - ConnectInBackground session property not supported by the bearer plugin"); + QCOMPARE(cib.toBool(), background); + QNetworkSessionPrivate::setUsagePolicies(*const_cast<QNetworkSession *>(session.data()), original); + } else { + QSKIP("inconclusive - network session has been destroyed"); + } + + QVERIFY(reply->isFinished()); +#endif +#endif +} + // NOTE: This test must be last testcase in tst_qnetworkreply! void tst_QNetworkReply::parentingRepliesToTheApp() { |