test_nodelists.xul 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
  4. type="text/css"?>
  5. <window title="Test nodelists from chrome"
  6. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  7. <script type="application/javascript"
  8. src="chrome://mochikit/content/MochiKit/packed.js"></script>
  9. <script type="application/javascript"
  10. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  11. <!-- test results are displayed in the html:body -->
  12. <body xmlns="http://www.w3.org/1999/xhtml">
  13. </body>
  14. <!-- test code goes here -->
  15. <script type="application/javascript"><![CDATA[
  16. SimpleTest.waitForExplicitFinish();
  17. function go() {
  18. var win = $('ifr').contentWindow;
  19. var list = win.document.getElementsByTagName('p');
  20. is(list.length, 3, "can get the length");
  21. ok(list[0] instanceof HTMLParagraphElement, "can get list[0]");
  22. is(list[0], list.item(0), "list.item works");
  23. is(list.item, list.item, "don't recreate functions for each get");
  24. var list2 = list[2];
  25. ok(list[2] instanceof HTMLParagraphElement, "list[2] exists");
  26. ok("2" in list, "in operator works");
  27. is(win.document.body.removeChild(win.document.body.lastChild), list2, "remove last paragraph element");
  28. ok(!("2" in list), "in operator doesn't see phantom element");
  29. is(list[2], undefined, "no node there!");
  30. var optionList = win.document.createElement("select").options;
  31. var option = win.document.createElement("option");
  32. optionList[0] = option;
  33. is(optionList.item(0), option, "Creators work");
  34. option = win.document.createElement("option");
  35. optionList[0] = option;
  36. is(optionList.item(0), option, "Setters work");
  37. SimpleTest.finish();
  38. }
  39. ]]></script>
  40. <iframe id="ifr"
  41. src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_nodelists.html"
  42. onload="go()" />
  43. </window>