fune/testing/web-platform/tests/domparsing/insert_adjacent_html-xhtml.xhtml
Stephen McGruer 2c75ae426a Bug 1611178 [wpt PR 21377] - Replace some assert_throws("Something", stuff) calls with assert_throws_dom, a=testonly
Automatic update from web-platform-tests
Replace some assert_throws("Something", stuff) calls with assert_throws_dom. (#21377)

This diff was generated by running:

  find . -type f -print0 | xargs -0 perl -pi -e 'BEGIN { $/ = undef; } s/assert_throws\(([ \n]*"[A-Za-z_]*") *(, *.)/assert_throws_dom(\1\2/gs'

followed by a fix to
xhr/resources/send-after-setting-document-domain-window-helper.js to make
xhr/send-after-setting-document-domain.htm pass.

This does affect indentation poorly in cases when the first arg was on the same
line as the assert_throws, there was a newline after the ',' after the first
arg, and the following args were lined up with the first arg.  Fixing that,
especially when there are multiple lines after the first arg, is not trivial
with a regexp.

Co-authored-by: Boris Zbarsky <bzbarsky@mit.edu>

--

wpt-commits: 3696f2233a37437896505b7187968aa605be9255
wpt-pr: 21377
2020-01-27 15:36:06 +00:00

91 lines
3.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>insertAdjacentHTML in HTML</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="insert_adjacent_html.js"></script>
</head>
<body>
<p id="display"></p><div id="content" style="display: none"></div><div id="content2" style="display: none"></div>
<script><![CDATA[
var script_ran = false;
function testPositions(node, testDesc) {
test(function() {
script_ran = false;
node.insertAdjacentHTML("beforeBegin", "\u003Cscript>script_ran = true;\u003C/script><i></i>");
assert_equals(node.previousSibling.localName, "i", "Should have had <i> as previous sibling");
assert_equals(node.previousSibling.previousSibling.localName, "script", "Should have had <script> as second previous child");
assert_false(script_ran, "script should not have run");
}, "beforeBegin " + node.id + " " + testDesc)
test(function() {
script_ran = false;
node.insertAdjacentHTML("Afterbegin", "<b></b>\u003Cscript>script_ran = true;\u003C/script>");
assert_equals(node.firstChild.localName, "b", "Should have had <b> as first child");
assert_equals(node.firstChild.nextSibling.localName, "script", "Should have had <script> as second child");
assert_false(script_ran, "script should not have run");
}, "Afterbegin " + node.id + " " + testDesc);
test(function() {
script_ran = false;
node.insertAdjacentHTML("BeforeEnd", "\u003Cscript>script_ran = true;\u003C/script><u></u>");
assert_equals(node.lastChild.localName, "u", "Should have had <u> as last child");
assert_equals(node.lastChild.previousSibling.localName, "script", "Should have had <script> as penultimate child");
assert_false(script_ran, "script should not have run");
}, "BeforeEnd " + node.id + " " + testDesc)
test(function() {
script_ran = false;
node.insertAdjacentHTML("afterend", "<a></a>\u003Cscript>script_ran = true;\u003C/script>");
assert_equals(node.nextSibling.localName, "a", "Should have had <a> as next sibling");
assert_equals(node.nextSibling.nextSibling.localName, "script", "Should have had <script> as second next sibling");
assert_false(script_ran, "script should not have run");
}, "afterend " + node.id + " " + testDesc)
}
var content = document.getElementById("content");
testPositions(content, "without next sibling");
testPositions(content, "again, with next sibling");
test(function() {
assert_throws_dom("SYNTAX_ERR", function() {content.insertAdjacentHTML("bar", "foo")});
assert_throws_dom("SYNTAX_ERR", function() {content.insertAdjacentHTML("beforebegİn", "foo")});
assert_throws_dom("SYNTAX_ERR", function() {content.insertAdjacentHTML("beforebegın", "foo")});
}, "Should throw when inserting with invalid position string");
var parentElement = document.createElement("div");
var child = document.createElement("div");
child.id = "child";
testThrowingNoParent(child, "null");
testThrowingNoParent(document.documentElement, "a document");
test(function() {
child.insertAdjacentHTML("afterBegin", "foo");
child.insertAdjacentHTML("beforeend", "bar");
assert_equals(child.textContent, "foobar");
parentElement.appendChild(child);
}, "Inserting after being and before end should order things correctly");
testPositions(child, "node not in tree but has parent");
test(function() {
script_ran = false;
content.appendChild(parentElement); // must not run scripts
assert_false(script_ran, "script should not have run");
}, "Should not run script when appending things which have descendant <script> inserted via insertAdjacentHTML");
var content2 = document.getElementById("content2");
testPositions(content2, "without next sibling");
testPositions(content2, "test again, now that there's a next sibling");
// XML-only:
test(function() {
assert_throws_dom("SYNTAX_ERR", function() {content.insertAdjacentHTML("beforeend", "<p>")});
});
]]></script>
<div id="log"></div>
</body>
</html>