aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-27 09:52:51 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-27 14:40:00 +0200
commite2447f9f5fbe6c8c070ce454bb48c5e45b8c35b3 (patch)
tree5ea8ffde57b47a44577ca79b90daafab52eedd1b /tests/auto/shared
parent8018c4b6e7743c576a3548f6e73e588f19f632a9 (diff)
parent7302bc550aa75600c7cdcf5c3d34404e0a09cf67 (diff)
Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts: .qmake.conf tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp Change-Id: I715b8a78b74cbe0dcaf599367fd6e08af4858e11
Diffstat (limited to 'tests/auto/shared')
-rw-r--r--tests/auto/shared/testhttpserver.cpp39
-rw-r--r--tests/auto/shared/testhttpserver.h8
2 files changed, 42 insertions, 5 deletions
diff --git a/tests/auto/shared/testhttpserver.cpp b/tests/auto/shared/testhttpserver.cpp
index 96655f1541..7235246fc0 100644
--- a/tests/auto/shared/testhttpserver.cpp
+++ b/tests/auto/shared/testhttpserver.cpp
@@ -87,9 +87,28 @@ TestHTTPServer::TestHTTPServer()
}
-bool TestHTTPServer::listen(quint16 port)
+bool TestHTTPServer::listen()
{
- return server.listen(QHostAddress::LocalHost, port);
+ return server.listen(QHostAddress::LocalHost, 0);
+}
+
+QUrl TestHTTPServer::baseUrl() const
+{
+ QUrl url;
+ url.setScheme(QStringLiteral("http"));
+ url.setHost(QStringLiteral("127.0.0.1"));
+ url.setPort(server.serverPort());
+ return url;
+}
+
+QUrl TestHTTPServer::url(const QString &documentPath) const
+{
+ return baseUrl().resolved(documentPath);
+}
+
+QString TestHTTPServer::urlString(const QString &documentPath) const
+{
+ return url(documentPath).toString();
}
QString TestHTTPServer::errorString() const
@@ -117,6 +136,11 @@ void TestHTTPServer::addRedirect(const QString &filename, const QString &redirec
redirects.insert(filename, redirectName);
}
+void TestHTTPServer::registerFileNameForContentSubstitution(const QString &fileName)
+{
+ contentSubstitutedFileNames.insert(fileName);
+}
+
bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &body)
{
m_state = AwaitingHeader;
@@ -135,6 +159,8 @@ bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &bod
bodyData = bodyFile.readAll();
}
+ const QByteArray serverHostUrl = QByteArrayLiteral("127.0.0.1:") + QByteArray::number(server.serverPort());
+
QByteArray line;
bool headers_done = false;
while (!(line = expectFile.readLine()).isEmpty()) {
@@ -143,10 +169,12 @@ bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &bod
headers_done = true;
continue;
}
- if (headers_done)
+ if (headers_done) {
waitData.body.append(line);
- else
+ } else {
+ line.replace("{{ServerHostUrl}}", serverHostUrl);
waitData.headers.append(line);
+ }
}
/*
while (waitData.endsWith('\n'))
@@ -277,6 +305,9 @@ bool TestHTTPServer::reply(QTcpSocket *socket, const QByteArray &fileName)
return true;
QByteArray data = file.readAll();
+ if (contentSubstitutedFileNames.contains("/" + fileName)) {
+ data.replace(QByteArrayLiteral("{{ServerBaseUrl}}"), baseUrl().toString().toUtf8());
+ }
QByteArray response = "HTTP/1.0 200 OK\r\nContent-type: text/html; charset=UTF-8\r\nContent-length: ";
response += QByteArray::number(data.count());
diff --git a/tests/auto/shared/testhttpserver.h b/tests/auto/shared/testhttpserver.h
index 559d78c148..0c0e799d8e 100644
--- a/tests/auto/shared/testhttpserver.h
+++ b/tests/auto/shared/testhttpserver.h
@@ -45,7 +45,10 @@ class TestHTTPServer : public QObject
public:
TestHTTPServer();
- bool listen(quint16 port);
+ bool listen();
+ QUrl baseUrl() const;
+ QUrl url(const QString &documentPath) const;
+ QString urlString(const QString &documentPath) const;
QString errorString() const;
enum Mode { Normal, Delay, Disconnect };
@@ -57,6 +60,8 @@ public:
void addAlias(const QString &filename, const QString &aliasName);
void addRedirect(const QString &filename, const QString &redirectName);
+ void registerFileNameForContentSubstitution(const QString &fileName);
+
// In Delay mode, each item needs one call to this function to be sent
void sendDelayedItem();
@@ -79,6 +84,7 @@ private:
QList<QPair<QString, Mode> > dirs;
QHash<QTcpSocket *, QByteArray> dataCache;
QList<QPair<QTcpSocket *, QByteArray> > toSend;
+ QSet<QString> contentSubstitutedFileNames;
struct WaitData {
QList <QByteArray>headers;