<html>
<body>
<div class="one">
Line 1
<div class="two">Line 2</div>
<p>Line <i>3</i></p>
</div>
<div id="test" class="one two">
<div id="me"></div>
<div id="dupe"></div>
<div id="dupe"></div>
<div id="test2" class="one two">line 4</div>
<p class="two">line 5</p>
</div>
<pre id="console"></pre>
<script type="text/javascript">
if (window.testRunner)
testRunner.dumpAsText();
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}
Element.prototype.dump = function()
{
return this;
}
NodeList.prototype.dump = function()
{
var result = "";
var length = this.length;
for (var i = 0; i < length; i++)
result += this[i] + ", ";
result += "length: " + length;
return result;
}
testQuerySelectorAll = function(node, selectorString)
{
try {
log(node.querySelectorAll(selectorString).dump());
} catch (e) {
log(e);
}
}
testQuerySelector = function(node, selectorString)
{
try {
log(node.querySelector(selectorString).dump());
} catch (e) {
log(e);
}
}
var elm = document.getElementById("test");
var tagString = elm.outerHTML;
var range = document.createRange();
range.selectNode(elm);
var frag = range.createContextualFragment(tagString);
log("Document.querySelectorAll");
log("");
testQuerySelectorAll(document, "#test");
testQuerySelectorAll(document, "#notthere");
testQuerySelectorAll(document, "#dupe");
testQuerySelectorAll(document, ".two");
testQuerySelectorAll(document, ".one, .two");
testQuerySelectorAll(document, "@font-face");
testQuerySelectorAll(document, "");
testQuerySelectorAll(document, null);
testQuerySelectorAll(document, undefined);
testQuerySelectorAll(document, "#test>div");
log("");
log("Element.querySelectorAll");
log("");
testQuerySelectorAll(elm, "#test");
testQuerySelectorAll(elm, "#test2");
testQuerySelectorAll(elm, "#notthere");
testQuerySelectorAll(elm, "#dupe");
testQuerySelectorAll(elm, ".two");
testQuerySelectorAll(elm, ".one, .two");
testQuerySelectorAll(elm, "@font-face");
testQuerySelectorAll(elm, "");
testQuerySelectorAll(elm, null);
testQuerySelectorAll(elm, undefined);
log("");
log("DocumentFragment.querySelectorAll");
log("");
testQuerySelectorAll(frag, "#test");
testQuerySelectorAll(frag, "#test2");
testQuerySelectorAll(frag, "#notthere");
testQuerySelectorAll(frag, "#dupe");
testQuerySelectorAll(frag, ".two");
testQuerySelectorAll(frag, ".one, .two");
testQuerySelectorAll(frag, "@font-face");
testQuerySelectorAll(frag, "");
testQuerySelectorAll(frag, null);
testQuerySelectorAll(frag, undefined);
log("");
log("Document.querySelector");
log("");
testQuerySelector(document, "#test");
testQuerySelector(document, "#notthere");
testQuerySelector(document, "#dupe");
testQuerySelector(document, ".two");
testQuerySelector(document, ".one, .two");
testQuerySelector(document, "@font-face");
testQuerySelector(document, "");
testQuerySelector(document, null);
testQuerySelector(document, undefined);
log("");
log("Element.querySelector");
log("");
testQuerySelector(elm, "#test");
testQuerySelector(elm, "#test2");
testQuerySelector(elm, "#notthere");
testQuerySelector(elm, "#dupe");
testQuerySelector(elm, ".two");
testQuerySelector(elm, ".one, .two");
testQuerySelector(elm, "@font-face");
testQuerySelector(elm, "");
testQuerySelector(elm, null);
testQuerySelector(elm, undefined);
log("");
log("DocumentFragment.querySelector");
log("");
testQuerySelector(frag, "#test");
testQuerySelector(frag, "#test2");
testQuerySelector(frag, "#notthere");
testQuerySelector(frag, "#dupe");
testQuerySelector(frag, ".two");
testQuerySelector(frag, ".one, .two");
testQuerySelector(frag, "@font-face");
testQuerySelector(frag, "");
testQuerySelector(frag, null);
testQuerySelector(frag, undefined);
</script>
</body>
</html>