<!DOCTYPEhtml>
<html>
<head>
<meta charset="utf-8">
<title>Test for content subtree iterator</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script> var Cc = SpecialPowers.Cc; var Ci = SpecialPowers.Ci;
function finish() {
// The SimpleTest may require usual elements in the template, but they shouldn't be during test.
// So, let's create them at end of the test.
document.body.innerHTML = '';
SimpleTest.finish();
}
function createContentIterator() {
return Cc["@mozilla.org/scriptable-content-iterator;1"]
.createInstance(Ci.nsIScriptableContentIterator);
}
function getNodeDescription(aNode) {
if (aNode === undefined) {
return "undefine";
}
if (aNode === null) {
return "null";
}
function getElementDescription(aElement) {
if (aElement.tagName === "BR") {
if (aElement.previousSibling) {
return `<br> element after ${getNodeDescription(aElement.previousSibling)}`;
}
return `<br> element in ${getElementDescription(aElement.parentElement)}`;
}
let hasHint = aElement == document.body;
let tag = `<${aElement.tagName.toLowerCase()}`;
if (aElement.getAttribute("id")) {
tag += ` id="${aElement.getAttribute("id")}"`;
hasHint = true;
}
if (aElement.getAttribute("class")) {
tag += ` class="${aElement.getAttribute("class")}"`;
hasHint = true;
}
if (aElement.getAttribute("type")) {
tag += ` type="${aElement.getAttribute("type")}"`;
}
if (aElement.getAttribute("name")) {
tag += ` name="${aElement.getAttribute("name")}"`;
}
if (aElement.getAttribute("value")) {
tag += ` value="${aElement.getAttribute("value")}"`;
hasHint = true;
}
if (aElement.getAttribute("style")) {
tag += ` style="${aElement.getAttribute("style")}"`;
hasHint = true;
}
if (hasHint) {
return tag + ">";
}
return `${tag}> in ${getElementDescription(aElement.parentElement)}`;
}
switch (aNode.nodeType) {
case aNode.TEXT_NODE:
return `text node, "${aNode.wholeText.replace(/\n/g, '\\n')}"`;
case aNode.COMMENT_NODE:
return `comment node, "${aNode.data.replace(/\n/g, '\\n')}"`;
case aNode.ELEMENT_NODE:
return getElementDescription(SpecialPowers.unwrap(aNode));
default:
return "unknown node";
}
}
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function () {
let iter = createContentIterator();
/**
* FYI: ContentSubtreeIterator does not support initWithRootNode() nor positionAt().
*/
/**
* Basic behavior tests of first(), last(), prev() and next() after initialized with a range which selects empty element.
*/
document.body.innerHTML = "";
let range = document.createRange();
range.selectNode(document.body.firstChild);
let description = "Initialized with range including only empty
:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first()`);
iter.last();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> after calling last() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling last()`);
iter.prev();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling prev() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling prev()`); // XXX Is this expected?
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> after calling first() even after once done (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first() even after once done`);
iter.next();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling next() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling next()`);
/**
* Basic behavior tests of first(), last(), prev() and next() after initialized with positions which select empty element.
*/
range.selectNode(document.body.firstChild);
description = "Initialized with positions including only empty
:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first()`);
iter.last();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> after calling last() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling last()`);
iter.prev();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling prev() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling prev()`); // XXX Is this expected?
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> after calling first() even after once done (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first() even after once done`);
iter.next();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling next() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling next()`);
/**
* Tests to initializing with collapsed range in an empty element.
*/
range = document.createRange();
range.collapse(document.body.firstChild, 0);
description = "Initialized with range collapsed in empty
:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with collapsed range in an empty element.
*/
description = "Initialized with a position in empty
:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
document.body.firstChild, 0, document.body.firstChild, 0);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Basic behavior tests of first(), last(), prev() and next() after initialized with a range which selects the text node.
*/
document.body.innerHTML = "
some text.
";
range = document.createRange();
range.selectNode(document.body.firstChild.firstChild);
description = "Initialized with range including only text node:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild.firstChild,
`${description} currentNode should be the text node immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild.firstChild,
`${description} currentNode should be the text node after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first()`);
iter.last();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild.firstChild,
`${description} currentNode should be the text node after calling last() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling last()`);
iter.prev();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling prev() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling prev()`); // XXX Is this expected?
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild.firstChild,
`${description} currentNode should be the text node after calling first() even after once done (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first() even after once done`);
iter.next();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling next() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling next()`);
/**
* Basic behavior tests of first() and next() after initialized with positions which select the text node.
* XXX In this case, content iterator lists up the parent <div> element. Not sure if this is intentional difference
* from initWithRange().
*/
range.selectNode(document.body.firstChild);
description = "Initialized with positions including only text node:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> element immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), document.body.firstChild,
`${description} currentNode should be the <div> element after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(!iter.isDone, `${description} isDone shouldn't be true after calling first()`);
iter.next();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null after calling next() from first position (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true after calling next() from first position`);
/**
* Tests to initializing with collapsed range at start of a text node.
*/
range = document.createRange();
range.collapse(document.body.firstChild.firstChild, 0);
description = "Initialized with range collapsed at start of text node:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with collapsed range at start of a text node.
*/
description = "Initialized with a position at start of text node:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
document.body.firstChild.firstChild, 0, document.body.firstChild.firstChild, 0);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with collapsed range at end of a text node.
*/
range = document.createRange();
range.collapse(document.body.firstChild.firstChild, document.body.firstChild.firstChild.length);
description = "Initialized with range collapsed at end of text node:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with collapsed range at end of a text node.
*/
description = "Initialized with a position at end of text node:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
document.body.firstChild.firstChild, document.body.firstChild.firstChild.length,
document.body.firstChild.firstChild, document.body.firstChild.firstChild.length);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with collapsed range at middle of a text node.
*/
range = document.createRange();
range.collapse(document.body.firstChild.firstChild, document.body.firstChild.firstChild.length / 2);
description = "Initialized with range collapsed at end of text node:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with collapsed range at middle of a text node.
*/
description = "Initialized with a position at end of text node:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
document.body.firstChild.firstChild, document.body.firstChild.firstChild.length / 2,
document.body.firstChild.firstChild, document.body.firstChild.firstChild.length / 2);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with a range selecting all text in a text node.
*/
range = document.createRange();
range.setStart(document.body.firstChild.firstChild, 0);
range.setEnd(document.body.firstChild.firstChild, document.body.firstChild.firstChild.length);
description = "Initialized with range selecting all text in text node:";
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Tests to initializing with positions selecting all text in a text node.
*/
description = "Initialized with positions selecting all text in text node:";
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
document.body.firstChild.firstChild, 0,
document.body.firstChild.firstChild, document.body.firstChild.firstChild.length);
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null immediately after initialization (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true immediately after initialization`);
iter.first();
is(SpecialPowers.unwrap(iter.currentNode), null,
`${description} currentNode should be null even after calling first() (got: ${getNodeDescription(iter.currentNode)})`);
ok(iter.isDone, `${description} isDone should be true even after calling first()`);
/**
* Basic tests with complicated tree.
*/
function check(aIter, aExpectedResult, aDescription) {
if (aExpectedResult.length) {
is(SpecialPowers.unwrap(aIter.currentNode), aExpectedResult[0],
`${aDescription}: currentNode should be the text node immediately after initialization (got: ${getNodeDescription(aIter.currentNode)}, expected: ${getNodeDescription(aExpectedResult[0])})`);
ok(!aIter.isDone, `${aDescription}: isDone shouldn't be true immediately after initialization`);
aIter.first();
is(SpecialPowers.unwrap(aIter.currentNode), aExpectedResult[0],
`${aDescription}: currentNode should be the text node after calling first() (got: ${getNodeDescription(aIter.currentNode)}, expected: ${getNodeDescription(aExpectedResult[0])})`);
ok(!aIter.isDone, `${aDescription}: isDone shouldn't be true after calling first()`);
for (let expected of aExpectedResult) {
is(SpecialPowers.unwrap(aIter.currentNode), expected,
`${aDescription}: currentNode should be the node (got: ${getNodeDescription(aIter.currentNode)}, expected: ${getNodeDescription(expected)})`);
ok(!aIter.isDone, `${aDescription}: isDone shouldn't be true when ${getNodeDescription(expected)} is expected`);
aIter.next();
}
is(SpecialPowers.unwrap(aIter.currentNode), null,
`${aDescription}: currentNode should be null after calling next() finally (got: ${getNodeDescription(aIter.currentNode)}`);
ok(aIter.isDone, `${aDescription}: isDone should be true after calling next() finally`);
} else {
is(SpecialPowers.unwrap(aIter.currentNode), null,
`${aDescription}: currentNode should be null immediately after initialization (got: ${getNodeDescription(aIter.currentNode)})`);
ok(aIter.isDone, `${aDescription}: isDone should be true immediately after initialization`);
aIter.first();
is(SpecialPowers.unwrap(aIter.currentNode), null,
`${aDescription}: currentNode should be null after calling first() (got: ${getNodeDescription(aIter.currentNode)})`);
ok(aIter.isDone, `${aDescription}: isDone should be true after calling first()`);
}
}
document.body.innerHTML = "
"
+ "Here is bold and underlined and italic or no style text. " + "" + "
"
+ "Here is an <input> element: text\" value=\"default value\"> \n" + "and a <textarea> element:
\n" + "" + "";
/**
* Selects the <body> with a range.
*/
range = document.createRange();
range.selectNode(document.body);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [document.body], "Initialized with range selecting the ");
/**
* Selects the <body> with positions.
*/
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset, range.endContainer, range.endOffset);
check(iter, [document.body], "Initialized with positions selecting the ");
/**
* Selects all children in the <body> with a range.
*/
range = document.createRange();
range.selectNodeContents(document.body);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter,
[document.body.firstChild, // first <p>
document.body.firstChild.nextSibling], // second <p> "Initialized with range selecting all children in the ");
/**
* Selects all children in the <body> with positions.
*/
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset, range.endContainer, range.endOffset);
check(iter,
[document.body.firstChild, // first <p>
document.body.firstChild.nextSibling], // second <p> "Initialized with positions selecting all children in the ");
/**
* range/positions around elements.
*/
document.body.innerHTML = "abcdefghijkl";
range = document.createRange();
range.setStart(document.body.firstChild, 0);
range.setEnd(document.body.firstChild.nextSibling.firstChild, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting '[abcde]f'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting '[abcde]f'");
range.setStart(document.body.firstChild, 2);
range.setEnd(document.body.firstChild.nextSibling.firstChild, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter,[], "Initialized with range selecting 'ab[cde]f'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'ab[cde]f'");
range.setStart(document.body.firstChild, 3);
range.setEnd(document.body.firstChild.nextSibling.firstChild, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'abc[de]f'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'abc[de]f'");
range.setStart(document.body, 1);
range.setEnd(document.body.firstChild.nextSibling.firstChild, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'abc{de]f'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'abc{de]f'");
range.setStart(document.body.firstChild.nextSibling, 0);
range.setEnd(document.body.firstChild.nextSibling.firstChild, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting '{de]f'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting '{de]f'");
range.setStart(document.body.firstChild.nextSibling, 0);
range.setEnd(document.body.firstChild.nextSibling.firstChild, 3);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting '{def]'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting '{def]'");
range.setStart(document.body.firstChild.nextSibling, 0);
range.setEnd(document.body.firstChild.nextSibling, 1);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter,
[document.body.firstChild.nextSibling.firstChild], // text in <b> "Initialized with range selecting '{def}'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter,
[document.body.firstChild.nextSibling.firstChild], // text in <b> "Initialized with positions selecting '{def}'");
range.setStart(document.body.firstChild.nextSibling, 0);
range.setEnd(document.body, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter,
[document.body.firstChild.nextSibling.firstChild], // text in <b> "Initialized with range selecting '{def}ghi'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter,
[document.body.firstChild.nextSibling.firstChild], // text in <b> "Initialized with positions selecting '{def}ghi'");
range.setStart(document.body.firstChild.nextSibling.firstChild, 3);
range.setEnd(document.body, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'def[}ghi'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'def[}ghi'");
range.setStart(document.body.firstChild.nextSibling, 1);
range.setEnd(document.body, 2);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'def{}ghi'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'def{}ghi'");
range.setStart(document.body.firstChild.nextSibling, 1);
range.setEnd(document.body.firstChild.nextSibling.nextSibling, 0);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'def{}ghi'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'def{}ghi'");
range.setStart(document.body.firstChild.nextSibling, 1);
range.setEnd(document.body.firstChild.nextSibling.nextSibling.firstChild, 0);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'def{]ghi'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'def{]ghi'");
range.setStart(document.body.firstChild.nextSibling.nextSibling, 0);
range.setEnd(document.body, 3);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter,
[document.body.firstChild.nextSibling.nextSibling.firstChild], // text in <i> "Initialized with range selecting '{ghi}jkl'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter,
[document.body.firstChild.nextSibling.nextSibling.firstChild], // text in <i> "Initialized with positions selecting '{ghi}jkl'");
range.setStart(document.body.firstChild.nextSibling.nextSibling.firstChild, 3);
range.setEnd(document.body, 3);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'ghi[}jkl'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'ghi[}jkl'");
range.setStart(document.body.firstChild.nextSibling.nextSibling, 1);
range.setEnd(document.body, 3);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'ghi{}jkl'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'ghi{}jkl'");
range.setStart(document.body.firstChild.nextSibling.nextSibling, 1);
range.setEnd(document.body.firstChild.nextSibling.nextSibling.nextSibling, 0);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter, [], "Initialized with range selecting 'ghi{]jkl'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter, [], "Initialized with positions selecting 'ghi{]jkl'");
/**
* range/positions around <br> elements.
*/
document.body.innerHTML = "abc def";
range = document.createRange();
range.setStart(document.body.firstChild, 3);
range.setEnd(document.body.firstChild.nextSibling.nextSibling, 0);
iter.initWithRange(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR, range);
check(iter,
[document.body.firstChild.nextSibling], // <br> "Initialized with range selecting 'abc[ ]def'");
iter.initWithPositions(Ci.nsIScriptableContentIterator.SUBTREE_ITERATOR,
range.startContainer, range.startOffset,
range.endContainer, range.endOffset);
check(iter,
[document.body.firstChild.nextSibling], // <br> "Initialized with positions selecting 'abc[ ]def'");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.