test_custom_element_content.xhtml (2085B)
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 <!-- 6 https://bugzilla.mozilla.org/show_bug.cgi?id=1130028 7 --> 8 <window title="Mozilla Bug 1130028" 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 11 12 <!-- test results are displayed in the html:body --> 13 <body xmlns="http://www.w3.org/1999/xhtml"> 14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1130028" 15 target="_blank">Mozilla Bug 1130028</a> 16 <iframe onload="startTests()" id="frame" src="http://example.com/chrome/dom/base/test/chrome/frame_custom_element_content.html"></iframe> 17 </body> 18 19 <!-- test code goes here --> 20 <script type="application/javascript"><![CDATA[ 21 22 /** Test for Bug 1130028 */ 23 var connectedCallbackCount = 0; 24 25 function startTests() { 26 var frame = $("frame"); 27 28 class XFoo extends frame.contentWindow.HTMLElement {}; 29 frame.contentWindow.customElements.define("x-foo", XFoo); 30 var elem = new XFoo(); 31 is(elem.tagName, "X-FOO", "Constructor should create an x-foo element."); 32 33 class XBar extends frame.contentWindow.HTMLElement { 34 constructor() { 35 super(); 36 this.magicNumber = 42; 37 } 38 39 connectedCallback() { 40 connectedCallbackCount++; 41 // Callback should be called only once by element created in content. 42 is(connectedCallbackCount, 1, "Connected callback called, should be called once in test."); 43 is(this.magicNumber, 42, "Callback should be able to see the custom prototype."); 44 } 45 }; 46 47 frame.contentWindow.customElements.define("x-bar", XBar); 48 is(connectedCallbackCount, 1, "Connected callback should be called by element created in content."); 49 50 var element = frame.contentDocument.createElement("x-bar"); 51 is(element.magicNumber, 42, "Should be able to see the custom prototype on created element."); 52 } 53 54 ]]></script> 55 </window>