<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=870787
-->
<head>
  <title>Test for Bug 870787</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="reflect.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=870787">Mozilla Bug 870787</a>

<p id="msg"></p>

<form id="form0"></form>
<img name="img0" id="img0id">

<img name="img1" id="img1id" />
<form id="form1">
  <img name="img2" id="img2id" />
</form>
<img name="img3" id="img3id" />

<table>
  <form id="form2">
  <tr><td>
    <button name="input1" id="input1id" />
    <input name="input2" id="input2id" />
  </form>
</table>

<table>
  <form id="form3">
  <tr><td>
    <img name="img4" id="img4id" />
    <img name="img5" id="img5id" />
  </form>
</table>

<form id="form4"><img id="img6"></form>

<pre id="test">
<script type="application/javascript">

/** Test for Bug 870787 **/

var form0 = document.getElementById("form0");
ok(form0, "Form0 exists");
ok(!form0.img0, "Form0.img0 doesn't exist");
ok(!form0.img0id, "Form0.img0id doesn't exist");

var form1 = document.getElementById("form1");
ok(form1, "Form1 exists");
ok(!form1.img1, "Form1.img1 doesn't exist");
ok(!form1.img1id, "Form1.img1id doesn't exist");
is(form1.img2, document.getElementById("img2id"), "Form1.img2 exists");
is(form1.img2id, document.getElementById("img2id"), "Form1.img2id exists");
ok(!form1.img3, "Form1.img3 doesn't exist");
ok(!form1.img3id, "Form1.img3id doesn't exist");

var form2 = document.getElementById("form2");
ok(form2, "Form2 exists");
is(form2.input1, document.getElementById("input1id"), "Form2.input1 exists");
is(form2.input1id, document.getElementById("input1id"), "Form2.input1id exists");
is(form2.input2, document.getElementById("input2id"), "Form2.input2 exists");
is(form2.input2id, document.getElementById("input2id"), "Form2.input2id exists");

var form3 = document.getElementById("form3");
ok(form3, "Form3 exists");
is(form3.img4, document.getElementById("img4id"), "Form3.img4 doesn't exists");
is(form3.img4id, document.getElementById("img4id"), "Form3.img4id doesn't exists");
is(form3.img5, document.getElementById("img5id"), "Form3.img5 doesn't exists");
is(form3.img5id, document.getElementById("img5id"), "Form3.img5id doesn't exists");

var form4 = document.getElementById("form4");
ok(form4, "Form4 exists");
is(Object.getOwnPropertyNames(form4.elements).indexOf("img6"), -1, "Form4.elements should not contain img6");

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