summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qtextbrowser
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-19 13:06:05 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-05-30 16:37:23 +0000
commit0eb26c144346dcb12008e5b3e9441073f09668a8 (patch)
tree4134706a0eba2a22312ef2eb8350a28231c5c936 /tests/auto/widgets/widgets/qtextbrowser
parenta5b373e0db45a28c133bf413e00f15271aa20200 (diff)
QTextBrowser: detect and load markdown rather than assuming HTML
So we add the QTextDocument::ResourceType::MarkdownResource enum value to indicate the type. QMimeDatabase is generally unable to detect markdown by "magic", so we need to use the common file extensions to detect it (the same extensions as declared in the mime database XML). Change-Id: Ib71f03abd535c17e5a8c99bd92d0a6062e972837 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qtextbrowser')
-rw-r--r--tests/auto/widgets/widgets/qtextbrowser/markdown.md2
-rw-r--r--tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp16
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.md b/tests/auto/widgets/widgets/qtextbrowser/markdown.md
new file mode 100644
index 0000000000..be56aef234
--- /dev/null
+++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.md
@@ -0,0 +1,2 @@
+### this is a heading
+this is a paragraph
diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp
index 1f95032165..22cd3b46c6 100644
--- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp
+++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp
@@ -92,6 +92,7 @@ private slots:
void focusIndicator();
void focusHistory();
void urlEncoding();
+ void markdown();
private:
TestBrowser *browser;
@@ -678,5 +679,20 @@ void tst_QTextBrowser::urlEncoding()
delete browser;
}
+void tst_QTextBrowser::markdown()
+{
+ browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA("markdown.md")));
+ QTextFrame::iterator iterator = browser->document()->rootFrame()->begin();
+ int maxHeadingLevel = -1;
+ while (!iterator.atEnd())
+ maxHeadingLevel = qMax(iterator++.currentBlock().blockFormat().intProperty(QTextFormat::HeadingLevel), maxHeadingLevel);
+#if QT_CONFIG(textmarkdownreader)
+ QCOMPARE(maxHeadingLevel, 3);
+#else
+ // If Qt doesn't support markdown, this document will be misidentified as HTML, so it won't have any H3's.
+ QCOMPARE(maxHeadingLevel, 0);
+#endif
+}
+
QTEST_MAIN(tst_QTextBrowser)
#include "tst_qtextbrowser.moc"