<!DOCTYPE html>
<html>
<body>
<img id="1"><img id="2"><img id="3"><img id="4">
<script>

var errors = '';
var images = document.images;
for (var i = images.length; i > 0; i--) {
    images[0].class = 'foo';
    if (parseInt(images[i - 1].id) != i)
        errors += 'FAIL - Expected ' + i + ' but got ' + images[i - 1].id + '<br>';
    images[i - 1].class = 'foo';
}

if (window.testRunner)
    testRunner.dumpAsText();

document.body.innerHTML = 'Tests that HTMLCollection of a subtree (as opposed to direct children) can be iterated backwards.<br>'
+ 'There should be no console error and WebKit should not hit an assertion.<br><br>' + (errors ? errors : 'PASS');

</script>
</body>
</html>
