Bug 838954 - Backout newlines lost in .innerHTML serialization of <pre> when first character is a newline. r=smaug, a=gchang
authorJohn Dai <jdai@mozilla.com>
Thu, 22 Sep 2016 02:42:00 +0800
changeset 356092 a36fb6876e49d6cd19b8f0e7fc22f84a6433a878
parent 356091 88b6fcb46b5eb3b08ca9afdc1e53d276d758d73a
child 356093 c8cf23344b941a3a39d37dca323d6faf7e0af011
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, gchang
bugs838954
milestone51.0a2
Bug 838954 - Backout newlines lost in .innerHTML serialization of <pre> when first character is a newline. r=smaug, a=gchang
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/base/test/test_bug744830.html
modules/libpref/init/all.js
testing/profiles/prefs_general.js
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/html/syntax/serializing-html-fragments/initial-linefeed-pre.html.ini
testing/web-platform/tests/domparsing/innerhtml-02.html
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -277,17 +277,16 @@ bool nsContentUtils::sIsFrameTimingPrefE
 bool nsContentUtils::sIsPerformanceTimingEnabled = false;
 bool nsContentUtils::sIsResourceTimingEnabled = false;
 bool nsContentUtils::sIsUserTimingLoggingEnabled = false;
 bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false;
 bool nsContentUtils::sEncodeDecodeURLHash = false;
 bool nsContentUtils::sGettersDecodeURLHash = false;
 bool nsContentUtils::sPrivacyResistFingerprinting = false;
 bool nsContentUtils::sSendPerformanceTimingNotifications = false;
-bool nsContentUtils::sAppendLFInSerialization = false;
 bool nsContentUtils::sUseActivityCursor = false;
 
 uint32_t nsContentUtils::sHandlingInputTimeout = 1000;
 
 uint32_t nsContentUtils::sCookiesLifetimePolicy = nsICookieService::ACCEPT_NORMALLY;
 uint32_t nsContentUtils::sCookiesBehavior = nsICookieService::BEHAVIOR_ACCEPT;
 
 nsHtml5StringParser* nsContentUtils::sHTMLFragmentParser = nullptr;
@@ -595,18 +594,16 @@ nsContentUtils::Init()
   Preferences::AddUintVarCache(&sCookiesLifetimePolicy,
                                "network.cookie.lifetimePolicy",
                                nsICookieService::ACCEPT_NORMALLY);
 
   Preferences::AddUintVarCache(&sCookiesBehavior,
                                "network.cookie.cookieBehavior",
                                nsICookieService::BEHAVIOR_ACCEPT);
 
-  Preferences::AddBoolVarCache(&sAppendLFInSerialization,
-                               "dom.html_fragment_serialisation.appendLF");
 #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
   Preferences::AddBoolVarCache(&sDOMWindowDumpEnabled,
                                "browser.dom.window.dump.enabled");
 #endif
 
   Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
                                "privacy.donottrackheader.enabled", false);
 
@@ -9048,35 +9045,35 @@ StartElement(Element* aContent, StringBu
     aBuilder.Append(attName);
     aBuilder.Append("=\"");
     AppendEncodedAttributeValue(attValue, aBuilder);
     aBuilder.Append("\"");
   }
 
   aBuilder.Append(">");
 
-
+  /*
   // Per HTML spec we should append one \n if the first child of
   // pre/textarea/listing is a textnode and starts with a \n.
   // But because browsers haven't traditionally had that behavior,
   // we're not changing our behavior either - yet.
-  if (nsContentUtils::AppendLFInSerialization() && aContent->IsHTMLElement()) {
+  if (aContent->IsHTMLElement()) {
     if (localName == nsGkAtoms::pre || localName == nsGkAtoms::textarea ||
         localName == nsGkAtoms::listing) {
       nsIContent* fc = aContent->GetFirstChild();
       if (fc &&
           (fc->NodeType() == nsIDOMNode::TEXT_NODE ||
            fc->NodeType() == nsIDOMNode::CDATA_SECTION_NODE)) {
         const nsTextFragment* text = fc->GetText();
         if (text && text->GetLength() && text->CharAt(0) == char16_t('\n')) {
           aBuilder.Append("\n");
         }
       }
     }
-  }
+  }*/
 }
 
 static inline bool
 ShouldEscape(nsIContent* aParent)
 {
   if (!aParent || !aParent->IsHTMLElement()) {
     return true;
   }
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -1949,20 +1949,16 @@ public:
    *
    * @param aDoc the document for which to return a layer manager.
    * @param aAllowRetaining an outparam that states whether the returned
    * layer manager should be used for retained layers
    */
   static already_AddRefed<mozilla::layers::LayerManager>
   PersistentLayerManagerForDocument(nsIDocument *aDoc);
 
-  /* static */
-  static bool AppendLFInSerialization()
-    { return sAppendLFInSerialization; }
-
   /**
    * Determine whether a content node is focused or not,
    *
    * @param aContent the content node to check
    * @return true if the content node is focused, false otherwise.
    */
   static bool IsFocusedContent(const nsIContent *aContent);
 
@@ -2806,17 +2802,16 @@ private:
   static bool sIsResourceTimingEnabled;
   static bool sIsUserTimingLoggingEnabled;
   static bool sIsFrameTimingPrefEnabled;
   static bool sIsExperimentalAutocompleteEnabled;
   static bool sEncodeDecodeURLHash;
   static bool sGettersDecodeURLHash;
   static bool sPrivacyResistFingerprinting;
   static bool sSendPerformanceTimingNotifications;
-  static bool sAppendLFInSerialization;
   static bool sUseActivityCursor;
   static uint32_t sCookiesLifetimePolicy;
   static uint32_t sCookiesBehavior;
 
   static nsHtml5StringParser* sHTMLFragmentParser;
   static nsIParser* sXMLFragmentParser;
   static nsIFragmentContentSink* sXMLFragmentSink;
 
--- a/dom/base/test/test_bug744830.html
+++ b/dom/base/test/test_bug744830.html
@@ -21,17 +21,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   t.appendChild(PI);
   is(t.innerHTML, '<span>hi</span> there <!-- mon ami --><?foo bar="1.0">',
     "pi nodes should be included");
 
   t.innerHTML = null;
   t.appendChild(document.createElement("textarea"));
   t.firstChild.appendChild(document.createTextNode("\nhello"));
   // This is the old behavior. Spec requires something else.
-  is(t.innerHTML, "<textarea>\n\nhello</textarea>",
+  is(t.innerHTML, "<textarea>\nhello</textarea>",
      "No extra newlines should be inserted to the textarea!");
 
   t.innerHTML = null;
   t.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg:svg"));
   t.firstChild.textContent = "<foo>";
   is(t.innerHTML, "<svg>&lt;foo&gt;</svg>");
 
   t.innerHTML = null;
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5547,22 +5547,16 @@ pref("dom.webkitBlink.filesystem.enabled
 #endif
 
 pref("media.block-autoplay-until-in-foreground", true);
 #ifdef MOZ_STYLO
 // Is the Servo-backed style system enabled?
 pref("layout.css.servo.enabled", true);
 #endif
 
-#ifdef NIGHTLY_BUILD
-pref("dom.html_fragment_serialisation.appendLF", true);
-#else
-pref("dom.html_fragment_serialisation.appendLF", false);
-#endif
-
 // HSTS Priming
 // If a request is mixed-content, send an HSTS priming request to attempt to
 // see if it is available over HTTPS.
 pref("security.mixed_content.send_hsts_priming", true);
 #ifdef RELEASE_BUILD
 // Don't change the order of evaluation of mixed-content and HSTS upgrades in
 // order to be most compatible with current standards
 pref("security.mixed_content.use_hsts", false);
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -347,9 +347,8 @@ user_pref("browser.urlbar.suggest.search
 user_pref("browser.urlbar.userMadeSearchSuggestionsChoice", true);
 
 user_pref("dom.audiochannel.mutedByDefault", false);
 
 user_pref("webextensions.tests", true);
 user_pref("startup.homepage_welcome_url", "about:blank");
 user_pref("startup.homepage_welcome_url.additional", "");
 user_pref("browser.usedOnWindows10.introURL", "");
-user_pref("dom.html_fragment_serialisation.appendLF", true);
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -15413,20 +15413,16 @@
         "path": "domparsing/createContextualFragment.html",
         "url": "/domparsing/createContextualFragment.html"
       },
       {
         "path": "domparsing/innerhtml-01.xhtml",
         "url": "/domparsing/innerhtml-01.xhtml"
       },
       {
-        "path": "domparsing/innerhtml-02.html",
-        "url": "/domparsing/innerhtml-02.html"
-      },
-      {
         "path": "domparsing/innerhtml-03.xhtml",
         "url": "/domparsing/innerhtml-03.xhtml"
       },
       {
         "path": "domparsing/innerhtml-04.html",
         "url": "/domparsing/innerhtml-04.html"
       },
       {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/html/syntax/serializing-html-fragments/initial-linefeed-pre.html.ini
@@ -0,0 +1,7 @@
+[initial-linefeed-pre.html]
+  type: testharness
+  [outer div]
+    expected: FAIL
+
+  [inner div]
+    expected: FAIL
\ No newline at end of file
deleted file mode 100644
--- a/testing/web-platform/tests/domparsing/innerhtml-02.html
+++ /dev/null
@@ -1,126 +0,0 @@
-<!DOCTYPE html>
-<title>innerHTML in HTML</title>
-<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
-<link rel="help" href="http://html5.org/specs/dom-parsing.html#innerhtml">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<div id="log"></div>
-<script>
-var voidElements = [
-  "area", "base", "basefont", "bgsound", "br", "col", "command", "embed",
-  "frame", "hr", "img", "input", "keygen", "link", "meta", "param", "source",
-  "track", "wbr"
-];
-var tests = [
-  [
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement("xmp"))
-        .appendChild(document.createElement("span"))
-        .appendChild(document.createTextNode("<"));
-      return el;
-    },
-    "<xmp><span>&lt;<\/span><\/xmp>"
-  ],
-  [
-    function() {
-      var el = document.createElement("xmp");
-      el.appendChild(document.createElement("span"))
-        .appendChild(document.createTextNode("<"));
-      return el;
-    },
-    "<span>&lt;<\/span>"
-  ],
-  [
-    function() {
-      var el = document.createElement("xmp");
-      el.appendChild(document.createTextNode("<"));
-      return el;
-    },
-    "<"
-  ],
-  [
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement("br"));
-      return el;
-    },
-    "<br>"
-  ],
-  [
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement("input"))
-        .appendChild(document.createElement("span"));
-      return el;
-    },
-    "<input>"
-  ],
-  [
-    function() {
-      var el = document.createElement("img");
-      el.appendChild(document.createElement("div"))
-        .appendChild(document.createElement("span"));
-      return el.firstChild;
-    },
-    "<span><\/span>"
-  ],
-  [
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement("style"))
-        .appendChild(document.createElement("span"));
-      return el;
-    },
-    "<style><span><\/span><\/style>"
-  ],
-  [
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement("style"))
-        .appendChild(document.createTextNode("<"));
-      return el;
-    },
-    "<style><<\/style>"
-  ],
-  [
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement("style"))
-        .appendChild(document.createElement("span"))
-        .appendChild(document.createTextNode("<"));
-      return el;
-    },
-    "<style><span>&lt;<\/span><\/style>"
-  ]
-];
-voidElements.forEach(function(tag) {
-  tests.push([
-    function() {
-      var el = document.createElement(tag);
-      el.appendChild(document.createElement("span"));
-      return el;
-    },
-    "<span><\/span>"
-  ]);
-});
-["pre", "textarea", "listing"].forEach(function(tag) {
-  tests.push([
-    function() {
-      var el = document.createElement("div");
-      el.appendChild(document.createElement(tag))
-        .appendChild(document.createTextNode("\nA"));
-      return el;
-    },
-    "<" + tag + ">\n\nA<\/" + tag + ">"
-  ]);
-});
-test(function() {
-  tests.forEach(function(t) {
-    var el = t[0](), expected = t[1];
-    test(function() {
-      assert_equals(el.innerHTML, expected);
-    }, "Expected innerHTML: " + format_value(expected) + " for " + el.localName + ".");
-  });
-});
-</script>
\ No newline at end of file