test_bug389797.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=389797
  5. -->
  6. <head>
  7. <title>Test for Bug 389797</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=389797">Mozilla Bug 389797</a>
  13. <p id="display"></p>
  14. <div id="content" style="display: none">
  15. </div>
  16. <pre id="test">
  17. <script class="testbody" type="text/javascript">
  18. /** Test for Bug 389797 **/
  19. var allTags = [];
  20. var classInfos = {};
  21. var interfaces = {};
  22. var interfacesNonClassinfo = {};
  23. function getClassName(tag) {
  24. return "HTML" + classInfos[tag] + "Element";
  25. }
  26. function HTML_TAG(aTagName, aImplClass) {
  27. allTags.push(aTagName);
  28. classInfos[aTagName] = aImplClass;
  29. interfaces[aTagName] = [ "nsIDOMEventTarget" ];
  30. // Some interfaces don't appear in classinfo because other interfaces that
  31. // inherit from them do.
  32. interfacesNonClassinfo[aTagName] =
  33. [ "nsIDOMNode",
  34. "nsIDOMElement" ];
  35. var interfaceName = "nsIDOM" + getClassName(aTagName);
  36. if (interfaceName in SpecialPowers.Ci) { // no nsIDOMHTMLSpanElement
  37. interfaces[aTagName].push(interfaceName);
  38. interfacesNonClassinfo[aTagName].push("nsIDOMHTMLElement");
  39. } else {
  40. // Inherits directly from nsIDOMHTMLElement.
  41. interfaces[aTagName].push("nsIDOMHTMLElement");
  42. }
  43. var interfaceNameNS = "nsIDOMNS" + getClassName(aTagName);
  44. if (interfaceNameNS in SpecialPowers.Ci) {
  45. interfaces[aTagName].push(interfaceNameNS);
  46. }
  47. if (arguments.length > 2) {
  48. for (var i = 0; i < arguments[2].length; ++i) {
  49. interfaces[aTagName].push(arguments[2][i]);
  50. }
  51. }
  52. if (arguments.length > 3) {
  53. for (i = 0; i < arguments[3].length; ++i) {
  54. interfacesNonClassinfo[aTagName].push(arguments[3][i]);
  55. }
  56. }
  57. }
  58. const objectIfaces = [
  59. "imgINotificationObserver", "nsIRequestObserver", "nsIStreamListener",
  60. "nsIFrameLoaderOwner", "nsIObjectLoadingContent", "nsIChannelEventSink"
  61. ];
  62. var objectIfaces2 = [];
  63. for (var iface of objectIfaces) {
  64. objectIfaces2.push(iface);
  65. }
  66. objectIfaces2.push("nsIImageLoadingContent");
  67. /* List copy/pasted from nsHTMLTagList.h, with the second field modified to the
  68. correct classinfo (instead of the impl class) in the following cases:
  69. applet
  70. base
  71. blockquote
  72. dir
  73. dl
  74. embed
  75. menu
  76. ol
  77. param
  78. q
  79. ul
  80. wbr
  81. head
  82. html
  83. */
  84. HTML_TAG("a", "Anchor");
  85. HTML_TAG("abbr", "");
  86. HTML_TAG("acronym", "");
  87. HTML_TAG("address", "");
  88. HTML_TAG("applet", "Applet", [], objectIfaces);
  89. HTML_TAG("area", "Area");
  90. HTML_TAG("article", "");
  91. HTML_TAG("aside", "");
  92. HTML_TAG("b", "");
  93. HTML_TAG("base", "Base");
  94. HTML_TAG("bdo", "");
  95. HTML_TAG("bgsound", "Unknown");
  96. HTML_TAG("big", "");
  97. HTML_TAG("blockquote", "Quote");
  98. HTML_TAG("body", "Body");
  99. HTML_TAG("br", "BR");
  100. HTML_TAG("button", "Button");
  101. HTML_TAG("canvas", "Canvas");
  102. HTML_TAG("caption", "TableCaption");
  103. HTML_TAG("center", "");
  104. HTML_TAG("cite", "");
  105. HTML_TAG("code", "");
  106. HTML_TAG("col", "TableCol");
  107. HTML_TAG("colgroup", "TableCol");
  108. HTML_TAG("data", "Data");
  109. HTML_TAG("datalist", "DataList");
  110. HTML_TAG("dd", "");
  111. HTML_TAG("del", "Mod");
  112. HTML_TAG("dfn", "");
  113. HTML_TAG("dir", "Directory");
  114. HTML_TAG("div", "Div");
  115. HTML_TAG("dl", "DList");
  116. HTML_TAG("dt", "");
  117. HTML_TAG("em", "");
  118. HTML_TAG("embed", "Embed", [], objectIfaces);
  119. HTML_TAG("fieldset", "FieldSet");
  120. HTML_TAG("figcaption", "")
  121. HTML_TAG("figure", "")
  122. HTML_TAG("font", "Font");
  123. HTML_TAG("footer", "")
  124. HTML_TAG("form", "Form", [], [ "nsIWebProgressListener" ]);
  125. HTML_TAG("frame", "Frame", [ "nsIDOMMozBrowserFrame" ], [ "nsIFrameLoaderOwner" ]);
  126. HTML_TAG("frameset", "FrameSet");
  127. HTML_TAG("h1", "Heading");
  128. HTML_TAG("h2", "Heading");
  129. HTML_TAG("h3", "Heading");
  130. HTML_TAG("h4", "Heading");
  131. HTML_TAG("h5", "Heading");
  132. HTML_TAG("h6", "Heading");
  133. HTML_TAG("head", "Head");
  134. HTML_TAG("header", "")
  135. HTML_TAG("hgroup", "")
  136. HTML_TAG("hr", "HR");
  137. HTML_TAG("html", "Html");
  138. HTML_TAG("i", "");
  139. HTML_TAG("iframe", "IFrame", [ "nsIDOMMozBrowserFrame" ],
  140. [ "nsIFrameLoaderOwner" ]);
  141. HTML_TAG("image", "");
  142. HTML_TAG("img", "Image", [ "nsIImageLoadingContent" ], []);
  143. HTML_TAG("input", "Input", [], [ "imgINotificationObserver",
  144. "nsIImageLoadingContent",
  145. "nsIDOMNSEditableElement" ]);
  146. HTML_TAG("ins", "Mod");
  147. HTML_TAG("kbd", "");
  148. HTML_TAG("keygen", "Span");
  149. HTML_TAG("label", "Label");
  150. HTML_TAG("legend", "Legend");
  151. HTML_TAG("li", "LI");
  152. HTML_TAG("link", "Link");
  153. HTML_TAG("listing", "Pre");
  154. HTML_TAG("main", "");
  155. HTML_TAG("map", "Map");
  156. HTML_TAG("mark", "");
  157. HTML_TAG("menu", "Menu");
  158. HTML_TAG("meta", "Meta");
  159. HTML_TAG("meter", "Meter");
  160. HTML_TAG("multicol", "Unknown");
  161. HTML_TAG("nav", "")
  162. HTML_TAG("nobr", "");
  163. HTML_TAG("noembed", "");
  164. HTML_TAG("noframes", "");
  165. HTML_TAG("noscript", "");
  166. HTML_TAG("object", "Object", [],
  167. objectIfaces.concat([ "nsIImageLoadingContent" ]));
  168. HTML_TAG("ol", "OList");
  169. HTML_TAG("optgroup", "OptGroup");
  170. HTML_TAG("option", "Option");
  171. HTML_TAG("p", "Paragraph");
  172. HTML_TAG("param", "Param");
  173. HTML_TAG("plaintext", "");
  174. HTML_TAG("pre", "Pre");
  175. HTML_TAG("q", "Quote");
  176. HTML_TAG("rb", "");
  177. HTML_TAG("rp", "");
  178. HTML_TAG("rt", "");
  179. HTML_TAG("rtc", "");
  180. HTML_TAG("ruby", "");
  181. HTML_TAG("s", "");
  182. HTML_TAG("samp", "");
  183. HTML_TAG("script", "Script", [ "nsIScriptLoaderObserver" ], []);
  184. HTML_TAG("section", "")
  185. HTML_TAG("select", "Select", ["nsIDOMHTMLSelectElement"]);
  186. HTML_TAG("small", "");
  187. HTML_TAG("span", "Span");
  188. HTML_TAG("strike", "");
  189. HTML_TAG("strong", "");
  190. HTML_TAG("style", "Style");
  191. HTML_TAG("sub", "");
  192. HTML_TAG("sup", "");
  193. HTML_TAG("table", "Table");
  194. HTML_TAG("tbody", "TableSection");
  195. HTML_TAG("td", "TableCell");
  196. HTML_TAG("textarea", "TextArea", [], [ "nsIDOMNSEditableElement" ]);
  197. HTML_TAG("tfoot", "TableSection");
  198. HTML_TAG("th", "TableCell");
  199. HTML_TAG("thead", "TableSection");
  200. HTML_TAG("template", "Template");
  201. HTML_TAG("time", "Time");
  202. HTML_TAG("title", "Title");
  203. HTML_TAG("tr", "TableRow");
  204. HTML_TAG("tt", "");
  205. HTML_TAG("u", "");
  206. HTML_TAG("ul", "UList");
  207. HTML_TAG("var", "");
  208. HTML_TAG("wbr", "");
  209. HTML_TAG("xmp", "Pre");
  210. function tagName(aTag) {
  211. return "<" + aTag + ">";
  212. }
  213. for (var tag of allTags) {
  214. var node = document.createElement(tag);
  215. // Have to use the proto's toString(), since HTMLAnchorElement and company
  216. // override toString().
  217. var nodeString = HTMLElement.prototype.toString.apply(node);
  218. // Debug builds have extra info, so chop off after "Element" if it's followed
  219. // by ' ' or ']'
  220. nodeString = nodeString.replace(/Element[\] ].*/, "Element");
  221. var classInfoString = getClassName(tag);
  222. is(nodeString, "[object " + classInfoString,
  223. "Unexpected classname for " + tagName(tag));
  224. is(node instanceof window[classInfoString], true,
  225. tagName(tag) + " not an instance of " + classInfos[tag]);
  226. if (classInfoString != 'HTMLUnknownElement') {
  227. is(node instanceof HTMLUnknownElement, false,
  228. tagName(tag) + " is an instance of HTMLUnknownElement");
  229. } else {
  230. is(node instanceof HTMLUnknownElement, true,
  231. tagName(tag) + " is an instance of HTMLUnknownElement");
  232. }
  233. // Check that each node QIs to all the things we expect it to QI to
  234. for (var iface of interfaces[tag].concat(interfacesNonClassinfo[tag])) {
  235. is(iface in SpecialPowers.Ci, true,
  236. iface + " not in Components.interfaces");
  237. is(node instanceof SpecialPowers.Ci[iface], true,
  238. tagName(tag) + " does not QI to " + iface);
  239. }
  240. }
  241. </script>
  242. </pre>
  243. </body>
  244. </html>