From c0ecfc08e3bfb8d93136a859808bf713c56b68e3 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 10 Apr 2017 11:05:51 +0200 Subject: QTextDocument: improve import of DIV tags
1
2 was inserting two newlines between 1 and 2, while all tested web browsers only insert one newline - as long as there is nothing between the
and the . This was the cause for extra newlines being inserted in KMail when replying to HTML emails, such as those generated by gmail. Change-Id: I5145d977701e68913264357bba22780e7cdd3f7d Reviewed-by: Simon Hausmann --- .../gui/text/qtextdocument/tst_qtextdocument.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index ef1ad76161..764b99646b 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -134,6 +134,7 @@ private slots: void clearResources(); void setPlainText(); + void toPlainText_data(); void toPlainText(); void toRawText(); @@ -2391,10 +2392,27 @@ void tst_QTextDocument::setPlainText() QCOMPARE(doc->toPlainText(), s); } +void tst_QTextDocument::toPlainText_data() +{ + QTest::addColumn("html"); + QTest::addColumn("expectedPlainText"); + + QTest::newRow("nbsp") << "Hello World" << "Hello World"; + QTest::newRow("empty_div") << "
hello" << "hello"; + QTest::newRow("br_and_p") << "

first

second

" << "first\n\nsecond\n"; + QTest::newRow("div") << "first
second
third
fourth" << "first\nsecond\nthird\nfourth"; //
and
become newlines... + QTest::newRow("br_text_end_of_div") << "
first
moretext
second
" << "first\nmoretext\nsecond\n"; // ... when there is text before
+ QTest::newRow("br_end_of_div_like_gmail") << "
first
second
third
" << "first\nsecond\nthird\n"; // ... and when there is text before
+ QTest::newRow("p_and_div") << "
first

second

third
" << "first\nsecond\nthird"; +} + void tst_QTextDocument::toPlainText() { - doc->setHtml("Hello World"); - QCOMPARE(doc->toPlainText(), QLatin1String("Hello World")); + QFETCH(QString, html); + QFETCH(QString, expectedPlainText); + + doc->setHtml(html); + QCOMPARE(doc->toPlainText(), expectedPlainText); } void tst_QTextDocument::toRawText() -- cgit v1.2.3