OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../../../resources/testharness.js"></script> | |
3 <script src="../../../resources/testharnessreport.js"></script> | |
4 | |
5 <template id="template"> | |
6 <svg> | |
7 <defs> | |
8 <g id="used-group"> | |
9 <rect | |
10 id="rect" | |
11 is="x-rect" | |
12 x="10" y="10" | |
13 width="100" height="100" | |
14 fill="red"/> | |
15 </g> | |
16 </defs> | |
17 <use xlink:href="#used-group"/> | |
18 </svg> | |
19 </template> | |
20 | |
21 <div id="container"></div> | |
22 | |
23 <script> | |
24 "use strict"; | |
25 | |
26 var instances = []; | |
27 | |
28 function createPrototype(superClass) { | |
29 class ElementType extends superClass { | |
dominicc (has gone to gerrit)
2015/10/30 02:42:39
This nested class definition w/ superClass is very
| |
30 get ownerScope() { | |
31 var scope = this.parentNode; | |
32 while (scope && scope.parentNode) | |
33 scope = scope.parentNode; | |
34 return scope; | |
35 } | |
36 createdCallback() { | |
37 this.instanceId = instances.length; | |
38 instances[this.instanceId] = this; | |
39 assert_false(this.ownerScope instanceof ShadowRoot, | |
40 "Should not call createdCallback in UA ShadowRoot."); | |
41 } | |
42 attachedCallback() { | |
43 assert_false(this.ownerScope instanceof ShadowRoot, | |
44 "Should not call attachedCallback in UA ShadowRoot."); | |
45 assert_equals(instances[this.instanceId], this); | |
46 } | |
47 detachedCallback() { | |
48 assert_false(this.ownerScope instanceof ShadowRoot, | |
49 "Should not call detachedCallback in UA ShadowRoot."); | |
50 assert_equals(instances[this.instanceId], this); | |
51 } | |
52 attributeChangedCallback() { | |
53 assert_unreached("attributeChangedCallback should never be called.") ; | |
54 } | |
55 }; | |
56 return ElementType.prototype; | |
57 } | |
58 | |
59 // <rect is=x-rect> | |
60 var XRectElement = document.registerElement('x-rect', { | |
61 extends: 'rect', | |
62 prototype: createPrototype(SVGRectElement), | |
63 }); | |
64 | |
65 // <x-test> | |
66 var XTestElement = document.registerElement('x-test', { | |
67 prototype: createPrototype(HTMLElement), | |
68 }); | |
69 | |
70 test(function () { | |
71 var template = document.getElementById("template"); | |
72 var svg = document.importNode(template.content, true).firstElementChild; | |
73 var usedGroup = svg.getElementById("used-group"); | |
74 document.body.appendChild(svg); | |
75 | |
76 // Force a recreation of the use trees. | |
77 document.body.offsetTop; | |
78 assert_array_equals([usedGroup.firstElementChild], instances); | |
79 | |
80 var elements = [ | |
81 usedGroup.firstElementChild, | |
82 new XRectElement(), | |
83 new XTestElement(), | |
84 new XRectElement(), | |
85 ]; | |
86 | |
87 // Add another <rect is=x-rect>, and a child <x-test> that also contains one . | |
88 usedGroup.appendChild(elements[1]); | |
89 var test = usedGroup.appendChild(elements[2]); | |
90 test.appendChild(elements[3]); | |
91 | |
92 // Force a recreation of the use trees. | |
93 document.body.offsetTop; | |
94 assert_array_equals(elements, instances); | |
95 | |
96 for (var i = 0; i < instances.length; ++i) { | |
97 assert_true(instances[i].ownerScope instanceof Document, | |
98 "No instances should be inside a ShadowRoot."); | |
99 } | |
100 }, "SVG <use> shadow trees should not be exposed through custom elements."); | |
101 </script> | |
OLD | NEW |