diff --git a/autotests/data/plainText.pdf b/autotests/data/plainText.pdf new file mode 100644 --- /dev/null +++ b/autotests/data/plainText.pdf @@ -0,0 +1 @@ +This is a text file with wrong file ending. diff --git a/autotests/parttest.cpp b/autotests/parttest.cpp --- a/autotests/parttest.cpp +++ b/autotests/parttest.cpp @@ -15,6 +15,8 @@ #include "../ui/pageview.h" #include +#include +#include #include #include @@ -39,6 +41,8 @@ void testGeneratorPreferences(); void testSelectText(); void testClickInternalLink(); + void testOpenUrlArguments(); + void testChooseBackendByMimeType(); }; class PartThatHijacksQueryClose : public Okular::Part @@ -251,6 +255,37 @@ QCOMPARE(part.m_document->currentPage(), 1u); } +// Test that OpenUrlArguments passed to Okular are not dropped on calls to openUrl +void PartTest::testOpenUrlArguments() +{ + QVariantList dummyArgs; + Okular::Part part(NULL, NULL, dummyArgs); + + KParts::OpenUrlArguments args; + args.setMimeType(QStringLiteral("text/plain")); + + part.setArguments(args); + + part.openUrl(QUrl::fromLocalFile(KDESRCDIR "data/file1.pdf")); + + QCOMPARE( part.arguments().mimeType(), QStringLiteral("text/plain") ); +} + +// Test that Okular uses the correct backend when given a mime type through OpenUrlArguments +void PartTest::testChooseBackendByMimeType() +{ + QVariantList dummyArgs; + Okular::Part part(NULL, NULL, dummyArgs); + + KParts::OpenUrlArguments args; + args.setMimeType("text/plain"); + + part.setArguments(args); + part.openUrl(QUrl::fromLocalFile(KDESRCDIR "data/plainText.pdf")); + + QCOMPARE( part.m_document->generatorInfo().pluginId(), QStringLiteral("okular_txt") ); +} + } int main(int argc, char *argv[]) diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -1397,7 +1397,7 @@ } else { - mimes << pathMime << argMime; + mimes << argMime << pathMime; } if (mimes[0].name() == QLatin1String("text/plain")) { @@ -1541,9 +1541,15 @@ bool Part::openUrl(const QUrl &_url) { + // The subsequent call to closeUrl clears the arguments. + // We want to save them and restore them later. + KParts::OpenUrlArguments args = arguments(); + // Close current document if any if ( !closeUrl() ) return false; + + setArguments(args); QUrl url( _url ); if ( url.hasFragment() )