blob: f82f0699309223294e280e4ccc0dec1b9b8db9ea [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<div id="test" contenteditable></div>
<dl>
<dt>Removed</dt>
<dd id="removed"></dd>
<dt>Preserved</dt>
<dd id="preserved"></dd>
<dt>Exceptions</dt>
<dd id="exceptions"></dd>
</dl>
<script type="text/javascript">
if (window.testRunner)
testRunner.dumpAsText();
var elements = [ "noscript", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio",
"b", "base", "basefont", "bdo", "bgsound", "big", "blockquote", "body", "br", "button",
"canvas", ["table", "caption"], "center", "cite", "code", ["table", "col"], ["table", "colgroup"], "command",
"datagrid", "datalist", "dcell", "dcol", "dd", "del", "details", "dfn", "dir", "div", "dl", "drow", "dt",
"em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset",
"h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html",
"i", "iframe", "image", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "layer", "legend", ["ul", "li"], "link", "listing",
"main", "map", "mark", "marquee", "menu", "meta", "meter", "nav", "nobr", "noembed", "noframes", "nolayer", "noscript",
"object", "ol", "optgroup", "option", "p", "param", "plaintext", "pre", "progress", "q", "rp", "rt", "ruby",
"s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup",
"table", ["table", "tbody"], ["table", "td"], "textarea", ["table", "tfoot"], ["table", "th"], ["table", "thead"],
"title", ["table", "tr"], "track", "tt", "u", "ul", "var", "video", "wbr", "xmp" ];
function addResult(container, name, annotation, description)
{
if (container.innerHTML.length && !annotation)
container.innerHTML += ', ';
container.innerHTML += name;
if (annotation)
container.appendChild(document.createTextNode(" (" + annotation + ")"));
if (description)
container.appendChild(document.createTextNode(description));
if (annotation || description)
container.appendChild(document.createElement('br'));
}
function contains(node, descendant)
{
while (descendant && descendant != node && descendant.parentNode)
descendant = descendant.parentNode;
return descendant == node;
}
var test = document.getElementById('test');
for (var i = 0; i < elements.length; i++) {
var elementName;
var instance = null;
var container = null;
if (typeof elements[i] == 'string') {
elementName = elements[i];
instance = document.createElement(elementName)
container = instance;
} else {
var elementList = elements[i];
for (var j = 0; j < elementList.length; j++) {
var node = document.createElement(elementList[j]);
if (!container)
container = node;
if (instance)
instance.appendChild(node);
instance = node;
}
elementName = elementList[elementList.length - 1];
}
var dummy_text = document.createTextNode('hello=1;');
if (instance === undefined) {
addResult(document.getElementById('exceptions'), elementName, test.innerHTML);
continue;
}
test.innerHTML = "";
try {
instance.appendChild(dummy_text); // this may fail for non-container elements.
} catch (error) { }
test.appendChild(container);
test.appendChild(document.createTextNode(' webkit=2;'));
var ec = ''
if (window.getSelection) {
window.getSelection().selectAllChildren(test);
} else {
var range = document.body.createTextRange();
range.moveToElementText(test.firstChild);
try { range.select(); }
catch (error) { ec += ' failed to select'; }
}
document.execCommand('removeFormat', false, null);
if (ec) {
addResult(document.getElementById('exceptions'), elementName, test.innerHTML, ec);
continue;
}
if (!test.firstChild || test.firstChild.nodeType == 3 /*TextNode*/)
addResult(document.getElementById('removed'), elementName)
else if (contains(test, instance) && (instance.innerHTML == "" || instance.innerHTML == "hello=1;" || elementName == "keygen"))
addResult(document.getElementById('preserved'), elementName);
else
addResult(document.getElementById('exceptions'), elementName, test.innerHTML);
}
document.body.removeChild(test);
</script>
</body>
</html>