Changeset View
Changeset View
Standalone View
Standalone View
autotests/openurljobtest.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 71 | { | |||
---|---|---|---|---|---|
74 | // Ensure no leftovers from other tests | 74 | // Ensure no leftovers from other tests | ||
75 | QDir(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)).removeRecursively(); | 75 | QDir(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)).removeRecursively(); | ||
76 | // (including a mimeapps.list file) | 76 | // (including a mimeapps.list file) | ||
77 | // Don't remove ConfigLocation completely, it's useful when enabling debug output with kdebugsettings --test-mode | 77 | // Don't remove ConfigLocation completely, it's useful when enabling debug output with kdebugsettings --test-mode | ||
78 | const QString mimeApps = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/mimeapps.list"); | 78 | const QString mimeApps = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/mimeapps.list"); | ||
79 | QFile::remove(mimeApps); | 79 | QFile::remove(mimeApps); | ||
80 | 80 | | |||
81 | ksycoca_ms_between_checks = 0; // need it to check the ksycoca mtime | 81 | ksycoca_ms_between_checks = 0; // need it to check the ksycoca mtime | ||
82 | QString fakeService = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + QLatin1Char('/') + s_tempServiceName; | 82 | m_fakeService = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + QLatin1Char('/') + s_tempServiceName; | ||
83 | writeApplicationDesktopFile(fakeService); | 83 | writeApplicationDesktopFile(m_fakeService); | ||
84 | fakeService = QFileInfo(fakeService).canonicalFilePath(); | 84 | m_fakeService = QFileInfo(m_fakeService).canonicalFilePath(); | ||
85 | m_filesToRemove.append(fakeService); | 85 | m_filesToRemove.append(m_fakeService); | ||
86 | 86 | | |||
87 | // Ensure our service is the preferred one | 87 | // Ensure our service is the preferred one | ||
88 | KConfig mimeAppsCfg(mimeApps); | 88 | KConfig mimeAppsCfg(mimeApps); | ||
89 | KConfigGroup grp = mimeAppsCfg.group("Default Applications"); | 89 | KConfigGroup grp = mimeAppsCfg.group("Default Applications"); | ||
90 | grp.writeEntry("text/plain", s_tempServiceName); | 90 | grp.writeEntry("text/plain", s_tempServiceName); | ||
91 | grp.writeEntry("text/html", s_tempServiceName); | 91 | grp.writeEntry("text/html", s_tempServiceName); | ||
92 | grp.writeEntry("application/x-shellscript", s_tempServiceName); | 92 | grp.writeEntry("application/x-shellscript", s_tempServiceName); | ||
93 | grp.sync(); | 93 | grp.sync(); | ||
94 | 94 | | |||
95 | for (const char *mimeType : {"text/plain", "application/x-shellscript"}) { | 95 | for (const char *mimeType : {"text/plain", "application/x-shellscript"}) { | ||
96 | KService::Ptr preferredTextEditor = KApplicationTrader::preferredService(QString::fromLatin1(mimeType)); | 96 | KService::Ptr preferredTextEditor = KApplicationTrader::preferredService(QString::fromLatin1(mimeType)); | ||
97 | QVERIFY(preferredTextEditor); | 97 | QVERIFY(preferredTextEditor); | ||
98 | QCOMPARE(preferredTextEditor->entryPath(), fakeService); | 98 | QCOMPARE(preferredTextEditor->entryPath(), m_fakeService); | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | // As used for preferredService | 101 | // As used for preferredService | ||
102 | QVERIFY(KService::serviceByDesktopName("openurljobtest_service")); | 102 | QVERIFY(KService::serviceByDesktopName("openurljobtest_service")); | ||
103 | 103 | | |||
104 | ksycoca_ms_between_checks = 5000; // all done, speed up again | 104 | ksycoca_ms_between_checks = 5000; // all done, speed up again | ||
105 | } | 105 | } | ||
106 | 106 | | |||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Line(s) | 436 | connect(job, &KIO::OpenUrlJob::mimeTypeFound, this, [&](const QString &mimeType) { | |||
437 | foundMime = mimeType; | 437 | foundMime = mimeType; | ||
438 | job->kill(); | 438 | job->kill(); | ||
439 | }); | 439 | }); | ||
440 | QVERIFY(!job->exec()); | 440 | QVERIFY(!job->exec()); | ||
441 | QCOMPARE(job->error(), KJob::KilledJobError); | 441 | QCOMPARE(job->error(), KJob::KilledJobError); | ||
442 | QCOMPARE(foundMime, "image/jpeg"); | 442 | QCOMPARE(foundMime, "image/jpeg"); | ||
443 | } | 443 | } | ||
444 | 444 | | |||
445 | void OpenUrlJobTest::runDeskopFileDirectly() | ||||
446 | { | ||||
447 | KIO::OpenUrlJob *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(m_fakeService), this); | ||||
448 | job->setRunExecutables(true); | ||||
449 | QVERIFY(job->exec()); | ||||
450 | | ||||
451 | const QString dest = m_tempDir.path() + "/dest"; | ||||
452 | QTRY_VERIFY2(QFile::exists(dest), qPrintable(dest)); | ||||
453 | QCOMPARE(readFile(dest), QString{}); | ||||
454 | } | ||||
455 | | ||||
445 | void OpenUrlJobTest::writeApplicationDesktopFile(const QString &filePath) | 456 | void OpenUrlJobTest::writeApplicationDesktopFile(const QString &filePath) | ||
446 | { | 457 | { | ||
447 | KDesktopFile file(filePath); | 458 | KDesktopFile file(filePath); | ||
448 | KConfigGroup group = file.desktopGroup(); | 459 | KConfigGroup group = file.desktopGroup(); | ||
449 | group.writeEntry("Name", "KRunUnittestService"); | 460 | group.writeEntry("Name", "KRunUnittestService"); | ||
450 | group.writeEntry("MimeType", "text/plain;application/x-shellscript;x-scheme-handler/scheme"); | 461 | group.writeEntry("MimeType", "text/plain;application/x-shellscript;x-scheme-handler/scheme"); | ||
451 | group.writeEntry("Type", "Application"); | 462 | group.writeEntry("Type", "Application"); | ||
452 | group.writeEntry("Exec", QByteArray("echo %u > " + QFile::encodeName(m_tempDir.path()) + "/dest")); // not using %d because of remote urls | 463 | group.writeEntry("Exec", QByteArray("echo %u > " + QFile::encodeName(m_tempDir.path()) + "/dest")); // not using %d because of remote urls | ||
453 | QVERIFY(file.sync()); | 464 | QVERIFY(file.sync()); | ||
454 | } | 465 | } |