From aaa0af1db95dceead9d905b9741e1c4f26a3dd5e Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 23 Jan 2015 18:07:03 -0500 Subject: [PATCH] Bug 1123062 - Fall back to looking at the tag for determining if an element is preformatted when there is no style information available; r=bzbarsky --- dom/base/nsPlainTextSerializer.cpp | 3 ++- dom/base/test/TestPlainTextSerializer.cpp | 26 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dom/base/nsPlainTextSerializer.cpp b/dom/base/nsPlainTextSerializer.cpp index 5ae4b3b78b81..be3a3b26e96c 100644 --- a/dom/base/nsPlainTextSerializer.cpp +++ b/dom/base/nsPlainTextSerializer.cpp @@ -1774,7 +1774,8 @@ nsPlainTextSerializer::IsElementPreformatted(Element* aElement) const nsStyleText* textStyle = styleContext->StyleText(); return textStyle->WhiteSpaceOrNewlineIsSignificant(); } - return false; + // Fall back to looking at the tag, in case there is no style information. + return GetIdForContent(aElement) == nsGkAtoms::pre; } /** diff --git a/dom/base/test/TestPlainTextSerializer.cpp b/dom/base/test/TestPlainTextSerializer.cpp index be77795361e3..7be9bce0fda0 100644 --- a/dom/base/test/TestPlainTextSerializer.cpp +++ b/dom/base/test/TestPlainTextSerializer.cpp @@ -114,6 +114,29 @@ TestPrettyPrintedHtml() return NS_OK; } +nsresult +TestPreElement() +{ + nsString test; + test.AppendLiteral( + "" NS_LINEBREAK + "" NS_LINEBREAK + "
" NS_LINEBREAK
+    "  first" NS_LINEBREAK
+    "  second" NS_LINEBREAK
+    "
" NS_LINEBREAK + "" NS_LINEBREAK ""); + + ConvertBufToPlainText(test, 0); + if (!test.EqualsLiteral(" first" NS_LINEBREAK " second" NS_LINEBREAK NS_LINEBREAK)) { + fail("Wrong prettyprinted html to text serialization"); + return NS_ERROR_FAILURE; + } + + passed("prettyprinted HTML to text serialization test"); + return NS_OK; +} + nsresult TestPlainTextSerializer() { @@ -137,6 +160,9 @@ TestPlainTextSerializer() rv = TestPrettyPrintedHtml(); NS_ENSURE_SUCCESS(rv, rv); + rv = TestPreElement(); + NS_ENSURE_SUCCESS(rv, rv); + // Add new tests here... return NS_OK; }