innerText setter should not modify an existing Text child

We have an optimization reusing a Text child, but the standard doesn't
define such behavior, and Edge, Firefox, and Safari don't have it.

This CL might regress benchmarks.  We'll accept it.

Bug: 573309
Change-Id: I3aacae5d37e5a7685ce2d310944dfef8d6e4b13a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1502338
Commit-Queue: Kent Tamura <tkent@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637665}
diff --git a/content/test/data/accessibility/event/live-region-change.html b/content/test/data/accessibility/event/live-region-change.html
index 9898d95b..caf272b 100644
--- a/content/test/data/accessibility/event/live-region-change.html
+++ b/content/test/data/accessibility/event/live-region-change.html
@@ -4,7 +4,7 @@
 <div id="live" aria-live="polite">Before</div>
 <script>
   function go() {
-    document.getElementById('live').innerText = 'After';
+    document.getElementById('live').firstChild.data = 'After';
   }
 </script>
 </body>
diff --git a/third_party/blink/renderer/core/editing/serializers/serialization.cc b/third_party/blink/renderer/core/editing/serializers/serialization.cc
index 541be41..06c8e61 100644
--- a/third_party/blink/renderer/core/editing/serializers/serialization.cc
+++ b/third_party/blink/renderer/core/editing/serializers/serialization.cc
@@ -737,22 +737,6 @@
 
   ChildListMutationScope mutation(*container_node);
 
-  // FIXME: This is wrong if containerNode->firstChild() has more than one ref!
-  // Example:
-  // <div>foo</div>
-  // <script>
-  // var oldText = div.firstChild;
-  // console.log(oldText.data); // foo
-  // div.innerText = "bar";
-  // console.log(oldText.data); // bar!?!
-  // </script>
-  // I believe this is an intentional benchmark cheat from years ago.
-  // We should re-visit if we actually want this still.
-  if (container_node->HasOneTextChild()) {
-    ToText(container_node->firstChild())->setData(text);
-    return;
-  }
-
   // NOTE: This method currently always creates a text node, even if that text
   // node will be empty.
   Text* text_node = Text::Create(container_node->GetDocument(), text);
diff --git a/third_party/blink/web_tests/accessibility/inline-text-changes.html b/third_party/blink/web_tests/accessibility/inline-text-changes.html
index 72151ca..7515f0b 100644
--- a/third_party/blink/web_tests/accessibility/inline-text-changes.html
+++ b/third_party/blink/web_tests/accessibility/inline-text-changes.html
@@ -30,7 +30,8 @@
     assert_equals(axInlineBefore1.name, 'two lines of text.');
 
     // Modify the text.
-    document.getElementById("p").innerText += ' One more sentence.';
+    var p = document.getElementById("p");
+    p.firstChild.data = p.innerText + ' One more sentence.';
 
     // Wait for a notification on the element before checking the new state.
     axStaticText.addNotificationListener(t.step_func((notification) => {
diff --git a/third_party/blink/web_tests/external/wpt/html/dom/elements/the-innertext-idl-attribute/setter-expected.txt b/third_party/blink/web_tests/external/wpt/html/dom/elements/the-innertext-idl-attribute/setter-expected.txt
deleted file mode 100644
index e263930..0000000
--- a/third_party/blink/web_tests/external/wpt/html/dom/elements/the-innertext-idl-attribute/setter-expected.txt
+++ /dev/null
@@ -1,130 +0,0 @@
-This is a testharness.js-based test.
-Found 126 tests; 95 PASS, 31 FAIL, 0 TIMEOUT, 0 NOTRUN.
-PASS Simplest possible test
-PASS Simplest possible test, detached
-PASS Newlines convert to <br> in non-white-space:pre elements
-PASS Newlines convert to <br> in non-white-space:pre elements, detached
-PASS Newlines convert to <br> in <pre> element
-PASS Newlines convert to <br> in <pre> element, detached
-PASS Newlines convert to <br> in <textarea> element
-PASS Newlines convert to <br> in <textarea> element, detached
-PASS Newlines convert to <br> in white-space:pre element
-PASS Newlines convert to <br> in white-space:pre element, detached
-PASS CRs convert to <br> in non-white-space:pre elements
-PASS CRs convert to <br> in non-white-space:pre elements, detached
-PASS CRs convert to <br> in <pre> element
-PASS CRs convert to <br> in <pre> element, detached
-PASS Newline/CR pair converts to <br> in non-white-space:pre element
-PASS Newline/CR pair converts to <br> in non-white-space:pre element, detached
-PASS Newline/newline pair converts to two <br>s in non-white-space:pre element
-PASS Newline/newline pair converts to two <br>s in non-white-space:pre element, detached
-PASS CR/CR pair converts to two <br>s in non-white-space:pre element
-PASS CR/CR pair converts to two <br>s in non-white-space:pre element, detached
-PASS CRs convert to <br> in white-space:pre element
-PASS CRs convert to <br> in white-space:pre element, detached
-PASS < preserved
-PASS < preserved, detached
-PASS > preserved
-PASS > preserved, detached
-PASS & preserved
-PASS & preserved, detached
-PASS " preserved
-PASS " preserved, detached
-PASS ' preserved
-PASS ' preserved, detached
-PASS innerText not supported on SVG elements
-PASS innerText not supported on SVG elements, detached
-PASS innerText not supported on MathML elements
-PASS innerText not supported on MathML elements, detached
-PASS Null characters preserved
-PASS Null characters preserved, detached
-PASS Tabs preserved
-PASS Tabs preserved, detached
-PASS Leading whitespace preserved
-PASS Leading whitespace preserved, detached
-PASS Trailing whitespace preserved
-PASS Trailing whitespace preserved, detached
-PASS Whitespace not compressed
-PASS Whitespace not compressed, detached
-FAIL Existing text deleted assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-FAIL Existing text deleted, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS Existing <br> deleted
-PASS Existing <br> deleted, detached
-PASS Assigning the empty string
-PASS Assigning the empty string, detached
-PASS Assigning null
-PASS Assigning null, detached
-PASS Assigning undefined
-PASS Assigning undefined, detached
-PASS Start with CR
-PASS Start with CR, detached
-PASS Start with LF
-PASS Start with LF, detached
-PASS Start with CRLF
-PASS Start with CRLF, detached
-PASS End with CR
-PASS End with CR, detached
-PASS End with LF
-PASS End with LF, detached
-PASS End with CRLF
-PASS End with CRLF, detached
-PASS innerText on <area> element
-FAIL innerText on <area> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <base> element
-FAIL innerText on <base> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <basefont> element
-FAIL innerText on <basefont> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <bgsound> element
-FAIL innerText on <bgsound> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <br> element
-FAIL innerText on <br> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <col> element
-FAIL innerText on <col> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <embed> element
-FAIL innerText on <embed> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <frame> element
-FAIL innerText on <frame> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <hr> element
-FAIL innerText on <hr> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <image> element
-FAIL innerText on <image> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <img> element
-FAIL innerText on <img> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <input> element
-FAIL innerText on <input> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <keygen> element
-FAIL innerText on <keygen> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <link> element
-FAIL innerText on <link> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <menuitem> element
-FAIL innerText on <menuitem> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <meta> element
-FAIL innerText on <meta> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <param> element
-FAIL innerText on <param> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <source> element
-FAIL innerText on <source> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <track> element
-FAIL innerText on <track> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <wbr> element
-FAIL innerText on <wbr> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <colgroup> element
-FAIL innerText on <colgroup> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <frameset> element
-FAIL innerText on <frameset> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <head> element
-FAIL innerText on <head> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <html> element
-FAIL innerText on <html> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <table> element
-FAIL innerText on <table> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <tbody> element
-FAIL innerText on <tbody> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <tfoot> element
-FAIL innerText on <tfoot> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <thead> element
-FAIL innerText on <thead> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-PASS innerText on <tr> element
-FAIL innerText on <tr> element, detached assert_not_equals: Child should be a *new* text node got disallowed value Text node "abc"
-Harness: the test ran to completion.
-
diff --git a/third_party/blink/web_tests/fast/dom/HTMLElement/set-inner-outer-optimization.html b/third_party/blink/web_tests/fast/dom/HTMLElement/set-inner-outer-optimization.html
index 3c774041..016c083 100644
--- a/third_party/blink/web_tests/fast/dom/HTMLElement/set-inner-outer-optimization.html
+++ b/third_party/blink/web_tests/fast/dom/HTMLElement/set-inner-outer-optimization.html
@@ -99,8 +99,8 @@
     runTest('', 'innerText', '<a></a><b></b>', 'modified');
 
     runTest('text', 'innerText', '', 'modified');
-    runTest('text', 'innerText', 'different text', 'modified, with same first child');
-    runTest('text', 'innerText', 'text', 'modified, with same first child');
+    runTest('text', 'innerText', 'different text', 'modified');
+    runTest('text', 'innerText', 'text', 'modified');
 
     runTest('<a></a>', 'innerText', '', 'modified');
     runTest('<a></a>', 'innerText', 'text', 'modified');
diff --git a/third_party/blink/web_tests/paint/invalidation/block-no-inflow-children.html b/third_party/blink/web_tests/paint/invalidation/block-no-inflow-children.html
index 3be22ea..b604afe 100644
--- a/third_party/blink/web_tests/paint/invalidation/block-no-inflow-children.html
+++ b/third_party/blink/web_tests/paint/invalidation/block-no-inflow-children.html
@@ -2,7 +2,7 @@
     <script>
         function repaintTest()
         {
-            document.getElementById("target").innerText += " la";
+            document.getElementById("target").firstChild.data += " la";
         }
     </script>
     <script src="resources/text-based-repaint.js"></script>
diff --git a/third_party/blink/web_tests/paint/invalidation/position/layout-state-relative.html b/third_party/blink/web_tests/paint/invalidation/position/layout-state-relative.html
index 284d5e1..16419ae2 100644
--- a/third_party/blink/web_tests/paint/invalidation/position/layout-state-relative.html
+++ b/third_party/blink/web_tests/paint/invalidation/position/layout-state-relative.html
@@ -6,7 +6,7 @@
     <script type="text/javascript">
        function repaintTest()
        {
-           document.getElementById("target").innerText = "PASS";
+           document.getElementById("target").firstChild.data = "PASS";
        }
     </script>
 </head>
diff --git a/third_party/blink/web_tests/paint/invalidation/reflection/reflection-with-rotation.html b/third_party/blink/web_tests/paint/invalidation/reflection/reflection-with-rotation.html
index fa2810c..5840c5e1 100644
--- a/third_party/blink/web_tests/paint/invalidation/reflection/reflection-with-rotation.html
+++ b/third_party/blink/web_tests/paint/invalidation/reflection/reflection-with-rotation.html
@@ -6,7 +6,7 @@
     <script type="text/javascript">
        function repaintTest()
        {
-           document.getElementById("target").innerText = "PASS";
+           document.getElementById("target").firstChild.data = "PASS";
        }
     </script>
     <style type="text/css" media="screen">
diff --git a/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset.html b/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset.html
index 26d1094..326ea3c 100644
--- a/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset.html
+++ b/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset.html
@@ -16,7 +16,7 @@
   parent.scrollLeft = 10;
 
   function repaintTest() {
-    document.getElementById('target').innerText = 'after';
+    document.getElementById('target').firstChild.data = 'after';
   }
 </script>
 </html>
diff --git a/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset2.html b/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset2.html
index 30b3aa4..ed10369 100644
--- a/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset2.html
+++ b/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset2.html
@@ -22,7 +22,7 @@
   parent2.scrollLeft = 7;
 
   function repaintTest() {
-    document.getElementById('target').innerText = 'after'
+    document.getElementById('target').firstChild.data = 'after'
   }
 </script>
 </html>
diff --git a/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset3.html b/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset3.html
index 242cb67..7d92c1d2 100644
--- a/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset3.html
+++ b/third_party/blink/web_tests/paint/invalidation/scroll/layout-state-scrolloffset3.html
@@ -16,7 +16,7 @@
   parent.scrollLeft = 10;
 
   function repaintTest() {
-    document.getElementById('target').innerText = 'after';
+    document.getElementById('target').firstChild.data = 'after';
   }
 </script>
 </html>
diff --git a/third_party/blink/web_tests/paint/invalidation/scroll/line-in-scrolled-clipped-block.html b/third_party/blink/web_tests/paint/invalidation/scroll/line-in-scrolled-clipped-block.html
index 60d6714..32223e8 100644
--- a/third_party/blink/web_tests/paint/invalidation/scroll/line-in-scrolled-clipped-block.html
+++ b/third_party/blink/web_tests/paint/invalidation/scroll/line-in-scrolled-clipped-block.html
@@ -7,6 +7,6 @@
 
     function repaintTest()
     {
-        target.innerText = "                         PASS     .";
+        target.firstChild.data = "                         PASS     .";
     }
 </script>
diff --git a/third_party/blink/web_tests/paint/invalidation/transform/transform-layout-repaint.html b/third_party/blink/web_tests/paint/invalidation/transform/transform-layout-repaint.html
index 174d17a..dbee7284 100644
--- a/third_party/blink/web_tests/paint/invalidation/transform/transform-layout-repaint.html
+++ b/third_party/blink/web_tests/paint/invalidation/transform/transform-layout-repaint.html
@@ -6,7 +6,7 @@
     <script type="text/javascript">
        function repaintTest()
        {
-           document.getElementById("target").innerText = "PASS";
+           document.getElementById("target").firstChild.data = "PASS";
        }
     </script>
     <style type="text/css" media="screen">