Bug 1113238 - Part 1: Make our plaintext and HTML serializers aware of CSS preformatted styles. r=bzbarsky, a=lmandel
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 19 Dec 2014 12:45:50 -0500
changeset 249608 fac2be3ae18f25bc9c9d98e4e0d74e24d0d1add9
parent 249607 c2931fcc7178f1c858df8ad8f32563c53c8cc6b2
child 249609 27b2f1bb01e609f2d06ad2edbc9ea12e8daf31bc
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
bugs1113238
milestone37.0a2
Bug 1113238 - Part 1: Make our plaintext and HTML serializers aware of CSS preformatted styles. r=bzbarsky, a=lmandel This code is super-hairy, but I think this is the minimum amount of changes that we need. nsPlainTextSerializer::IsInPre() before this patch is completely broken, and I changed it to maintain a stack of bools representing whether the elements that we saw as we were traversing the tree are preformatted or not. nsXHTMLContentSerializer maintains this information using a counter, which is broken in case pre and non-preformatted elements are stacked underneath each other, but I'm not sure why this code is using a counter and I didn't want to change it drastically, so for now I'm just making it look at the element's style first as opposed to its tag name. Follow-up work may include exploring whether nsXHTMLContentSerializer should use a stack similar to nsPlainTextSerializer, and also audit this code for more places where things are hardcoded based on tag names where we should be really looking at the style.
dom/base/nsPlainTextSerializer.cpp
dom/base/nsPlainTextSerializer.h
dom/base/nsXHTMLContentSerializer.cpp
dom/base/nsXHTMLContentSerializer.h
dom/base/test/copypaste.js
dom/base/test/file_htmlserializer_1_bodyonly.html
dom/base/test/file_htmlserializer_1_format.html
dom/base/test/file_htmlserializer_1_linebreak.html
dom/base/test/file_htmlserializer_1_links.html
dom/base/test/file_htmlserializer_1_nested_body.html
dom/base/test/file_htmlserializer_1_noflag.html
dom/base/test/file_htmlserializer_1_noformatpre.html
dom/base/test/file_htmlserializer_1_sibling_body.html
dom/base/test/file_htmlserializer_1_sibling_body_only_body.html
dom/base/test/file_htmlserializer_1_wrap.html
dom/base/test/file_xhtmlserializer_1_bodyonly.xhtml
dom/base/test/file_xhtmlserializer_1_format.xhtml
dom/base/test/file_xhtmlserializer_1_linebreak.xhtml
dom/base/test/file_xhtmlserializer_1_links.xhtml
dom/base/test/file_xhtmlserializer_1_nested_body.xhtml
dom/base/test/file_xhtmlserializer_1_noflag.xhtml
dom/base/test/file_xhtmlserializer_1_noformatpre.xhtml
dom/base/test/file_xhtmlserializer_1_sibling_body.xhtml
dom/base/test/file_xhtmlserializer_1_sibling_body_only_body.xhtml
dom/base/test/file_xhtmlserializer_1_wrap.xhtml
dom/base/test/test_bug116083.html
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -17,16 +17,17 @@
 #include "nsTextFragment.h"
 #include "nsContentUtils.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/BinarySearch.h"
+#include "nsComputedDOMStyle.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define PREF_STRUCTS "converter.html2txt.structs"
 #define PREF_HEADER_STRATEGY "converter.html2txt.header_strategy"
 
 static const  int32_t kTabSize=4;
@@ -351,16 +352,17 @@ nsPlainTextSerializer::AppendElementStar
   nsIAtom* id = GetIdForContent(mElement);
 
   bool isContainer = !nsContentUtils::IsHTMLVoid(id);
 
   mOutputString = &aStr;
 
   if (isContainer) {
     rv = DoOpenContainer(id);
+    mPreformatStack.push(IsElementPreformatted(mElement));
   }
   else {
     rv = DoAddLeaf(id);
   }
 
   mElement = nullptr;
   mOutputString = nullptr;
 
@@ -384,16 +386,17 @@ nsPlainTextSerializer::AppendElementEnd(
 
   bool isContainer = !nsContentUtils::IsHTMLVoid(id);
 
   mOutputString = &aStr;
 
   rv = NS_OK;
   if (isContainer) {
     rv = DoCloseContainer(id);
+    mPreformatStack.pop();
   }
 
   mElement = nullptr;
   mOutputString = nullptr;
 
   if (id == nsGkAtoms::head) {
     NS_ASSERTION(mHeadLevel != 0,
                  "mHeadLevel being decremented below 0");
@@ -1532,17 +1535,17 @@ nsPlainTextSerializer::Write(const nsASt
   // Output directly while the other code path goes through AddToLine.
   if ((mPreFormatted && !mWrapColumn) || IsInPre()
       || ((mSpanLevel > 0 || mDontWrapAnyQuotes)
           && mEmptyLines >= 0 && str.First() == char16_t('>'))) {
     // No intelligent wrapping.
 
     // This mustn't be mixed with intelligent wrapping without clearing
     // the mCurrentLine buffer before!!!
-    NS_ASSERTION(mCurrentLine.IsEmpty(),
+    NS_ASSERTION(mCurrentLine.IsEmpty() || IsInPre(),
                  "Mixed wrapping data and nonwrapping data on the same line");
     if (!mCurrentLine.IsEmpty()) {
       FlushLine();
     }
 
     // Put the mail quote "> " chars in, if appropriate.
     // Have to put it in before every line.
     while(bol<totLen) {
@@ -1750,38 +1753,32 @@ nsPlainTextSerializer::GetIdForContent(n
   if (!aContent->IsHTML()) {
     return nullptr;
   }
 
   nsIAtom* localName = aContent->Tag();
   return localName->IsStaticAtom() ? localName : nullptr;
 }
 
-/**
- * Returns true if we currently are inside a <pre>. The check is done
- * by traversing the tag stack looking for <pre> until we hit a block
- * level tag which is assumed to override any <pre>:s below it in
- * the stack. To do this correctly to a 100% would require access
- * to style which we don't support in this converter.
- */  
 bool
 nsPlainTextSerializer::IsInPre()
 {
-  int32_t i = mTagStackIndex;
-  while(i > 0) {
-    if (mTagStack[i - 1] == nsGkAtoms::pre)
-      return true;
-    if (nsContentUtils::IsHTMLBlock(mTagStack[i - 1])) {
-      // We assume that every other block overrides a <pre>
-      return false;
-    }
-    --i;
+  return !mPreformatStack.empty() && mPreformatStack.top();
+}
+
+bool
+nsPlainTextSerializer::IsElementPreformatted(Element* aElement)
+{
+  nsRefPtr<nsStyleContext> styleContext =
+    nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement, nullptr,
+                                                         nullptr);
+  if (styleContext) {
+    const nsStyleText* textStyle = styleContext->StyleText();
+    return textStyle->WhiteSpaceOrNewlineIsSignificant();
   }
-
-  // Not a <pre> in the whole stack
   return false;
 }
 
 /**
  * This method is required only to identify LI's inside OL.
  * Returns TRUE if we are inside an OL tag and FALSE otherwise.
  */
 bool
--- a/dom/base/nsPlainTextSerializer.h
+++ b/dom/base/nsPlainTextSerializer.h
@@ -17,16 +17,18 @@
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsIContentSerializer.h"
 #include "nsIDocumentEncoder.h"
 #include "nsILineBreaker.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
+#include <stack>
+
 class nsIContent;
 
 namespace mozilla {
 namespace dom {
 class Element;
 } // namespace dom
 } // namespace mozilla
 
@@ -107,16 +109,19 @@ protected:
   // Stack handling functions
   bool GetLastBool(const nsTArray<bool>& aStack);
   void SetLastBool(nsTArray<bool>& aStack, bool aValue);
   void PushBool(nsTArray<bool>& aStack, bool aValue);
   bool PopBool(nsTArray<bool>& aStack);
 
   bool ShouldReplaceContainerWithPlaceholder(nsIAtom* aTag);
 
+private:
+  bool IsElementPreformatted(mozilla::dom::Element* aElement);
+
 protected:
   nsString         mCurrentLine;
   uint32_t         mHeadLevel;
   bool             mAtFirstColumn;
 
   // Handling of quoted text (for mail):
   // Quotes need to be wrapped differently from non-quoted text,
   // because quoted text has a few extra characters (e.g. ">> ")
@@ -191,16 +196,21 @@ protected:
   nsAString*            mOutputString;
 
   // The tag stack: the stack of tags we're operating on, so we can nest.
   // The stack only ever points to static atoms, so they don't need to be
   // refcounted.
   nsIAtom**        mTagStack;
   uint32_t         mTagStackIndex;
 
+  // The stack indicating whether the elements we've been operating on are
+  // CSS preformatted elements, so that we can tell if the text inside them
+  // should be formatted.
+  std::stack<bool> mPreformatStack;
+
   // Content in the stack above this index should be ignored:
   uint32_t          mIgnoreAboveIndex;
 
   // The stack for ordered lists
   int32_t         *mOLStack;
   uint32_t         mOLStackIndex;
 
   uint32_t         mULCount;
--- a/dom/base/nsXHTMLContentSerializer.cpp
+++ b/dom/base/nsXHTMLContentSerializer.cpp
@@ -28,16 +28,18 @@
 #include "nsITextToSubURI.h"
 #include "nsCRT.h"
 #include "nsIParserService.h"
 #include "nsContentUtils.h"
 #include "nsLWBrkCIID.h"
 #include "nsIScriptElement.h"
 #include "nsAttrName.h"
 #include "nsParserConstants.h"
+#include "nsComputedDOMStyle.h"
+#include "mozilla/dom/Element.h"
 
 static const int32_t kLongLineLen = 128;
 
 #define kXMLNS "xmlns"
 
 nsresult NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer)
 {
   nsXHTMLContentSerializer* it = new nsXHTMLContentSerializer();
@@ -845,17 +847,17 @@ nsXHTMLContentSerializer::MaybeEnterInPr
 {
 
   if (aNode->GetNameSpaceID() != kNameSpaceID_XHTML) {
     return;
   }
 
   nsIAtom *name = aNode->Tag();
 
-  if (name == nsGkAtoms::pre ||
+  if (IsElementPreformatted(aNode) ||
       name == nsGkAtoms::script ||
       name == nsGkAtoms::style ||
       name == nsGkAtoms::noscript ||
       name == nsGkAtoms::noframes
       ) {
     mPreLevel++;
   }
 }
@@ -863,26 +865,42 @@ nsXHTMLContentSerializer::MaybeEnterInPr
 void
 nsXHTMLContentSerializer::MaybeLeaveFromPreContent(nsIContent* aNode)
 {
   if (aNode->GetNameSpaceID() != kNameSpaceID_XHTML) {
     return;
   }
 
   nsIAtom *name = aNode->Tag();
-  if (name == nsGkAtoms::pre ||
+  if (IsElementPreformatted(aNode) ||
       name == nsGkAtoms::script ||
       name == nsGkAtoms::style ||
       name == nsGkAtoms::noscript ||
       name == nsGkAtoms::noframes
     ) {
     --mPreLevel;
   }
 }
 
+bool
+nsXHTMLContentSerializer::IsElementPreformatted(nsIContent* aNode)
+{
+  if (!aNode->IsElement()) {
+    return false;
+  }
+  nsRefPtr<nsStyleContext> styleContext =
+    nsComputedDOMStyle::GetStyleContextForElementNoFlush(aNode->AsElement(),
+                                                         nullptr, nullptr);
+  if (styleContext) {
+    const nsStyleText* textStyle = styleContext->StyleText();
+    return textStyle->WhiteSpaceOrNewlineIsSignificant();
+  }
+  return false;
+}
+
 void 
 nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIContent* aElement,
                                                     nsAString& aStr)
 {
   // We are copying and we are at the "first" LI node of OL in selected range.
   // It may not be the first LI child of OL but it's first in the selected range.
   // Note that we get into this condition only once per a OL.
   bool found = false;
--- a/dom/base/nsXHTMLContentSerializer.h
+++ b/dom/base/nsXHTMLContentSerializer.h
@@ -88,16 +88,20 @@ class nsXHTMLContentSerializer : public 
   bool IsShorthandAttr(const nsIAtom* aAttrName,
                          const nsIAtom* aElementName);
   virtual void AppendAndTranslateEntities(const nsAString& aStr,
                                           nsAString& aOutputStr) MOZ_OVERRIDE;
   nsresult EscapeURI(nsIContent* aContent,
                      const nsAString& aURI,
                      nsAString& aEscapedURI);
 
+private:
+  bool IsElementPreformatted(nsIContent* aNode);
+
+protected:
   nsCOMPtr<nsIEntityConverter> mEntityConverter;
 
   /*
    * isHTMLParser should be set to true by the HTML parser which inherits from
    * this class. It avoids to redefine methods just for few changes.
    */
   bool          mIsHTMLSerializer;
 
--- a/dom/base/test/copypaste.js
+++ b/dom/base/test/copypaste.js
@@ -155,27 +155,27 @@ function testCopyPaste (isXHTML) {
   }
   else {
     testClipboardValue("text/html", "<div id=\"div4\">\n  T<textarea>t t t</textarea>\n</div>");
     testInnerHTML("div4", "\n  T<textarea>t t t</textarea>\n");
   }
   testPasteText(" Tt t t ");
 
   copyChildrenToClipboard("div5");
-  testSelectionToString(" T ");
-  testClipboardValue("text/unicode", " T ");
+  testSelectionToString(" T     ");
+  testClipboardValue("text/unicode", " T     ");
   if (isXHTML) {
     testClipboardValue("text/html", "<div id=\"div5\">\n  T<textarea xmlns=\"http://www.w3.org/1999/xhtml\">     </textarea>\n</div>");
     testInnerHTML("div5", "\n  T<textarea xmlns=\"http://www.w3.org/1999/xhtml\">     </textarea>\n");
   }
   else {
     testClipboardValue("text/html", "<div id=\"div5\">\n  T<textarea>     </textarea>\n</div>");
     testInnerHTML("div5", "\n  T<textarea>     </textarea>\n");
   }
-  testPasteText(" T ");
+  testPasteText(" T     ");
 
   copyRangeToClipboard($("div6").childNodes[0],0, $("div6").childNodes[1],1,suppressUnicodeCheckIfHidden);
   testSelectionToString("");
 // START Disabled due to bug 564688
 if (false) {
   testClipboardValue("text/unicode", "");
   testClipboardValue("text/html", "");
 }
--- a/dom/base/test/file_htmlserializer_1_bodyonly.html
+++ b/dom/base/test/file_htmlserializer_1_bodyonly.html
@@ -28,16 +28,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_format.html
+++ b/dom/base/test/file_htmlserializer_1_format.html
@@ -37,21 +37,24 @@ var d = a < b && a > c;
       <li> non lacus posuere aliquet.</li>
       <li> Sed fermentum posuere nulla</li>
       <li> Donec tempor.</li>
     </ol>
     Donec sollicitudin tortor
     <!-- test on 
 comments -->
     <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
- Cras quis<br>
- nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
-lacus risus pulvinar ante.
-</pre>
+      Cras quis<br>
+      nisi at odio<br>
+      consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non
+      urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci
+      luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla
+      at pharetra rutrum, <br>
+      lacus risus pulvinar ante.
+    </pre>
     ut gravida eros leo ut libero
     <p></p>
     <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
     <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus
       aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
   </body>
 </html>
--- a/dom/base/test/file_htmlserializer_1_linebreak.html
+++ b/dom/base/test/file_htmlserializer_1_linebreak.html
@@ -32,16 +32,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body></html>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_links.html
+++ b/dom/base/test/file_htmlserializer_1_links.html
@@ -32,16 +32,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body></html>
--- a/dom/base/test/file_htmlserializer_1_nested_body.html
+++ b/dom/base/test/file_htmlserializer_1_nested_body.html
@@ -32,16 +32,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p><body><p>this is an other body element</p></body></body></html>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_noflag.html
+++ b/dom/base/test/file_htmlserializer_1_noflag.html
@@ -32,16 +32,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body></html>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_noformatpre.html
+++ b/dom/base/test/file_htmlserializer_1_noformatpre.html
@@ -29,23 +29,22 @@ var a=3, b=4, c=7;
 var d = a < b && a > c;
 </script>
 
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
-<pre>lacinia <em>libero</em> ullamcorper laoreet.
-
- Cras quis
-
- nisi at odio
-
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, 
-
+<pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
+ Cras quis<br>
+ nisi at odio<br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body></html>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_sibling_body.html
+++ b/dom/base/test/file_htmlserializer_1_sibling_body.html
@@ -32,16 +32,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body></html>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_sibling_body_only_body.html
+++ b/dom/base/test/file_htmlserializer_1_sibling_body_only_body.html
@@ -28,16 +28,19 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body>
\ No newline at end of file
--- a/dom/base/test/file_htmlserializer_1_wrap.html
+++ b/dom/base/test/file_htmlserializer_1_wrap.html
@@ -36,17 +36,20 @@ var d = a < b && a > c;
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum 
 posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br>
  Cras quis<br>
  nisi at odio<br>
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br>
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br>
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros leo ut libero
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc & non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus 
 aliquet lectus. Nunc vitae eros. Class aptent taciti</p></body></html>
\ No newline at end of file
--- a/dom/base/test/file_xhtmlserializer_1_bodyonly.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_bodyonly.xhtml
@@ -30,17 +30,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_format.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_format.xhtml
@@ -40,21 +40,24 @@ var d = a < b && a > c;
       <li> non lacus posuere aliquet.</li>
       <li> Sed fermentum posuere nulla</li>
       <li> Donec tempor.</li>
     </ol>
     Donec sollicitudin tortor
     <!-- test on 
 comments -->
     <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
- Cras quis<br />
- nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
-lacus risus pulvinar ante.
-</pre>
+      Cras quis<br />
+      nisi at odio<br />
+      consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non
+      urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci
+      luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla
+      at pharetra rutrum, <br />
+      lacus risus pulvinar ante.
+    </pre>
     ut gravida eros <br />
     leo ut libero
     <!-- empty element: end tag should be generated for backward compatibility with HTML -->
     <p></p>
     <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
     <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus
       aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_linebreak.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_linebreak.xhtml
@@ -38,17 +38,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_links.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_links.xhtml
@@ -38,17 +38,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_nested_body.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_nested_body.xhtml
@@ -38,17 +38,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_noflag.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_noflag.xhtml
@@ -38,17 +38,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_noformatpre.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_noformatpre.xhtml
@@ -35,24 +35,23 @@ var d = a < b && a > c;
 //]]>
 </script>
 
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
-<pre>lacinia <em>libero</em> ullamcorper laoreet.
-
- Cras quis
-
- nisi at odio
-
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, 
-
+<pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
+ Cras quis<br />
+ nisi at odio<br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_sibling_body.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_sibling_body.xhtml
@@ -38,17 +38,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_sibling_body_only_body.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_sibling_body_only_body.xhtml
@@ -30,17 +30,20 @@ var d = a < b && a > c;
 <ol><li>Fusce
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus aliquet lectus. Nunc vitae eros. Class aptent taciti</p>
--- a/dom/base/test/file_xhtmlserializer_1_wrap.xhtml
+++ b/dom/base/test/file_xhtmlserializer_1_wrap.xhtml
@@ -41,17 +41,20 @@ var d = a < b && a > c;
  a ipsum</li><li> non lacus posuere aliquet.</li><li> Sed fermentum 
 posuere nulla</li><li> Donec tempor.</li></ol>
 Donec sollicitudin tortor 
 <!-- test on 
 comments -->
 <pre>lacinia <em>libero</em> ullamcorper laoreet.<br />
  Cras quis<br />
  nisi at odio<br />
- consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at pharetra rutrum, <br />
+ consectetuer molestie. Curabitur consectetuer urna a sem. Nunc non 
+urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci 
+luctus et ultrices posuere cubilia Curae; Sed sollicitudin, nulla at 
+pharetra rutrum, <br />
 lacus risus pulvinar ante.
 </pre>
 ut gravida eros <br />leo ut libero
 <!-- empty element: end tag should be generated for backward compatibility with HTML -->
 <p></p>
 <noscript>
 <p>Curabitur consectetuer urna a sem. Nunc non urna. Cras in massa. Vestibulum ante ipsum primis in faucibus orci luctus</p></noscript>
 <p>Nam eu sapien. Sed viverra lacus. Donec quis ipsum. Nunc cursus 
--- a/dom/base/test/test_bug116083.html
+++ b/dom/base/test/test_bug116083.html
@@ -11,16 +11,20 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=116083">Mozilla Bug 116083</a>
 <div id="content">
 <div style="white-space: pre">foo  bar</div>
 <div style="white-space: pre-wrap">foo  bar</div>
 <div style="white-space: pre-line">foo  bar</div>
 <div style="white-space: -moz-pre-space">foo  bar</div>
+<div data-result="bar  baz"><span style="white-space: pre">bar  </span>baz</div>
+<div data-result="bar  baz"><span style="white-space: pre-wrap">bar  </span>baz</div>
+<div data-result="bar  baz"><span style="white-space: pre-line">bar  </span>baz</div>
+<div data-result="bar  baz"><span style="white-space: -moz-pre-space">bar  </span>baz</div>
 <div data-result="&#10;foo bar&#10;">foo  bar</div>
 </div>
 <script type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(function nextTest() {
   var div = document.querySelector("#content>div");
   if (!div) {