Use the correct scheme in setUrlHandler() for openUrlExternally() tests

testFileUrl() can return a QUrl with either file or qrc scheme, so the
handler need to register the correct scheme as well.

Task-number: QTBUG-97056
Pick-to: 6.2 6.3
Change-Id: I87028f75bbaf267b5eb58d28497cd2bea593c02a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Assam Boudjelthia 2021-12-13 14:27:17 +02:00
parent 220a547aa4
commit 36874e799a
1 changed files with 8 additions and 6 deletions

View File

@ -634,8 +634,9 @@ void tst_qqmlqt::openUrlExternally()
{
MyUrlHandler handler;
const QUrl htmlTestFile = testFileUrl("test.html");
QDesktopServices::setUrlHandler("test", &handler, "noteCall");
QDesktopServices::setUrlHandler("file", &handler, "noteCall");
QDesktopServices::setUrlHandler(htmlTestFile.scheme(), &handler, "noteCall");
QQmlComponent component(&engine, testFileUrl("openUrlExternally.qml"));
QScopedPointer<QObject> object(component.create());
@ -646,18 +647,19 @@ void tst_qqmlqt::openUrlExternally()
object->setProperty("testFile", true);
QCOMPARE(handler.called,2);
QCOMPARE(handler.last, testFileUrl("test.html"));
QCOMPARE(handler.last, htmlTestFile);
QDesktopServices::unsetUrlHandler("test");
QDesktopServices::unsetUrlHandler("file");
QDesktopServices::unsetUrlHandler(htmlTestFile.scheme());
}
void tst_qqmlqt::openUrlExternally_pragmaLibrary()
{
MyUrlHandler handler;
const QUrl htmlTestFile = testFileUrl("test.html");
QDesktopServices::setUrlHandler("test", &handler, "noteCall");
QDesktopServices::setUrlHandler("file", &handler, "noteCall");
QDesktopServices::setUrlHandler(htmlTestFile.scheme(), &handler, "noteCall");
QQmlComponent component(&engine, testFileUrl("openUrlExternally_lib.qml"));
QScopedPointer<QObject> object(component.create());
@ -668,10 +670,10 @@ void tst_qqmlqt::openUrlExternally_pragmaLibrary()
object->setProperty("testFile", true);
QCOMPARE(handler.called,2);
QCOMPARE(handler.last, testFileUrl("test.html"));
QCOMPARE(handler.last, htmlTestFile);
QDesktopServices::unsetUrlHandler("test");
QDesktopServices::unsetUrlHandler("file");
QDesktopServices::unsetUrlHandler(htmlTestFile.scheme());
}
void tst_qqmlqt::md5()