-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This accompanies whatwg/html#6653. Fixed: 710764 Change-Id: I7168df9bbaeef12ed256b7f2fb9c2c43c9d6b227 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2875725 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Domenic Denicola <[email protected]> Cr-Commit-Position: refs/heads/master@{#880460}
- Loading branch information
1 parent
e953dff
commit b1c25ca
Showing
9 changed files
with
155 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
html/dom/elements/the-innertext-and-outertext-properties/outertext-setter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<!DOCTYPE html> | ||
<title>outerText setter test</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<ul> | ||
<li>A <span id="testReplacePrevious">B</span></li> | ||
<li><span id="testReplaceFollowing">A</span> B</li> | ||
<li>A <span id="testReplaceBoth">B</span> C</li> | ||
<li><span id="testRemove">Testing</span> removing node using outerText.</li> | ||
</ul> | ||
|
||
<div id="container"></div> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
test(() => { | ||
const node = document.getElementById("testReplacePrevious"); | ||
const parent = node.parentNode; | ||
|
||
node.outerText = "Replaced"; | ||
|
||
assert_equals(parent.innerHTML, "A Replaced"); | ||
assert_equals(parent.childNodes.length, 1, "It got merged with the previous text node"); | ||
}, "Replacing a node and merging with the previous text node"); | ||
|
||
test(() => { | ||
const node = document.getElementById("testReplaceFollowing"); | ||
const parent = node.parentNode; | ||
|
||
node.outerText = "Replaced"; | ||
|
||
assert_equals(parent.innerHTML, "Replaced B"); | ||
assert_equals(parent.childNodes.length, 1, "It got merged with the following text node"); | ||
}, "Replacing a node and merging with the following text node"); | ||
|
||
test(() => { | ||
const node = document.getElementById("testReplaceBoth"); | ||
const parent = node.parentNode; | ||
|
||
node.outerText = "Replaced"; | ||
|
||
assert_equals(parent.innerHTML, "A Replaced C"); | ||
assert_equals(parent.childNodes.length, 1, "It got merged with the previous and following text node"); | ||
}, "Replacing a node and merging with the previous and following text node"); | ||
|
||
test(t => { | ||
const container = document.getElementById("container"); | ||
t.add_cleanup(() => { container.textContent = ""; }); | ||
|
||
container.append("A", "B", document.createElement("span"), "D", "E"); | ||
assert_equals(container.childNodes.length, 5, "Precondition check: five separate nodes"); | ||
|
||
const node = container.childNodes[2]; | ||
node.outerText = "Replaced"; | ||
|
||
assert_equals(container.innerHTML, "ABReplacedDE"); | ||
assert_equals(container.childNodes.length, 3, "It got merged with the previous and following text node"); | ||
assert_equals(container.childNodes[0].data, "A"); | ||
assert_equals(container.childNodes[1].data, "BReplacedD"); | ||
assert_equals(container.childNodes[2].data, "E"); | ||
}, "Only merges with the previous and following text nodes, does not completely normalize"); | ||
|
||
test(() => { | ||
const node = document.getElementById("testRemove"); | ||
const parent = node.parentNode; | ||
|
||
node.outerText = ""; | ||
|
||
assert_equals(parent.innerHTML, " removing node using outerText."); | ||
}, "Removing a node"); | ||
|
||
test(() => { | ||
const node = document.createElement("span"); | ||
|
||
assert_throws_dom("NoModificationAllowedError", () => { node.outerText = ""; }); | ||
}, "Detached node"); | ||
|
||
testText("<div>", "abc", "abc", "Simplest possible test"); | ||
testHTML("<div>", "abc\ndef", "abc<br>def", "Newlines convert to <br> in non-white-space:pre elements"); | ||
testHTML("<pre>", "abc\ndef", "abc<br>def", "Newlines convert to <br> in <pre> element"); | ||
testHTML("<textarea>", "abc\ndef", "abc<br>def", "Newlines convert to <br> in <textarea> element"); | ||
testHTML("<div style='white-space:pre'>", "abc\ndef", "abc<br>def", "Newlines convert to <br> in white-space:pre element"); | ||
testHTML("<div>", "abc\rdef", "abc<br>def", "CRs convert to <br> in non-white-space:pre elements"); | ||
testHTML("<pre>", "abc\rdef", "abc<br>def", "CRs convert to <br> in <pre> element"); | ||
testHTML("<div>", "abc\r\ndef", "abc<br>def", "Newline/CR pair converts to <br> in non-white-space:pre element"); | ||
testHTML("<div>", "abc\n\ndef", "abc<br><br>def", "Newline/newline pair converts to two <br>s in non-white-space:pre element"); | ||
testHTML("<div>", "abc\r\rdef", "abc<br><br>def", "CR/CR pair converts to two <br>s in non-white-space:pre element"); | ||
testHTML("<div style='white-space:pre'>", "abc\rdef", "abc<br>def", "CRs convert to <br> in white-space:pre element"); | ||
testText("<div>", "abc<def", "abc<def", "< preserved"); | ||
testText("<div>", "abc>def", "abc>def", "> preserved"); | ||
testText("<div>", "abc&", "abc&", "& preserved"); | ||
testText("<div>", "abc\"def", "abc\"def", "\" preserved"); | ||
testText("<div>", "abc\'def", "abc\'def", "\' preserved"); | ||
testHTML("<svg>", "abc", "<svg></svg>", "outerText not supported on SVG elements"); | ||
testHTML("<math>", "abc", "<math></math>", "outerText not supported on MathML elements"); | ||
testText("<div>", "abc\0def", "abc\0def", "Null characters preserved"); | ||
testText("<div>", "abc\tdef", "abc\tdef", "Tabs preserved"); | ||
testText("<div>", " abc", " abc", "Leading whitespace preserved"); | ||
testText("<div>", "abc ", "abc ", "Trailing whitespace preserved"); | ||
testText("<div>", "abc def", "abc def", "Whitespace not compressed"); | ||
testText("<div>abc\n\n", "abc", "abc", "Existing text deleted"); | ||
testText("<div><br>", "abc", "abc", "Existing <br> deleted"); | ||
testHTML("<div>", "", "", "Assigning the empty string"); | ||
testHTML("<div>", null, "", "Assigning null"); | ||
testHTML("<div>", undefined, "undefined", "Assigning undefined"); | ||
testHTML("<div>", "\rabc", "<br>abc", "Start with CR"); | ||
testHTML("<div>", "\nabc", "<br>abc", "Start with LF"); | ||
testHTML("<div>", "\r\nabc", "<br>abc", "Start with CRLF"); | ||
testHTML("<div>", "abc\r", "abc<br>", "End with CR"); | ||
testHTML("<div>", "abc\n", "abc<br>", "End with LF"); | ||
testHTML("<div>", "abc\r\n", "abc<br>", "End with CRLF"); | ||
|
||
function testText(startingHTML, outerText, expected, description) { | ||
test(t => { | ||
const container = document.getElementById("container"); | ||
t.add_cleanup(() => { container.textContent = ""; }); | ||
|
||
container.innerHTML = startingHTML; | ||
const elementToReplace = container.firstElementChild; | ||
|
||
elementToReplace.outerText = outerText; | ||
assert_equals(container.textContent, expected); | ||
}, description); | ||
} | ||
|
||
function testHTML(startingHTML, outerText, expected, description) { | ||
test(t => { | ||
const container = document.getElementById("container"); | ||
t.add_cleanup(() => { container.textContent = ""; }); | ||
|
||
container.innerHTML = startingHTML; | ||
const elementToReplace = container.firstElementChild; | ||
|
||
elementToReplace.outerText = outerText; | ||
assert_equals(container.innerHTML, expected); | ||
}, description); | ||
} | ||
</script> |