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, a=lmandel
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 23 Jan 2015 18:07:03 -0500
changeset 249610 074e4205c39991a09c021dcd58ae2c9a930af37b
parent 249609 27b2f1bb01e609f2d06ad2edbc9ea12e8daf31bc
child 249611 f76c1b5753c6d0c65933446087d5eec7bb8ac3da
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, lmandel
bugs1123062
milestone37.0a2
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, a=lmandel
dom/base/nsPlainTextSerializer.cpp
dom/base/test/TestPlainTextSerializer.cpp
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -1769,17 +1769,18 @@ nsPlainTextSerializer::IsElementPreforma
 {
   nsRefPtr<nsStyleContext> styleContext =
     nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement, nullptr,
                                                          nullptr);
   if (styleContext) {
     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;
 }
 
 /**
  * This method is required only to identify LI's inside OL.
  * Returns TRUE if we are inside an OL tag and FALSE otherwise.
  */
 bool
 nsPlainTextSerializer::IsInOL()
--- a/dom/base/test/TestPlainTextSerializer.cpp
+++ b/dom/base/test/TestPlainTextSerializer.cpp
@@ -110,16 +110,39 @@ TestPrettyPrintedHtml()
     return NS_ERROR_FAILURE;
   }
 
   passed("prettyprinted HTML to text serialization test");
   return NS_OK;
 }
 
 nsresult
+TestPreElement()
+{
+  nsString test;
+  test.AppendLiteral(
+    "<html>" NS_LINEBREAK
+    "<body>" NS_LINEBREAK
+    "<pre>" NS_LINEBREAK
+    "  first" NS_LINEBREAK
+    "  second" NS_LINEBREAK
+    "</pre>" NS_LINEBREAK
+    "</body>" NS_LINEBREAK "</html>");
+
+  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()
 {
   nsString test;
   test.AppendLiteral("<html><base>base</base><head><span>span</span></head>"
                      "<body>body</body></html>");
   ConvertBufToPlainText(test, 0);
   if (!test.EqualsLiteral("basespanbody")) {
     fail("Wrong html to text serialization");
@@ -132,16 +155,19 @@ TestPlainTextSerializer()
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = TestCJKWithFlowedDelSp();
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = TestPrettyPrintedHtml();
   NS_ENSURE_SUCCESS(rv, rv);
 
+  rv = TestPreElement();
+  NS_ENSURE_SUCCESS(rv, rv);
+
   // Add new tests here...
   return NS_OK;
 }
 
 int main(int argc, char** argv)
 {
   ScopedXPCOM xpcom("PlainTextSerializer");
   if (xpcom.failed())