| 1 |
// Copyright (C) 2016 Intel Corporation. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <QString> |
| 5 |
#include <QTest> |
| 6 |
#include <QCoreApplication> |
| 7 |
#include <QDesktopServices> |
| 8 |
|
| 9 |
class tst_QDesktopServices : public QObject |
| 10 |
{ |
| 11 |
Q_OBJECT |
| 12 |
|
| 13 |
private Q_SLOTS: |
| 14 |
void openUrl(); |
| 15 |
void openUrl_data(); |
| 16 |
}; |
| 17 |
|
| 18 |
void tst_QDesktopServices::openUrl_data() |
| 19 |
{ |
| 20 |
QTest::addColumn<QUrl>("data"); |
| 21 |
QTest::addColumn<QString>("message"); |
| 22 |
|
| 23 |
QUrl localFile = QUrl::fromLocalFile(QFINDTESTDATA("test.txt")); |
| 24 |
|
| 25 |
QTest::newRow("text-file") |
| 26 |
<< localFile |
| 27 |
<< "This should open test.txt in a text editor"; |
| 28 |
|
| 29 |
localFile.setQuery("x=y"); |
| 30 |
QTest::newRow("text-file-with-query") |
| 31 |
<< localFile |
| 32 |
<< "This should open test.txt in a text editor. Queries do not usually show up."; |
| 33 |
|
| 34 |
localFile.setQuery(QString()); |
| 35 |
localFile.setFragment("top"); |
| 36 |
QTest::newRow("text-file-with-fragment") |
| 37 |
<< localFile |
| 38 |
<< "This should open test.txt in a text editor. Fragments do not usually show up."; |
| 39 |
|
| 40 |
QTest::newRow("browser-plain") |
| 41 |
<< QUrl("http://qt-project.org") |
| 42 |
<< "This should open http://qt-project.org in the default web browser"; |
| 43 |
|
| 44 |
QTest::newRow("search-url") |
| 45 |
<< QUrl("http://google.com/search?q=Qt+Project") |
| 46 |
<< "This should search \"Qt Project\" on Google"; |
| 47 |
|
| 48 |
QTest::newRow("search-url-with-space") |
| 49 |
<< QUrl("http://google.com/search?q=Qt Project") |
| 50 |
<< "This should search \"Qt Project\" on Google"; |
| 51 |
|
| 52 |
QTest::newRow("search-url-with-quotes") |
| 53 |
<< QUrl("http://google.com/search?q=\"Qt+Project\"") |
| 54 |
<< "This should search '\"Qt Project\"' on Google (including the quotes)"; |
| 55 |
|
| 56 |
QTest::newRow("search-url-with-hashtag") |
| 57 |
<< QUrl("http://google.com/search?q=%23qtproject") |
| 58 |
<< "This should search \"#qtproject\" on Google. The # should appear in the Google search field"; |
| 59 |
|
| 60 |
QTest::newRow("search-url-with-fragment") |
| 61 |
<< QUrl("http://google.com/search?q=Qt+Project#top") |
| 62 |
<< "This should search \"Qt Project\" on Google. There should be no # in the Google search field"; |
| 63 |
|
| 64 |
// see QTBUG-32311 |
| 65 |
QTest::newRow("search-url-with-slashes") |
| 66 |
<< QUrl("http://google.com/search?q=/profile/5") |
| 67 |
<< "This should search \"/profile/5\" on Google."; |
| 68 |
|
| 69 |
// see QTBUG-31945 |
| 70 |
QTest::newRow("two-fragments") |
| 71 |
<< QUrl("http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW81") |
| 72 |
<< "This should open \"Implementing a Container View Controller\" in the UIViewController docs"; |
| 73 |
|
| 74 |
QTest::newRow("mail") |
| 75 |
<< QUrl("mailto:[email protected]") |
| 76 |
<< "This should open an email composer with the destination set to [email protected]"; |
| 77 |
|
| 78 |
QTest::newRow("mail-subject") |
| 79 |
<< QUrl("mailto:[email protected]?subject=[Development]%20Test%20Mail") |
| 80 |
<< "This should open an email composer and tries to set the subject"; |
| 81 |
} |
| 82 |
|
| 83 |
void tst_QDesktopServices::openUrl() |
| 84 |
{ |
| 85 |
QFETCH(QUrl, data); |
| 86 |
QFETCH(QString, message); |
| 87 |
qWarning("\n\nOpening \"%s\": %s", qPrintable(data.toString()), qPrintable(message)); |
| 88 |
QVERIFY(QDesktopServices::openUrl(data)); |
| 89 |
} |
| 90 |
|
| 91 |
QTEST_MAIN(tst_QDesktopServices) |
| 92 |
|
| 93 |
#include "tst_qdesktopservices.moc" |