chromium/third_party/blink/web_tests/fast/dom/HTMLDocument/document-special-properties.html

<body>

<p>This test covers the various ways of accessing DOM elements through
the document object by name, id or index, directly as properties of
the document object. This lookup is supposed to include embed,
form, image, object and iframe by name, but only object by
id. It should give the element itself in the case of a single match,
or an HTMLCollection in the case of multiple matches; except that when
exactly one item that is an iframe matches, it will give the window
object for that iframe.
</p>

<p>Our results match IE.</p>

<hr>

<script>
document.custom=new Object();

if (window.testRunner)
    testRunner.dumpAsText();
</script>

<div style="visibility: hidden; width: 0px; height: 0px;">
<img name="image1" width="0" height="0">
<img name="image2" width="0" height="0">
<img name="image2" width="0" height="0">
<img id="image3" width="0" height="0">
<img id="image4" width="0" height="0">
<img id="image4" width="0" height="0">
<img id="image5" width="0" height="0">
<img name="image5" width="0" height="0">
<img name="image5" width="0" height="0">
<img id="image5" width="0" height="0">
<img id="image6" name="image6name" width="0" height="0">
<img id="image7" name="" width="0" height="0">
<img id="image8" name="image8name" width="0" height="0">
<img id="image8" width="0" height="0">
<img id="image8" name="image7name" width="0" height="0">
<img id="image9" name="image9name" width="0" height="0">

<form name="form1" width="0" height="0"></form>
<form name="form2" width="0" height="0"></form>
<form name="form2" width="0" height="0"></form>
<form id="form3" width="0" height="0"></form>
<form id="form4" width="0" height="0"></form>
<form id="form4" width="0" height="0"></form>
<form id="form5" width="0" height="0"></form>
<form name="form5" width="0" height="0"></form>
<form name="form5" width="0" height="0"></form>
<form id="form5" width="0" height="0"></form>

<embed name="embed1" width="0" height="0"></embed>
<embed name="embed2" width="0" height="0"></embed>
<embed name="embed2" width="0" height="0"></embed>
<embed id="embed3" width="0" height="0"></embed>
<embed id="embed4" width="0" height="0"></embed>
<embed id="embed4" width="0" height="0"></embed>
<embed id="embed5" width="0" height="0"></embed>
<embed name="embed5" width="0" height="0"></embed>
<embed name="embed5" width="0" height="0"></embed>
<embed id="embed5" width="0" height="0"></embed>
<object name="embed6"><embed name="embed6"></embed></object>
<object name="embed7_0"><embed name="embed7"></embed></object>
<object name="object8_0" width="0" height="0"><param><embed name="embed8" width="0" height="0"></object></param></object>

<object name="object1" width="0" height="0"></object>
<object name="object2" width="0" height="0"></object>
<object name="object2" width="0" height="0"></object>
<object id="object3" width="0" height="0"></object>
<object id="object4" width="0" height="0"></object>
<object id="object4" width="0" height="0"></object>
<object id="object5" width="0" height="0"></object>
<object name="object5" width="0" height="0"></object>
<object name="object5" width="0" height="0"></object>
<object id="object5" width="0" height="0"></object>
<object name="object6" width="0" height="0"><object name="object6" width="0" height="0"></object></object>
<object name="object7_0" width="0" height="0"><object name="object7" width="0" height="0"></object></object>

<iframe name="iframe1" width="0" height="0"></iframe>
<iframe name="iframe2" width="0" height="0"></iframe>
<iframe name="iframe2" width="0" height="0"></iframe>
<iframe id="iframe3" width="0" height="0"></iframe>
<iframe id="iframe4" width="0" height="0"></iframe>
<iframe id="iframe4" width="0" height="0"></iframe>
<iframe id="iframe5" width="0" height="0"></iframe>
<iframe name="iframe5" width="0" height="0"></iframe>
<iframe name="iframe5" width="0" height="0"></iframe>
<iframe id="iframe5" width="0" height="0"></iframe>

<span name="span1" width="0" height="0"></span>
<span name="span2" width="0" height="0"></span>
<span name="span2" width="0" height="0"></span>
<span id="span3" width="0" height="0"></span>
<span id="span4" width="0" height="0"></span>
<span id="span4" width="0" height="0"></span>
<span id="span5" width="0" height="0"></span>
<span name="span5" width="0" height="0"></span>
<span name="span5" width="0" height="0"></span>
<span id="span5" width="0" height="0"></span>

<img id="mixed1" width="0" height="0">
<form id="mixed1" width="0" height="0"></form>
<embed id="mixed1" width="0" height="0"></embed>
<object id="mixed1" width="0" height="0"></object>
<iframe id="mixed1" width="0" height="0"></iframe>
<span id="mixed1" width="0" height="0"></span>

<img name="mixed2" width="0" height="0">
<form name="mixed2" width="0" height="0"></form>
<embed name="mixed2" width="0" height="0"></embed>
<object name="mixed2" width="0" height="0"></object>
<iframe name="mixed2" width="0" height="0"></iframe>
<span name="mixed2" width="0" height="0"></span>

<img id="mixed3" width="0" height="0">
<form id="mixed3" width="0" height="0"></form>
<embed id="mixed3" width="0" height="0"></embed>
<object id="mixed3" width="0" height="0"></object>
<span id="mixed3" width="0" height="0"></span>

<img name="mixed4" width="0" height="0">
<form name="mixed4" width="0" height="0"></form>
<embed name="mixed4" width="0" height="0"></embed>
<object name="mixed4" width="0" height="0"></object>
<span name="mixed4" width="0" height="0"></span>

<img name="body" with="0" height="0">
<img name="custom" with="0" height="0">
<iframe name="location" with="0" height="0"></iframe>

</div>

<pre id="results">
Results:<br>
</pre>

<script>
function print(x)
{
   document.getElementById("results").innerHTML += x;
}

function printElement(e)
{
    if (e.tagName) {
        print(" " + e.tagName);

    if (e.name && e.id) {
        print("(id,name)");
    } else if (e.name) {
        print("(name)");
        } else if (e.id) {
        print("(id)");
    }
    } else if (e.navigator) {
        print(" WINDOW");
    } else {
        print(" OTHER");
    }
}

function testProperty(description, propName) {
    print(description);
    print(":");
    var propVal = document[propName];

    if (!propVal) {
        print(" undefined");
    } else if (propVal.length) {
        print(" collection(" + propVal.length + ")");
    for (var i = 0; i < propVal.length; i++) {
        printElement(propVal[i]);
    }
    } else {
        print(" single");
    printElement(propVal);
    }
    
    print("<br>");
}

testProperty("Nonexistent image name", "image0");
testProperty("Image by name (unique)", "image1");
testProperty("Image by name (multiple)", "image2");
testProperty("Image by id (unique)", "image3");
testProperty("Image by id (multiple)", "image4");
testProperty("Image by id/name mixed", "image5");
testProperty("Image by id, name present (unique)", "image6");
testProperty("Image by id, empty name present (unique)", "image7");
testProperty("Image by id, name present (multiple)", "image8");
testProperty("Image by name, id present (unique)", "image9name");

print("<br>");

testProperty("Nonexistent form name", "form0");
testProperty("Form by name (unique)", "form1");
testProperty("Form by name (multiple)", "form2");
testProperty("Form by id (unique)", "form3");
testProperty("Form by id (multiple)", "form4");
testProperty("Form by id/name mixed", "form5");
print("<br>");

testProperty("Nonexistent object name", "object0");
testProperty("Object by name (unique)", "object1");
testProperty("Object by name (multiple)", "object2");
testProperty("Object by id (unique)", "object3");
testProperty("Object by id (multiple)", "object4");
testProperty("Object by id/name mixed", "object5");
testProperty("Object by name nested in object with the same name", "object6");
testProperty("Object by name nested in object with a different name", "object7");
print("<br>");

testProperty("Nonexistent embed name", "embed0");
testProperty("Embed by name (unique)", "embed1");
testProperty("Embed by name (multiple)", "embed2");
testProperty("Embed by id (unique)", "embed3");
testProperty("Embed by id (multiple)", "embed4");
testProperty("Embed by id/name mixed", "embed5");
testProperty("Embed by name nested in object with the same name", "embed6");
testProperty("Embed by name nested in object with a different name", "embed7");
testProperty("Embed by name nested in param of an object with a different name", "embed8");
print("<br>");

testProperty("Nonexistent iframe name", "iframe0");
testProperty("Iframe by name (unique)", "iframe1");
testProperty("Iframe by name (multiple)", "iframe2");
testProperty("Iframe by id (unique)", "iframe3");
testProperty("Iframe by id (multiple)", "iframe4");
testProperty("Iframe by id/name mixed", "iframe5");
print("<br>");

testProperty("Nonexistent span name", "span0");
testProperty("Span by name (unique)", "span1");
testProperty("Span by name (multiple)", "span2");
testProperty("Span by id (unique)", "span3");
testProperty("Span by id (multiple)", "span4");
testProperty("Span by id/name mixed", "span5");
print("<br>");

testProperty("Mixed by id", "mixed1");
testProperty("Mixed by name", "mixed2");
testProperty("Mixed by id (no iframe)", "mixed3");
testProperty("Mixed by name (no iframe)", "mixed4");
print("<br>");

testProperty("Numeric 0", 0);
testProperty("Numeric 12", 12);
testProperty("Numeric 13", 13);
print("<br>");

testProperty("Conflicting image", "body");
testProperty("Conflicting image (custom property)", "custom");
testProperty("Conflicting iframe", "location");

</script>
</body>