summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_bug409380.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/base/test/test_bug409380.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/base/test/test_bug409380.html')
-rw-r--r--dom/base/test/test_bug409380.html378
1 files changed, 378 insertions, 0 deletions
diff --git a/dom/base/test/test_bug409380.html b/dom/base/test/test_bug409380.html
new file mode 100644
index 000000000..695de5f91
--- /dev/null
+++ b/dom/base/test/test_bug409380.html
@@ -0,0 +1,378 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=409380
+-->
+<head>
+ <title>Test for Bug 409380</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <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=409380">Mozilla Bug 409380</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 409380 **/
+
+function runRangeTest()
+{
+ // Bug 336381
+ // This is a case which can't be supported (at least not at the moment)
+ // because DOM Range requires that when the start boundary point is text node,
+ // it must be splitted. But in this case boundary point doesn't have parent,
+ // so splitting doesn't work.
+ var zz = document.getElementById("connectedDiv").firstChild;
+ zz.parentNode.removeChild(zz);
+ var range = document.createRange();
+ var hadException = false;
+ try {
+ range.setStart(zz, 0);
+ range.setEnd(zz, 0);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException ,
+ "It should be possible to select text node even if the node is not in DOM.");
+ hadException = false;
+ try {
+ range.insertNode(document.createTextNode('5'));
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException,
+ "It shouldn't be possible to insert text node to a detached range.");
+
+ // Bug 409380
+ var element = document.createElement('div');
+ var elementContent = "This is the element content";
+ element.innerHTML = elementContent;
+ range = element.ownerDocument.createRange();
+ hadException = false;
+ try {
+ range.selectNodeContents(element);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException,
+ "It should be possible to select node contents of a detached element.");
+ ok(range.toString() == elementContent, "Wrong range selection");
+
+ // range.selectNode can't succeed because selectNode sets boundary points
+ // to be parentNode, which in this testcase is null.
+ element = document.createElement('div');
+ range = element.ownerDocument.createRange();
+ hadException = false;
+ try {
+ range.selectNode(element);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "It shouldn't be possible to select a detached element.");
+
+ // Testing contextual fragment.
+ range = element.ownerDocument.createRange();
+ var cf = null;
+ var testContent = "<span>foo</span><span>bar</span>";
+ try {
+ range.selectNodeContents(element);
+ cf = range.createContextualFragment(testContent);
+ element.appendChild(cf);
+ } catch (ex) {
+ }
+ ok(cf, "Creating contextual fragment didn't succeed!");
+ ok(element.innerHTML == testContent, "Wrong innerHTML!");
+
+ element = document.createElement('div');
+ element.textContent = "foobar";
+ range = element.ownerDocument.createRange();
+ try {
+ range.selectNodeContents(element);
+ element.firstChild.insertData(3, " ");
+ } catch (ex) {
+ }
+ ok(range.toString() == "foo bar");
+
+ // Testing contextual fragment, but inserting element to document
+ // after creating range.
+ element = document.createElement('div');
+ range = element.ownerDocument.createRange();
+ document.body.appendChild(element);
+ cf = null;
+ testContent = "<span>foo</span><span>bar</span>";
+ try {
+ range.selectNodeContents(element);
+ cf = range.createContextualFragment(testContent);
+ element.appendChild(cf);
+ } catch (ex) {
+ }
+ ok(cf, "Creating contextual fragment didn't succeed!");
+ ok(element.innerHTML == testContent, "Wrong innerHTML!");
+
+ // Testing contextual fragment, but inserting element to document
+ // before creating range.
+ element = document.createElement('div');
+ document.body.appendChild(element);
+ range = element.ownerDocument.createRange();
+ cf = null;
+ testContent = "<span>foo</span><span>bar</span>";
+ try {
+ range.selectNodeContents(element);
+ cf = range.createContextualFragment(testContent);
+ element.appendChild(cf);
+ } catch (ex) {
+ }
+ ok(cf, "Creating contextual fragment didn't succeed!");
+ ok(element.innerHTML == testContent, "Wrong innerHTML!");
+
+ element = document.createElement('div');
+ var range2 = element.ownerDocument.createRange();
+ hadException = false;
+ try {
+ range2.selectNodeContents(element);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException,
+ "It should be possible to select node contents of a detached element.");
+
+ // Now the boundary points of range are in DOM, but boundary points of
+ // range2 aren't.
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.START_TO_START, range2);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.START_TO_END, range2);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.END_TO_START, range2);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.END_TO_END, range2);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.START_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.START_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.END_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.END_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ // range3 will be in document
+ element = document.createElement('div');
+ document.body.appendChild(element);
+ range3 = element.ownerDocument.createRange();
+ hadException = false;
+ try {
+ range3.selectNodeContents(element);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException,
+ "It should be possible to select node contents of a detached element.");
+
+ hadException = false;
+ try {
+ range3.compareBoundaryPoints(range.START_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range3.compareBoundaryPoints(range.START_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range3.compareBoundaryPoints(range.END_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range3.compareBoundaryPoints(range.END_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ // range4 won't be in document
+ element = document.createElement('div');
+ var range4 = element.ownerDocument.createRange();
+ hadException = false;
+ try {
+ range4.selectNodeContents(element);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException,
+ "It should be possible to select node contents of a detached element.");
+
+ hadException = false;
+ try {
+ range4.compareBoundaryPoints(range.START_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.START_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range4.compareBoundaryPoints(range.END_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ hadException = false;
+ try {
+ range4.compareBoundaryPoints(range.END_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(hadException, "Should have got an exception!");
+
+ // Compare range to itself.
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.START_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.START_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.END_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range.compareBoundaryPoints(range.END_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ // Attach startContainer of range2 to document.
+ ok(range2.startContainer == range2.endContainer, "Wrong container?");
+ document.body.appendChild(range2.startContainer);
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.START_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.START_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.END_TO_START, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ hadException = false;
+ try {
+ range2.compareBoundaryPoints(range.END_TO_END, range);
+ } catch (ex) {
+ hadException = true;
+ }
+ ok(!hadException, "Shouldn't have got an exception!");
+
+ SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(runRangeTest);
+
+</script>
+</pre>
+<div id="connectedDiv">zz</div>
+</body>
+</html>
+