From 5f161591b6ae25524b129bf4a41d6438f0a4d402 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 28 Sep 2011 10:08:55 +0300 Subject: Fix QTextBrowser autotest to use "file" scheme in URLs. A security fix to QUrl that causes it to no longer interpret URLs without scheme as local files broke QTextBrowser test case. Added the necessary "file" schemes to URLs used in the test. Also added a mention about necessity of using "file" scheme to QTextBrowser documentation. Task-number: QT-5286 Reviewed-by: Sami Merila --- src/gui/widgets/qtextbrowser.cpp | 3 ++- tests/auto/qtextbrowser/tst_qtextbrowser.cpp | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/gui/widgets/qtextbrowser.cpp b/src/gui/widgets/qtextbrowser.cpp index cd8fa11..e786c5c 100644 --- a/src/gui/widgets/qtextbrowser.cpp +++ b/src/gui/widgets/qtextbrowser.cpp @@ -619,7 +619,8 @@ void QTextBrowserPrivate::restoreHistoryEntry(const HistoryEntry entry) If you want to load documents stored in the Qt resource system use \c{qrc} as the scheme in the URL to load. For example, for the document resource path \c{:/docs/index.html} use \c{qrc:/docs/index.html} as - the URL with setSource(). + the URL with setSource(). To access local files, use \c{file} as the + scheme in the URL. \sa QTextEdit, QTextDocument */ diff --git a/tests/auto/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/qtextbrowser/tst_qtextbrowser.cpp index f36b335..4489daa 100644 --- a/tests/auto/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/qtextbrowser/tst_qtextbrowser.cpp @@ -146,7 +146,7 @@ void tst_QTextBrowser::cleanup() void tst_QTextBrowser::noReloadOnAnchorJump() { - QUrl url("anchor.html"); + QUrl url("file:anchor.html"); browser->htmlLoadAttempts = 0; browser->setSource(url); @@ -162,7 +162,7 @@ void tst_QTextBrowser::noReloadOnAnchorJump() void tst_QTextBrowser::bgColorOnSourceChange() { - browser->setSource(QUrl("pagewithbg.html")); + browser->setSource(QUrl("file:pagewithbg.html")); QVERIFY(browser->document()->rootFrame()->frameFormat().hasProperty(QTextFormat::BackgroundBrush)); QVERIFY(browser->document()->rootFrame()->frameFormat().background().color() == Qt::blue); @@ -179,7 +179,7 @@ void tst_QTextBrowser::forwardButton() QVERIFY(browser->historyTitle(0).isEmpty()); QVERIFY(browser->historyTitle(1).isEmpty()); - browser->setSource(QUrl("pagewithbg.html")); + browser->setSource(QUrl("file:pagewithbg.html")); QVERIFY(!forwardEmissions.isEmpty()); QVariant val = forwardEmissions.takeLast()[0]; @@ -192,7 +192,7 @@ void tst_QTextBrowser::forwardButton() QVERIFY(val.toBool() == false); QVERIFY(browser->historyTitle(-1).isEmpty()); - QCOMPARE(browser->historyUrl(0), QUrl("pagewithbg.html")); + QCOMPARE(browser->historyUrl(0), QUrl("file:pagewithbg.html")); QCOMPARE(browser->documentTitle(), QString("Page With BG")); QCOMPARE(browser->historyTitle(0), QString("Page With BG")); QVERIFY(browser->historyTitle(1).isEmpty()); @@ -244,7 +244,7 @@ void tst_QTextBrowser::forwardButton() void tst_QTextBrowser::viewportPositionInHistory() { - browser->setSource(QUrl("bigpage.html")); + browser->setSource(QUrl("file:bigpage.html")); browser->scrollToAnchor("bottom"); QVERIFY(browser->verticalScrollBar()->value() > 0); @@ -283,7 +283,7 @@ void tst_QTextBrowser::relativeLinks() void tst_QTextBrowser::anchors() { - browser->setSource(QUrl("bigpage.html")); + browser->setSource(QUrl("file:bigpage.html")); browser->setSource(QUrl("#bottom")); QVERIFY(browser->verticalScrollBar()->value() > 0); @@ -306,7 +306,7 @@ void tst_QTextBrowser::forwardBackwardAvailable() QVERIFY(!browser->isBackwardAvailable()); QVERIFY(!browser->isForwardAvailable()); - browser->setSource(QUrl("anchor.html")); + browser->setSource(QUrl("file:anchor.html")); QVERIFY(!browser->isBackwardAvailable()); QVERIFY(!browser->isForwardAvailable()); QCOMPARE(backwardSpy.count(), 1); @@ -406,7 +406,7 @@ void tst_QTextBrowser::clearHistory() backwardSpy.clear(); forwardSpy.clear(); - browser->setSource(QUrl("anchor.html")); + browser->setSource(QUrl("file:anchor.html")); QVERIFY(!browser->isBackwardAvailable()); QVERIFY(!browser->isForwardAvailable()); QCOMPARE(backwardSpy.count(), 1); @@ -447,7 +447,7 @@ void tst_QTextBrowser::clearHistory() void tst_QTextBrowser::sourceInsideLoadResource() { - QUrl url("pagewithimage.html"); + QUrl url("file:pagewithimage.html"); browser->setSource(url); QCOMPARE(browser->lastResource.toString(), QUrl::fromLocalFile(QDir::current().filePath("foobar.png")).toString()); QEXPECT_FAIL("", "This is currently not supported", Continue); @@ -532,7 +532,7 @@ void tst_QTextBrowser::adjacentAnchors() void tst_QTextBrowser::loadResourceOnRelativeLocalFiles() { - browser->setSource(QUrl("subdir/index.html")); + browser->setSource(QUrl("file:subdir/index.html")); QVERIFY(!browser->toPlainText().isEmpty()); QVariant v = browser->loadResource(QTextDocument::HtmlResource, QUrl("../anchor.html")); QVERIFY(v.isValid()); @@ -543,7 +543,7 @@ void tst_QTextBrowser::loadResourceOnRelativeLocalFiles() void tst_QTextBrowser::focusIndicator() { HackBrowser *browser = new HackBrowser; - browser->setSource(QUrl("firstpage.html")); + browser->setSource(QUrl("file:firstpage.html")); QVERIFY(!browser->textCursor().hasSelection()); browser->focusTheNextChild(); @@ -595,7 +595,7 @@ void tst_QTextBrowser::focusIndicator() void tst_QTextBrowser::focusHistory() { HackBrowser *browser = new HackBrowser; - browser->setSource(QUrl("firstpage.html")); + browser->setSource(QUrl("file:firstpage.html")); QVERIFY(!browser->textCursor().hasSelection()); browser->focusTheNextChild(); -- cgit v0.12