<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<div style="display: none">
    <form id=a>
        <input id=x>
        <input name=z>
    </form>
    <form name=z>
        <input id=x>
        <input name=z>
        <select>
            <option id=o>a</option>
            <option name=z>b</option>
            <option>c</option>
        </select>
    </form>
    <a href="http://c.example.org" id=c name=cc></a>
    <a href="http://d.example.org" name=z></a>
</div>
<script>

description("HTMLCollection.item() shouldn't fallback to namedItem().");

function runTests(collection, expectedElement) {
    shouldBe(collection + ".item(0)", expectedElement);
    shouldBe(collection + ".item('0')", expectedElement);
    shouldBe(collection + ".item('z')", expectedElement);
    shouldBe(collection + ".item(undefined)", expectedElement);
    shouldBe(collection + ".item(null)", expectedElement);
    shouldBe(collection + ".item({a: 'blah'})", expectedElement);
    shouldBe(collection + ".item(false)", expectedElement);
    shouldBe(collection + ".item(true)", collection + ".item(1)");
    shouldBe(collection + ".item(4294967297)", collection + ".item(1)");
    shouldBeNull(collection + ".item(10000)");
    shouldBeNull(collection + ".item(-1)");
}

runTests("document.forms", "document.getElementById('a')");
runTests("document.forms[0].elements", "document.getElementById('x')");
runTests("document.forms[1].elements[2].options", "document.getElementById('o')");
runTests("document.anchors", "document.getElementById('c')");

// document.all is an ugly mutant (i.e. not an HTMLCollection).

if ("all" in document) {
    shouldBe("document.all.item('z')[0]", "document.forms[0].elements.namedItem('z')");
    shouldBe("document.all.item('z')[1]", "document.forms.namedItem('z')");
    shouldBe("document.all.item('z')[2]", "document.forms.namedItem('z').elements.namedItem('z')");
}

</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
