File indexing completed on 2024-04-28 03:54:49
0001 /* 0002 0003 SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include <KIO/TransferJob> 0009 0010 #include <QSignalSpy> 0011 #include <QTest> 0012 0013 class UserAgentTest : public QObject 0014 { 0015 Q_OBJECT 0016 private Q_SLOTS: 0017 void testGet(); 0018 void testGet_data(); 0019 }; 0020 0021 void UserAgentTest::testGet_data() 0022 { 0023 QTest::addColumn<QString>("url"); 0024 QTest::addColumn<QString>("expectedMimeType"); 0025 QTest::addColumn<QByteArray>("expectedData"); 0026 0027 QTest::addRow("html") << "http://localhost:5000/useragent/enforce" 0028 << "text/html" << QByteArray("Hello"); 0029 } 0030 0031 void UserAgentTest::testGet() 0032 { 0033 QFETCH(QString, url); 0034 QFETCH(QString, expectedMimeType); 0035 QFETCH(QByteArray, expectedData); 0036 0037 auto *job = KIO::get(QUrl(url)); 0038 0039 job->addMetaData("UserAgent", "my test UA"); 0040 0041 QSignalSpy dataSpy(job, &KIO::TransferJob::data); 0042 QSignalSpy spy(job, &KJob::finished); 0043 spy.wait(); 0044 QVERIFY(spy.size()); 0045 0046 QVERIFY(dataSpy.count()); 0047 const QByteArray actualData = dataSpy.first().at(1).toByteArray(); 0048 QCOMPARE(actualData, expectedData); 0049 0050 QCOMPARE(job->error(), KJob::NoError); 0051 } 0052 0053 QTEST_GUILESS_MAIN(UserAgentTest) 0054 0055 #include "useragenttest.moc"