Improve QTextBrowser unit test.

The relativeLinks() test function was not performing sufficient
verification steps and thus hid a regression.

Task-number: QTBUG-22416
Change-Id: I2db4d4035e7a32f3c84630c7a15408d31d85ac9e
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2011-10-28 16:17:34 +10:00 committed by Qt by Nokia
parent 0a75be21b3
commit 0b77a19394

View File

@ -251,26 +251,34 @@ void tst_QTextBrowser::viewportPositionInHistory()
void tst_QTextBrowser::relativeLinks() void tst_QTextBrowser::relativeLinks()
{ {
QEXPECT_FAIL("", "QTBUG-22416: First call to QTextBrowser::setSource fails unless URL created with QUrl::fromLocalFile", Abort);
qRegisterMetaType<QUrl>("QUrl"); qRegisterMetaType<QUrl>("QUrl");
QSignalSpy sourceChangedSpy(browser, SIGNAL(sourceChanged(const QUrl &))); QSignalSpy sourceChangedSpy(browser, SIGNAL(sourceChanged(const QUrl &)));
browser->setSource(QUrl("../qtextbrowser.html")); browser->setSource(QUrl("../qtextbrowser.html"));
QVERIFY(!browser->document()->isEmpty());
QVERIFY(sourceChangedSpy.count() == 1); QVERIFY(sourceChangedSpy.count() == 1);
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../qtextbrowser.html")); QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../qtextbrowser.html"));
browser->setSource(QUrl("qtextbrowser/subdir/index.html")); browser->setSource(QUrl("qtextbrowser/subdir/index.html"));
QVERIFY(!browser->document()->isEmpty());
QVERIFY(sourceChangedSpy.count() == 1); QVERIFY(sourceChangedSpy.count() == 1);
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("qtextbrowser/subdir/index.html")); QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("qtextbrowser/subdir/index.html"));
browser->setSource(QUrl("../anchor.html")); browser->setSource(QUrl("../anchor.html"));
QVERIFY(!browser->document()->isEmpty());
QVERIFY(sourceChangedSpy.count() == 1); QVERIFY(sourceChangedSpy.count() == 1);
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../anchor.html")); QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../anchor.html"));
browser->setSource(QUrl("subdir/index.html")); browser->setSource(QUrl("subdir/index.html"));
QVERIFY(!browser->document()->isEmpty());
QVERIFY(sourceChangedSpy.count() == 1); QVERIFY(sourceChangedSpy.count() == 1);
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("subdir/index.html")); QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("subdir/index.html"));
// using QUrl::fromLocalFile() // using QUrl::fromLocalFile()
browser->setSource(QUrl::fromLocalFile("anchor.html")); browser->setSource(QUrl::fromLocalFile("anchor.html"));
QVERIFY(!browser->document()->isEmpty());
QVERIFY(sourceChangedSpy.count() == 1); QVERIFY(sourceChangedSpy.count() == 1);
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("file:anchor.html")); QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("file:anchor.html"));
browser->setSource(QUrl("../qtextbrowser.html")); browser->setSource(QUrl("../qtextbrowser.html"));
QVERIFY(!browser->document()->isEmpty());
QVERIFY(sourceChangedSpy.count() == 1); QVERIFY(sourceChangedSpy.count() == 1);
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../qtextbrowser.html")); QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../qtextbrowser.html"));
} }