2007-04-12 10:40:27 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=372086
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 372086</title>
|
2019-11-11 22:26:56 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2007-04-12 10:40:27 +04:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=372086">Mozilla Bug 372086</a>
|
|
|
|
<p id="display">
|
2019-11-11 22:26:56 +03:00
|
|
|
<div id="d" is="custom-div">abc</div>def
|
2007-04-12 10:40:27 +04:00
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
2019-11-11 22:26:56 +03:00
|
|
|
|
2007-04-12 10:40:27 +04:00
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 372086 **/
|
|
|
|
|
2019-11-11 22:26:56 +03:00
|
|
|
customElements.define("custom-div", class extends HTMLDivElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.attachShadow({ mode: "open" });
|
|
|
|
this.shadowRoot.innerHTML = `ghi<slot></slot>jkl`;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
extends: "div",
|
|
|
|
});
|
2014-04-06 23:32:38 +04:00
|
|
|
|
2007-04-12 10:40:27 +04:00
|
|
|
function runTest() {
|
2019-11-11 22:26:56 +03:00
|
|
|
let range = document.createRange();
|
2007-04-12 10:40:27 +04:00
|
|
|
|
|
|
|
var c = $("d").firstChild;
|
|
|
|
var a = $("d").nextSibling;
|
2019-11-11 22:26:56 +03:00
|
|
|
|
2007-04-12 10:40:27 +04:00
|
|
|
range.setStart(c, 1);
|
|
|
|
range.setEnd(c, 3);
|
2019-11-11 22:26:56 +03:00
|
|
|
is(range.startContainer, c, "Unexpected start container");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.startOffset, 1, "Unexpected start offset");
|
2019-11-11 22:26:56 +03:00
|
|
|
is(range.endContainer, c, "Unexpected end container");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.endOffset, 3, "Unexpected end offset");
|
|
|
|
is(range.toString(), "bc", "Unexpected range serialization");
|
|
|
|
|
2019-11-11 22:26:56 +03:00
|
|
|
let shadow = d.shadowRoot.firstChild;
|
2007-04-12 10:40:27 +04:00
|
|
|
// Should collapse the range, because can't determine order
|
2019-11-11 22:26:56 +03:00
|
|
|
range.setEnd(shadow, 2);
|
|
|
|
is(range.startContainer, shadow,
|
2014-04-06 23:32:38 +04:00
|
|
|
"Unexpected collapsed start container");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.startOffset, 2, "Unexpected collapsed start offset");
|
2019-11-11 22:26:56 +03:00
|
|
|
is(range.endContainer, shadow,
|
2014-04-06 23:32:38 +04:00
|
|
|
"Unexpected collapsed end container");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.endOffset, 2, "Unexpected collapsed end offset");
|
|
|
|
is(range.toString(), "", "Unexpected collapsed range serialization");
|
|
|
|
|
|
|
|
range.setEnd(a, 2);
|
|
|
|
range.setStart(a, 0);
|
2019-11-11 22:26:56 +03:00
|
|
|
is(range.startContainer, a, "Unexpected start container after");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.startOffset, 0, "Unexpected start offset after");
|
2019-11-11 22:26:56 +03:00
|
|
|
is(range.endContainer, a, "Unexpected end container after");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.endOffset, 2, "Unexpected end offset after");
|
|
|
|
is(range.toString(), "de", "Unexpected range serialization after");
|
|
|
|
|
2019-11-11 22:26:56 +03:00
|
|
|
shadow = d.shadowRoot.lastChild;
|
2007-04-12 10:40:27 +04:00
|
|
|
// Collapses because one endpoint is anonymous from point of view of
|
2019-11-11 22:26:56 +03:00
|
|
|
// the other.
|
|
|
|
range.setStart(shadow, 1);
|
|
|
|
is(range.startContainer, shadow,
|
|
|
|
"Unexpected newly collapsed start container");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.startOffset, 1, "Unexpected newly collapsed start offset");
|
2019-11-11 22:26:56 +03:00
|
|
|
is(range.endContainer, shadow,
|
2014-04-06 23:32:38 +04:00
|
|
|
"Unexpected newly collapsed end container");
|
2007-04-12 10:40:27 +04:00
|
|
|
is(range.endOffset, 1, "Unexpected newly collapsed end offset");
|
|
|
|
is(range.toString(), "", "Unexpected collapsed range serialization");
|
|
|
|
|
2019-11-11 22:26:56 +03:00
|
|
|
range.setEnd(shadow, 3);
|
|
|
|
is(range.startContainer, shadow,
|
|
|
|
"Unexpected shadow start container");
|
|
|
|
is(range.startOffset, 1, "Unexpected shadow start offset");
|
|
|
|
is(range.endContainer, shadow,
|
|
|
|
"Unexpected shadow end container");
|
|
|
|
is(range.endOffset, 3, "Unexpected shadow end offset");
|
|
|
|
is(range.toString(), "kl", "Unexpected shadow range serialization");
|
2007-04-12 10:40:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
addLoadEvent(runTest);
|
|
|
|
addLoadEvent(SimpleTest.finish)
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|