Changeset View
Changeset View
Standalone View
Standalone View
autotests/favicontest.cpp
Show All 30 Lines | |||||
31 | #include <QtConcurrentRun> | 31 | #include <QtConcurrentRun> | ||
32 | #include <QThreadPool> | 32 | #include <QThreadPool> | ||
33 | 33 | | |||
34 | static const char s_hostUrl[] = "http://www.google.com/index.html"; | 34 | static const char s_hostUrl[] = "http://www.google.com/index.html"; | ||
35 | static const char s_pageUrl[] = "http://www.google.com/somepage.html"; | 35 | static const char s_pageUrl[] = "http://www.google.com/somepage.html"; | ||
36 | static const char s_iconUrl[] = "http://www.google.com/favicon.ico"; | 36 | static const char s_iconUrl[] = "http://www.google.com/favicon.ico"; | ||
37 | static const char s_altIconUrl[] = "http://www.ibm.com/favicon.ico"; | 37 | static const char s_altIconUrl[] = "http://www.ibm.com/favicon.ico"; | ||
38 | static const char s_thirdIconUrl[] = "http://www.google.fr/favicon.ico"; | 38 | static const char s_thirdIconUrl[] = "http://www.google.fr/favicon.ico"; | ||
39 | static const char s_failingIconUrl[] = "https://www.kde.org/kio_test_non_existing_favicon.ico"; | ||||
39 | static const char s_iconUrlForThreadTest[] = "http://www.google.de/favicon.ico"; | 40 | static const char s_iconUrlForThreadTest[] = "http://www.google.de/favicon.ico"; | ||
40 | 41 | | |||
41 | static enum NetworkAccess { Unknown, Yes, No } s_networkAccess = Unknown; | 42 | static enum NetworkAccess { Unknown, Yes, No } s_networkAccess = Unknown; | ||
42 | static bool checkNetworkAccess() | 43 | static bool checkNetworkAccess() | ||
43 | { | 44 | { | ||
44 | if (s_networkAccess == Unknown) { | 45 | if (s_networkAccess == Unknown) { | ||
45 | QElapsedTimer tm; | 46 | QElapsedTimer tm; | ||
46 | tm.start(); | 47 | tm.start(); | ||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Line(s) | |||||
205 | } | 206 | } | ||
206 | 207 | | |||
207 | void FavIconTest::failedDownloadShouldBeRemembered() | 208 | void FavIconTest::failedDownloadShouldBeRemembered() | ||
208 | { | 209 | { | ||
209 | const QUrl url(s_pageUrl); | 210 | const QUrl url(s_pageUrl); | ||
210 | 211 | | |||
211 | // Set icon URL to a non-existing favicon | 212 | // Set icon URL to a non-existing favicon | ||
212 | KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(url); | 213 | KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(url); | ||
213 | job->setIconUrl(QUrl("http://www.kde.org/favicon.ico")); | 214 | job->setIconUrl(QUrl(s_failingIconUrl)); | ||
214 | QVERIFY(willDownload(job)); | 215 | QVERIFY(willDownload(job)); | ||
215 | QVERIFY(!job->exec()); | 216 | QVERIFY(!job->exec()); | ||
216 | QVERIFY(job->iconFile().isEmpty()); | 217 | QVERIFY(job->iconFile().isEmpty()); | ||
217 | QCOMPARE(job->error(), int(KIO::ERR_DOES_NOT_EXIST)); | 218 | QCOMPARE(job->error(), int(KIO::ERR_DOES_NOT_EXIST)); | ||
218 | QCOMPARE(job->errorString(), QStringLiteral("The file or folder http://www.kde.org/favicon.ico does not exist.")); | 219 | QCOMPARE(job->errorString(), QString("The file or folder %1 does not exist.").arg(s_failingIconUrl)); | ||
219 | 220 | | |||
220 | // Second job should use the cache and not do anything | 221 | // Second job should use the cache and not do anything | ||
221 | KIO::FavIconRequestJob *secondJob = new KIO::FavIconRequestJob(url); | 222 | KIO::FavIconRequestJob *secondJob = new KIO::FavIconRequestJob(url); | ||
222 | QVERIFY(!willDownload(secondJob)); | 223 | QVERIFY(!willDownload(secondJob)); | ||
223 | QVERIFY(!secondJob->exec()); | 224 | QVERIFY(!secondJob->exec()); | ||
224 | QVERIFY(secondJob->iconFile().isEmpty()); | 225 | QVERIFY(secondJob->iconFile().isEmpty()); | ||
225 | QCOMPARE(job->error(), int(KIO::ERR_DOES_NOT_EXIST)); | 226 | QCOMPARE(job->error(), int(KIO::ERR_DOES_NOT_EXIST)); | ||
226 | QCOMPARE(job->errorString(), QStringLiteral("The file or folder http://www.kde.org/favicon.ico does not exist.")); | 227 | QCOMPARE(job->errorString(), QString("The file or folder %1 does not exist.").arg(s_failingIconUrl)); | ||
227 | } | 228 | } | ||
228 | 229 | | |||
229 | void FavIconTest::tooBigFaviconShouldAbort() | 230 | void FavIconTest::tooBigFaviconShouldAbort() | ||
230 | { | 231 | { | ||
231 | const QUrl url(s_pageUrl); | 232 | const QUrl url(s_pageUrl); | ||
232 | 233 | | |||
233 | // Set icon URL to a >65KB file | 234 | // Set icon URL to a >65KB file | ||
234 | KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(url); | 235 | KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(url); | ||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |