diff options
author | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2009-09-29 16:00:40 (GMT) |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2009-09-29 16:03:14 (GMT) |
commit | dbe294cdf383d8c8c0da21730be155c5291541d8 (patch) | |
tree | 370f8ddde7e592dc34f5d84238579cedcadc0d8f /tests/auto/qurl | |
parent | c97b576a184a6ad57bf6bf043fa8b4b0be046730 (diff) | |
download | Qt-dbe294cdf383d8c8c0da21730be155c5291541d8.zip Qt-dbe294cdf383d8c8c0da21730be155c5291541d8.tar.gz Qt-dbe294cdf383d8c8c0da21730be155c5291541d8.tar.bz2 |
Adds QUrl::fromUserInput, gathered from QWebView::guessUrlFromString.
Reviewed-by: Thiago Macieira
Diffstat (limited to 'tests/auto/qurl')
-rw-r--r-- | tests/auto/qurl/tst_qurl.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 8899176..fb3cf0e 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -186,6 +186,8 @@ private slots: void resolvedWithAbsoluteSchemes_data() const; void binaryData_data(); void binaryData(); + void fromUserInput_data(); + void fromUserInput(); void task_199967(); void task_240612(); @@ -3637,6 +3639,69 @@ void tst_QUrl::binaryData() QCOMPARE(url2, url); } +void tst_QUrl::fromUserInput_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<QUrl>("url"); + + // Null + QTest::newRow("null") << QString() << QUrl(); + + // File + QDirIterator it(QDir::homePath()); + QString fileString; + int c = 0; + while (it.hasNext()) { + it.next(); + QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath()); + } + + // basic latin1 + QTest::newRow("unicode-0") << QString::fromUtf8("\xC3\xA5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xC3\xA5.com/").toUtf8(), QUrl::TolerantMode); + // unicode + QTest::newRow("unicode-1") << QString::fromUtf8("\xCE\xBB.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xCE\xBB.com/").toUtf8(), QUrl::TolerantMode); + + // no scheme + QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); + QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); + QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); + QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); + + // QUrl's tolerant parser should already handle this + QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); + + // Make sure the :80, i.e. port doesn't screw anything up + QUrl portUrl("http://webkit.org"); + portUrl.setPort(80); + QTest::newRow("port-0") << "webkit.org:80" << portUrl; + QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; + + // mailto doesn't have a ://, but is valid + QUrl mailto("somebody@somewhere.net"); + mailto.setScheme("mailto"); + QTest::newRow("mailto") << "mailto:somebody@somewhere.net" << mailto; + + // misc + QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); + QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); + QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); + QTest::newRow("trash-0") << "webkit.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://webkit.org/test?someData=42%25&someOtherData=abcde#anchor"); + + // FYI: The scheme in the resulting url user + QUrl authUrl("user:pass@domain.com"); + QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; +} + +// public static QUrl guessUrlFromString(QString const& string) +void tst_QUrl::fromUserInput() +{ + QFETCH(QString, string); + QFETCH(QUrl, url); + + QUrl guessedUrl = QUrl::fromUserInput(string); + QCOMPARE(guessedUrl, url); +} + void tst_QUrl::task_199967() { { |