summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qtbug_110287/tst_qtbug_110287.cpp
blob: 9453ae9b845c76962781629b82b0ba1d80c5ea20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QSignalSpy>
#include <QTest>
#include <QWebEngineView>

class tst_qtbug_110287 : public QObject
{
    Q_OBJECT
public:
    tst_qtbug_110287() { }

private slots:
    void getAddrInfo();
};

void tst_qtbug_110287::getAddrInfo()
{
    QNetworkAccessManager nam;
    QSignalSpy namSpy(&nam, &QNetworkAccessManager::finished);

    QString address("http://www.example.com");
    QScopedPointer<QNetworkReply> reply(nam.get(QNetworkRequest(address)));

    if (!namSpy.wait(25000) || reply->error() != QNetworkReply::NoError)
        QSKIP("Couldn't load page from network, skipping test.");

    QWebEngineView view;
    QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool)));

    // load() will trigger system DNS resolution that uses getaddrinfo()
    view.load(QUrl(address));
    QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.size() > 0, true, 30000);
    QTRY_COMPARE(loadFinishedSpy[0][0].toBool(), true);
}

#include "tst_qtbug_110287.moc"
QTEST_MAIN(tst_qtbug_110287)