4 <title>Changing IS attribute of the custom element must not affect this element's custom element type, after element is instantiated</title>
5 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
6 <meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
7 <meta name="assert" content="After a custom element is instantiated, changing the value of the IS attribute must not affect this element's custom element type">
8 <link rel="help" href="http://www.w3.org/TR/custom-elements/#instantiating-custom-elements">
9 <script src="../../../../resources/testharness.js"></script>
10 <script src="../../../../resources/testharnessreport.js"></script>
11 <script src="../testcommon.js"></script>
12 <link rel="stylesheet" href="../../../../resources/testharness.css">
18 var doc = newHTMLDocument();
19 var GeneratedConstructor = doc.registerElement('x-a');
20 var customElement = new GeneratedConstructor();
21 doc.registerElement('x-b');
22 customElement.setAttribute('is', 'x-b');
23 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
24 'Custom element type should be x-a');
25 }, 'Test custom element type, after assigning IS attribute value. ' +
26 'Element is created by constructor');
30 var doc = newHTMLDocument();
31 var GeneratedConstructor = doc.registerElement('x-c');
32 doc.registerElement('x-d');
33 doc.body.innerHTML = '<x-c id="x-c"></x-c>';
34 var customElement = doc.querySelector('#x-c');
35 customElement.setAttribute('is', 'x-d');
36 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
37 'Custom element type should be x-c');
38 }, 'Test custom element type, after assigning IS attribute value. ' +
39 'Element is created via innerHTML property');
43 var doc = newHTMLDocument();
44 doc.body.innerHTML = '<x-e id="x-e"></x-e>';
45 var customElement = doc.querySelector('#x-e');
46 customElement.setAttribute('is', 'x-f');
47 var GeneratedConstructor = doc.registerElement('x-e');
48 doc.registerElement('x-f');
49 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
50 'Custom element type should be x-e');
51 }, 'Test custom element type, after assigning IS attribute value to unresolved element. ' +
52 'Element is created via innerHTML property');
55 testInIFrame('../resources/x-element.html', function(doc) {
56 var GeneratedConstructor = doc.registerElement('x-element');
57 doc.registerElement('y-element');
58 var customElement = doc.querySelector('#x-element');
59 customElement.setAttribute('is', 'y-element');
60 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
61 'Custom element type should be x-element');
62 }, 'Test custom element type, after assigning IS attribute value. ' +
63 'Element is defined in loaded HTML document');
66 testInIFrame('../resources/x-element.html', function(doc) {
67 var customElement = doc.querySelector('#x-element');
68 customElement.setAttribute('is', 'y-element');
69 var GeneratedConstructor = doc.registerElement('x-element');
70 doc.registerElement('y-element');
71 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
72 'Custom element type should be x-element');
73 }, 'Test custom element type, after assigning IS attribute value to unresolved element. ' +
74 'Element is defined in loaded HTML document');
78 var doc = newHTMLDocument();
79 HTML5_ELEMENTS.forEach(function(tagName) {
80 if (HTML5_DOCUMENT_ELEMENTS.indexOf(tagName) !== -1) {
83 var name = 'y-' + tagName;
84 var obj = doc.createElement(tagName);
85 var proto = Object.create(obj.constructor.prototype);
86 var GeneratedConstructor = doc.registerElement(name, {prototype: proto, extends: tagName});
87 if (HTML5_TABLE_ELEMENTS.indexOf(tagName) !== -1) {
90 '<' + tagName + ' id="custom-element" is="' + name + '"></' + tagName + '>' +
94 '<' + tagName + ' id="custom-element" is="' + name + '"></' + tagName + '>';
96 var customElement = doc.querySelector('#custom-element');
97 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
98 'Custom element type should be '+ name);
100 var name2 = 'y-a-' + tagName;
101 doc.registerElement(name2);
102 customElement.setAttribute('is', name2);
103 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
104 'Custom element type should be ' + name);
106 }, 'Test custom element type after changing IS attribute value. ' +
107 'Element is HTML5 element with IS attribute referring to custom element type');
111 var doc = newHTMLDocument();
112 var localName = 'z-a';
113 var obj = doc.createElement('a');
114 var proto = Object.create(obj.constructor.prototype);
115 var GeneratedConstructor = doc.registerElement(localName, {prototype: proto, extends: 'a'});
116 doc.body.innerHTML = '<a id="custom-element" is="' + localName + '"></a>';
117 var customElement = doc.querySelector('#custom-element');
119 HTML5_ELEMENTS.forEach(function(tagName) {
120 var name = 'z-a-' + tagName;
121 var htmlElement = doc.createElement(tagName);
122 var htmlElementProto = Object.create(htmlElement.constructor.prototype);
123 doc.registerElement(name, {prototype: htmlElementProto, extends: tagName});
124 customElement.setAttribute('is', name);
125 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
126 'Custom element type should be ' + localName);
128 }, 'Test custom element type after changing IS attribute value several times. ' +
129 'Element is HTML5 element with IS attribute referring to custom element type');
133 var doc = newHTMLDocument();
134 var GeneratedConstructor = doc.registerElement('x-g');
135 doc.registerElement('x-h');
136 doc.body.innerHTML = '<x-g id="x-g" is="x-h"></x-g>';
137 var customElement = doc.querySelector('#x-g');
138 customElement.removeAttribute('is');
139 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
140 'Custom element type should be x-g');
141 }, 'Test custom element type, after removing IS attribute value. ' +
142 'Element is created via innerHTML property');
146 var doc = newHTMLDocument();
147 var obj = doc.createElement('a');
148 var proto = Object.create(obj.constructor.prototype);
149 var GeneratedConstructor = doc.registerElement('x-i', {prototype: proto, extends: 'a'});
150 doc.body.innerHTML = '<a id="x-i" is="x-i"></a>';
151 var customElement = doc.querySelector('#x-i');
152 customElement.removeAttribute('is');
153 assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
154 'Custom element type should be x-i');
155 }, 'Test custom element type, after removing IS attribute value. ' +
156 'Element is HTML5 element with IS attribute referring to custom element type');