summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-05-09 21:54:18 +1000
committerQt Continuous Integration System <qt-info@nokia.com>2011-05-09 21:54:18 +1000
commite8aceff19523a2fb048690798d789f0ec248696d (patch)
tree2304fe2216d6fc4ebbeb6bad9cfdbe3fb24876c2 /tests
parent38644abb0d15188e2f79f323ba091328aa0bd4ba (diff)
parent939886720920f907884b8b32bf501354ed805857 (diff)
Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-earth-staging
* 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-earth-staging: Skip test on MacOS due to problems with corewlan plugin Fix QNetworkConfigurationManager usage outside main thread first Update QTBUG-17223 for Qt 4.8 fix tst_qnetworkreply::httpProxyCommands autotest Send User-Agent from the network request in http proxy CONNECT command Add autotests for configuration dependent network proxies Fix QNetworkReplyImpl error handling Enable per network configuration proxy settings in QNetworkAccessManager Allow a network configuration to be included in a proxy query Fix error handling in write for socks socket engine
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp42
-rw-r--r--tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro2
-rw-r--r--tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp175
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp19
4 files changed, 234 insertions, 4 deletions
diff --git a/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp b/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
index 7787608485..c270eb8813 100644
--- a/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
+++ b/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
@@ -62,6 +62,7 @@ public slots:
void cleanup();
private slots:
+ void usedInThread(); // this test must be first, or it will falsely pass
void allConfigurations();
void defaultConfiguration();
void configurationFromIdentifier();
@@ -329,6 +330,47 @@ void tst_QNetworkConfigurationManager::configurationFromIdentifier()
QVERIFY(!invalid.isValid());
}
+class QNCMTestThread : public QThread
+{
+protected:
+ virtual void run()
+ {
+ QNetworkConfigurationManager manager;
+ preScanConfigs = manager.allConfigurations();
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ configs = manager.allConfigurations();
+ }
+public:
+ QList<QNetworkConfiguration> configs;
+ QList<QNetworkConfiguration> preScanConfigs;
+};
+
+// regression test for QTBUG-18795
+void tst_QNetworkConfigurationManager::usedInThread()
+{
+#if defined Q_OS_MAC && !defined (QT_NO_COREWLAN)
+ QSKIP("QTBUG-19070 Mac CoreWlan plugin is broken", SkipAll);
+#else
+ QNCMTestThread thread;
+ connect(&thread, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ thread.start();
+ QTestEventLoop::instance().enterLoop(100); //QTRY_VERIFY could take ~90 seconds to time out in the thread
+ QVERIFY(thread.isFinished());
+ qDebug() << "prescan:" << thread.preScanConfigs.count();
+ qDebug() << "postscan:" << thread.configs.count();
+
+ QNetworkConfigurationManager manager;
+ QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations();
+ QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
+ manager.updateConfigurations(); //initiate scans
+ QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QList<QNetworkConfiguration> configs = manager.allConfigurations();
+ QCOMPARE(thread.configs, configs);
+ QCOMPARE(thread.preScanConfigs, preScanConfigs);
+#endif
+}
QTEST_MAIN(tst_QNetworkConfigurationManager)
#include "tst_qnetworkconfigurationmanager.moc"
diff --git a/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro b/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro
index f05c423087..17ad403ba7 100644
--- a/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro
+++ b/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro
@@ -7,5 +7,5 @@ QT = core network
SOURCES += tst_qnetworkproxyfactory.cpp
-symbian: TARGET.CAPABILITY = NetworkServices
+symbian: TARGET.CAPABILITY = NetworkServices ReadUserData
diff --git a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
index 2baee27d5f..90ab8e045d 100644
--- a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
+++ b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
@@ -41,20 +41,64 @@
#include <QtTest/QTest>
+#include <QtTest/QTestEventLoop>
#include <qcoreapplication.h>
#include <qdebug.h>
#include <qnetworkproxy.h>
+#include <QNetworkConfiguration>
+#include <QNetworkConfigurationManager>
+#include <QNetworkSession>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QList>
+
+Q_DECLARE_METATYPE(QNetworkConfiguration);
+Q_DECLARE_METATYPE(QList<QNetworkProxy>);
+
+#include <QThread>
+
class tst_QNetworkProxyFactory : public QObject {
Q_OBJECT
+
+public:
+ tst_QNetworkProxyFactory();
+
+ class QDebugProxyFactory : public QNetworkProxyFactory
+ {
+ public:
+ virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery())
+ {
+ returnedList = QNetworkProxyFactory::systemProxyForQuery(query);
+ requestCounter++;
+ return returnedList;
+ }
+ QList<QNetworkProxy> returnedList;
+ int requestCounter;
+ };
+
private slots:
+ void systemProxyForQueryCalledFromThread();
void systemProxyForQuery() const;
+#ifndef QT_NO_BEARERMANAGEMENT
+ void fromConfigurations();
+ void inNetworkAccessManager_data();
+ void inNetworkAccessManager();
+#endif
private:
QString formatProxyName(const QNetworkProxy & proxy) const;
+ QDebugProxyFactory *factory;
};
+tst_QNetworkProxyFactory::tst_QNetworkProxyFactory()
+{
+ factory = new QDebugProxyFactory;
+ QNetworkProxyFactory::setApplicationProxyFactory(factory);
+}
+
QString tst_QNetworkProxyFactory::formatProxyName(const QNetworkProxy & proxy) const
{
QString proxyName;
@@ -96,5 +140,136 @@ void tst_QNetworkProxyFactory::systemProxyForQuery() const
QFAIL("One or more system proxy lookup failures occurred.");
}
+#ifndef QT_NO_BEARERMANAGEMENT
+
+//Purpose of this test is just to check systemProxyForQuery doesn't hang or crash
+//with any given configuration including no configuration.
+//We can't test it returns the right proxies without implementing the native proxy code
+//again here, which would be testing our implementation against itself.
+//Therefore it's just testing that something valid is returned (at least a NoProxy entry)
+void tst_QNetworkProxyFactory::fromConfigurations()
+{
+ QNetworkConfigurationManager manager;
+ QList<QNetworkProxy> proxies;
+ QUrl url(QLatin1String("http://qt.nokia.com"));
+ //get from known configurations
+ foreach (QNetworkConfiguration config, manager.allConfigurations()) {
+ QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest);
+ proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy);
+ }
+ }
+
+ //get from default configuration
+ QNetworkProxyQuery defaultquery(url, QNetworkProxyQuery::UrlRequest);
+ proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << "default - " << formatProxyName(proxy);
+ }
+
+ //get from active configuration
+ QNetworkSession session(manager.defaultConfiguration());
+ session.open();
+ QVERIFY(session.waitForOpened(30000));
+ proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << "active - " << formatProxyName(proxy);
+ }
+
+ //get from known configurations while there is one active
+ foreach (QNetworkConfiguration config, manager.allConfigurations()) {
+ QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest);
+ proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ QVERIFY(!proxies.isEmpty());
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy);
+ }
+ }
+}
+
+void tst_QNetworkProxyFactory::inNetworkAccessManager_data()
+{
+ QTest::addColumn<QNetworkConfiguration>("config");
+ QTest::addColumn<QList<QNetworkProxy> >("proxies");
+ QNetworkConfigurationManager manager;
+ //get from known configurations
+ foreach (QNetworkConfiguration config, manager.allConfigurations()) {
+ QNetworkProxyQuery query(config, QUrl(QString("http://qt.nokia.com")), QNetworkProxyQuery::UrlRequest);
+ QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ QTest::newRow(config.name().toUtf8()) << config << proxies;
+ }
+}
+
+//Purpose of this test is to check that QNetworkAccessManager uses the proxy from the configuration it
+//has been given. Needs two or more working configurations to be a good test.
+void tst_QNetworkProxyFactory::inNetworkAccessManager()
+{
+ QFETCH(QNetworkConfiguration, config);
+ QFETCH(QList<QNetworkProxy>, proxies);
+
+ int count = factory->requestCounter;
+
+ QNetworkAccessManager manager;
+ manager.setConfiguration(config);
+
+ //using an internet server, because cellular APs won't have a route to the test server.
+ QNetworkRequest req(QUrl(QString("http://qt.nokia.com")));
+ QNetworkReply *reply = manager.get(req);
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(30);
+ delete reply;
+
+ if (count == factory->requestCounter) {
+ //RND phones are preconfigured with several test access points which won't work without a matching SIM
+ //If the network fails to start, QNAM won't ask the factory for proxies so we can't test.
+ QSKIP("network configuration didn't start", SkipSingle);
+ }
+
+ qDebug() << "testing network configuration for" << config.name();
+ foreach (QNetworkProxy proxy, factory->returnedList) {
+ qDebug() << formatProxyName(proxy);
+ }
+ qDebug() << " <vs> ";
+ foreach (QNetworkProxy proxy, proxies) {
+ qDebug() << formatProxyName(proxy);
+ }
+ if (config.type() != QNetworkConfiguration::InternetAccessPoint)
+ QEXPECT_FAIL("","QNetworkProxyFactory::systemProxyForQuery doesn't work for service networks yet", Continue);
+ QCOMPARE(factory->returnedList, proxies);
+}
+
+#endif //QT_NO_BEARERMANAGEMENT
+
+
+class QSPFQThread : public QThread
+{
+protected:
+ virtual void run()
+ {
+ proxies = QNetworkProxyFactory::systemProxyForQuery(query);
+ }
+public:
+ QNetworkProxyQuery query;
+ QList<QNetworkProxy> proxies;
+};
+
+//regression test for QTBUG-18799
+void tst_QNetworkProxyFactory::systemProxyForQueryCalledFromThread()
+{
+ QUrl url(QLatin1String("http://qt.nokia.com"));
+ QNetworkProxyQuery query(url);
+ QSPFQThread thread;
+ thread.query = query;
+ connect(&thread, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ thread.start();
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(thread.isFinished());
+ QCOMPARE(thread.proxies, QNetworkProxyFactory::systemProxyForQuery(query));
+}
+
QTEST_MAIN(tst_QNetworkProxyFactory)
#include "tst_qnetworkproxyfactory.moc"
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index f7365dfbfd..6c77f11d03 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -4970,17 +4970,24 @@ void tst_QNetworkReply::httpProxyCommands()
QNetworkProxy proxy(QNetworkProxy::HttpProxy, "127.0.0.1", proxyServer.serverPort());
manager.setProxy(proxy);
- QNetworkReplyPtr reply = manager.get(QNetworkRequest(url));
- manager.setProxy(QNetworkProxy());
+ QNetworkRequest request(url);
+ request.setRawHeader("User-Agent", "QNetworkReplyAutoTest/1.0");
+ QNetworkReplyPtr reply = manager.get(request);
+ //clearing the proxy here causes the test to fail.
+ //the proxy isn't used until after the bearer has been started
+ //which is correct in general, because system proxy isn't known until that time.
+ //removing this line is safe, as the proxy is also reset by the cleanup() function
+ //manager.setProxy(QNetworkProxy());
// wait for the finished signal
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QTestEventLoop::instance().enterLoop(1);
+ QTestEventLoop::instance().enterLoop(15);
QVERIFY(!QTestEventLoop::instance().timeout());
//qDebug() << reply->error() << reply->errorString();
+ //qDebug() << proxyServer.receivedData;
// we don't really care if the request succeeded
// especially since it won't succeed in the HTTPS case
@@ -4988,6 +4995,12 @@ void tst_QNetworkReply::httpProxyCommands()
QString receivedHeader = proxyServer.receivedData.left(expectedCommand.length());
QCOMPARE(receivedHeader, expectedCommand);
+
+ //QTBUG-17223 - make sure the user agent from the request is sent to proxy server even for CONNECT
+ int uapos = proxyServer.receivedData.indexOf("User-Agent");
+ int uaend = proxyServer.receivedData.indexOf("\r\n", uapos);
+ QByteArray uaheader = proxyServer.receivedData.mid(uapos, uaend - uapos);
+ QCOMPARE(uaheader, QByteArray("User-Agent: QNetworkReplyAutoTest/1.0"));
}
class ProxyChangeHelper : public QObject {