2009-08-18 17:18:24 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=498240
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 498240</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
<style>
|
|
|
|
.container { border: 1px solid blue; display:block; }
|
|
|
|
b { color:blue; }
|
|
|
|
i { color:magenta; }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=498240">Mozilla Bug 498240</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 498240 **/
|
|
|
|
|
|
|
|
|
|
|
|
function create(s) {
|
|
|
|
var p = document.createElement('span');
|
|
|
|
p.innerHTML = s;
|
|
|
|
p.setAttribute("class","container");
|
|
|
|
document.body.appendChild(p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
function select(start, startOffset, end, endOffset) {
|
|
|
|
var sel = getSelection();
|
|
|
|
sel.removeAllRanges();
|
|
|
|
var range = document.createRange();
|
|
|
|
range.setStart(start, startOffset);
|
|
|
|
range.setEnd(end, endOffset);
|
|
|
|
sel.addRange(range);
|
|
|
|
}
|
|
|
|
|
|
|
|
function insertClone(node) {
|
|
|
|
var sel = getSelection();
|
|
|
|
var range = sel.getRangeAt(0);
|
|
|
|
range.insertNode(node.cloneNode(true));
|
|
|
|
}
|
|
|
|
function insertCloneAtEnd(node) {
|
|
|
|
var sel = getSelection();
|
|
|
|
var range = sel.getRangeAt(0);
|
|
|
|
range.endContainer.insertBefore(node.cloneNode(true),range.endContainer.childNodes[range.endOffset]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function check(start, startOffset, end, endOffset, s) {
|
|
|
|
var sel = getSelection();
|
|
|
|
var range = sel.getRangeAt(0);
|
|
|
|
is(range.startContainer, start, "wrong start node for range: '"+range.toString()+"'");
|
|
|
|
is(range.startOffset, startOffset, "wrong start offset for range: '"+range.toString()+"'");
|
|
|
|
is(range.endContainer, end, "wrong end node for range: '"+range.toString()+"'");
|
|
|
|
is(range.endOffset, endOffset, "wrong end offset for range: '"+range.toString()+"'");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testInsertNode(node) {
|
|
|
|
var p;
|
|
|
|
|
|
|
|
p = create('a<b>bc</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[1],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],0,p.childNodes[3],0);
|
|
|
|
|
|
|
|
p = create('d<b>ef</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[1],1);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],0,p.childNodes[3],1);
|
|
|
|
|
|
|
|
p = create('g<b>h</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[0],0);
|
|
|
|
insertClone(node);
|
2012-04-01 05:02:21 -07:00
|
|
|
check(p.childNodes[0],0,p,2);
|
2009-08-18 17:18:24 -07:00
|
|
|
|
|
|
|
p = create('i<b>j</b>');
|
|
|
|
select(p.childNodes[0],1,p.childNodes[0],1);
|
|
|
|
insertClone(node);
|
2012-04-01 05:02:21 -07:00
|
|
|
check(p.childNodes[0],1,p,2);
|
2009-08-18 17:18:24 -07:00
|
|
|
|
|
|
|
p = create('k<b>l</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[1].childNodes[0],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],0,p.childNodes[3].childNodes[0],0);
|
|
|
|
|
|
|
|
p = create('m<b>no</b>');
|
|
|
|
select(p.childNodes[0],1,p.childNodes[1].childNodes[0],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],1,p.childNodes[3].childNodes[0],0);
|
|
|
|
|
|
|
|
p = create('p<b>qr</b>');
|
|
|
|
select(p.childNodes[0],1,p.childNodes[1].childNodes[0],1);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],1,p.childNodes[3].childNodes[0],1);
|
|
|
|
|
|
|
|
p = create('s<b>tu</b>');
|
|
|
|
select(p.childNodes[0],1,p.childNodes[1],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],1,p.childNodes[3],0);
|
|
|
|
|
|
|
|
p = create('<i>A</i><b>BC</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[1],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],0,p.childNodes[1],0);
|
|
|
|
|
|
|
|
p = create('<i>D</i><b>EF</b>');
|
|
|
|
select(p.childNodes[0],1,p.childNodes[1],1);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],1,p.childNodes[1],1);
|
|
|
|
|
|
|
|
p = create('<i></i><b>GH</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[1],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p.childNodes[0],0,p.childNodes[1],0);
|
|
|
|
|
|
|
|
p = create('<i>I</i><b>J</b>');
|
|
|
|
select(p,0,p.childNodes[1],0);
|
|
|
|
insertClone(node);
|
|
|
|
check(p,0,p.childNodes[2],0);
|
|
|
|
|
|
|
|
p = create('<i>K</i><b>L</b>');
|
|
|
|
select(p,0,p,2);
|
|
|
|
insertClone(node);
|
|
|
|
check(p,0,p,3);
|
|
|
|
|
|
|
|
p = create('<i>M</i><b>N</b>');
|
|
|
|
select(p,1,p,2);
|
|
|
|
insertClone(node);
|
|
|
|
check(p,1,p,3);
|
|
|
|
|
|
|
|
p = create('<i>O</i><b>P</b>');
|
|
|
|
select(p,1,p,1);
|
|
|
|
insertClone(node);
|
2012-04-01 05:02:21 -07:00
|
|
|
check(p,1,p,2);
|
2009-08-18 17:18:24 -07:00
|
|
|
|
|
|
|
p = create('<i>Q</i><b>R</b>');
|
|
|
|
select(p,2,p,2);
|
|
|
|
insertClone(node);
|
2012-04-01 05:02:21 -07:00
|
|
|
check(p,2,p,3);
|
2009-08-18 17:18:24 -07:00
|
|
|
|
|
|
|
p = create('<i>S</i><b>T</b>');
|
|
|
|
select(p,1,p,1);
|
|
|
|
insertCloneAtEnd(node);
|
|
|
|
check(p,1,p,1);
|
|
|
|
|
|
|
|
p = create('<i>U</i><b>V</b>');
|
|
|
|
select(p,2,p,2);
|
|
|
|
insertCloneAtEnd(node);
|
|
|
|
check(p,2,p,2);
|
|
|
|
|
|
|
|
p = create('<i>X</i><b>Y</b>');
|
|
|
|
select(p,0,p,1);
|
|
|
|
insertCloneAtEnd(node);
|
|
|
|
check(p,0,p,1);
|
|
|
|
|
|
|
|
p = create('<i>X</i><b><s>Y</s></b>');
|
|
|
|
select(p,0,p.childNodes[1],1);
|
|
|
|
insertCloneAtEnd(node);
|
|
|
|
check(p,0,p.childNodes[1],1);
|
|
|
|
|
|
|
|
p = create('<i>Z</i><b></b>');
|
|
|
|
select(p,0,p.childNodes[1],0);
|
|
|
|
insertCloneAtEnd(node);
|
|
|
|
check(p,0,p.childNodes[1],0);
|
|
|
|
|
|
|
|
p = create('<i>ZA</i><b><s>ZB</s><u>ZC</u></b>');
|
|
|
|
select(p,0,p.childNodes[1],1);
|
|
|
|
insertCloneAtEnd(node);
|
|
|
|
check(p,0,p.childNodes[1],1);
|
|
|
|
}
|
|
|
|
function testInvalidNodeType(node) {
|
|
|
|
try {
|
|
|
|
testInsertNode(node);
|
2012-04-26 09:42:26 -07:00
|
|
|
ok(false,"Expected an InvalidNodeTypeError");
|
2009-08-18 17:18:24 -07:00
|
|
|
} catch(e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
is(e.name, "InvalidNodeTypeError", "Wrong exception, expected InvalidNodeTypeError");
|
|
|
|
ok(e instanceof DOMException, "Wrong type of exception: " + e);
|
|
|
|
is(e.code, DOMException.INVALID_NODE_TYPE_ERR, "Wrong exception code, expected INVALID_NODE_TYPE_ERR");
|
2009-08-18 17:18:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
testInsertNode(document.createTextNode('123'));
|
|
|
|
|
|
|
|
var i = document.createElement('SPAN')
|
|
|
|
i.innerHTML='456'
|
|
|
|
testInsertNode(i);
|
|
|
|
|
|
|
|
i = document.createDocumentFragment();
|
|
|
|
i.appendChild(document.createTextNode('789'));
|
|
|
|
testInsertNode(i);
|
|
|
|
|
|
|
|
/// DOM2 Traversal and Range Specification 2.13 "insertNode":
|
|
|
|
/// RangeException INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, Entity, Notation, or Document node.
|
|
|
|
// BUG: testInvalidNodeType(document.createAttribute('a'));
|
|
|
|
todo(false, "Test insertion of Entity node into range");
|
|
|
|
// TODO: testInvalidNodeType(document.createEntity());
|
|
|
|
todo(false, "Test insertion of Notation node into range");
|
|
|
|
// TODO: testInvalidNodeType(document.createNotation());
|
|
|
|
// BUG: testInvalidNodeType(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null));
|
|
|
|
|
2012-04-26 09:42:26 -07:00
|
|
|
// Intentionally fails because of bug 418755.
|
|
|
|
todo(false, "test that Range::insertNode() throws WrongDocumentError when it should");
|
2009-08-18 17:18:24 -07:00
|
|
|
i = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null).createElement('html');
|
|
|
|
try {
|
|
|
|
testInsertNode(i);
|
2012-04-26 09:42:26 -07:00
|
|
|
todo(false,"Expected a WrongDocumentError");
|
2009-08-18 17:18:24 -07:00
|
|
|
} catch(e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
is(e.name, "WrongDocumentError", "Wrong exception, expected WrongDocumentError");
|
2009-08-18 17:18:24 -07:00
|
|
|
ok(e instanceof DOMException, "Wrong type of exception: " + e);
|
2012-04-26 09:42:26 -07:00
|
|
|
is(e.code, DOMException.WRONG_DOCUMENT_ERR, "Wrong exception code, expected WRONG_DOCUMENT_ERR");
|
2009-08-18 17:18:24 -07:00
|
|
|
}
|
|
|
|
|
2012-04-26 09:42:26 -07:00
|
|
|
// Inserting an ancestor of the start container should throw HierarchyRequestError
|
|
|
|
todo(false, "test that Range::insertNode() throws HierarchyRequestError when it should");
|
2009-08-18 17:18:24 -07:00
|
|
|
var p = create('<b>IJK</b>');
|
|
|
|
select(p.childNodes[0],0,p.childNodes[0],1);
|
|
|
|
var sel = getSelection();
|
|
|
|
var range = sel.getRangeAt(0);
|
|
|
|
try {
|
|
|
|
range.insertNode(p);
|
2012-04-26 09:42:26 -07:00
|
|
|
ok(false,"Expected a HierarchyRequestError");
|
2009-08-18 17:18:24 -07:00
|
|
|
} catch(e) {
|
2012-04-26 09:42:26 -07:00
|
|
|
is(e.name, "HierarchyRequestError", "Wrong exception, expected HierarchyRequestError");
|
2009-08-18 17:18:24 -07:00
|
|
|
ok(e instanceof DOMException, "Wrong type of exception: " + e);
|
2012-04-26 09:42:26 -07:00
|
|
|
is(e.code, DOMException.HIERARCHY_REQUEST_ERR, "Wrong exception code, expected HIERARCHY_REQUEST_ERR");
|
2009-08-18 17:18:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: we should also have a test for:
|
2012-04-26 09:42:26 -07:00
|
|
|
/// "HierarchyRequestError: Raised if the container of the start of the Range is of a type
|
2009-08-18 17:18:24 -07:00
|
|
|
/// that does not allow children of the type of newNode"
|
|
|
|
|
2012-04-26 09:42:26 -07:00
|
|
|
todo(false, "InvalidStateError test goes here...");
|
2009-08-18 17:18:24 -07:00
|
|
|
|
|
|
|
var sel = getSelection();
|
|
|
|
sel.removeAllRanges();
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
addLoadEvent(runTest);
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|