4 <title>Attached callback of a custom element should be called </title>
5 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
6 <meta name="assert" content="attached callback ... must be enqueued whenever custom element is inserted into a document and this document has a browsing context.">
7 <link rel="help" href="http://www.w3.org/TR/custom-elements/#types-of-callbacks">
8 <script src="../../../../../resources/testharness.js"></script>
9 <script src="../../../../../resources/testharnessreport.js"></script>
10 <script src="../../testcommon.js"></script>
11 <link rel="stylesheet" href="../../../../../resources/testharness.css">
17 var doc = newHTMLDocument();
18 var proto = newHTMLElementPrototype();
19 var GeneratedConstructor = doc.registerElement('x-a', {prototype: proto});
20 var customElement = new GeneratedConstructor();
21 assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached ' +
22 'should not be called in documents that do not have a browsing context');
23 }, 'Test attached callback if custom element is instantiated via constructor. ' +
24 'Document has no browsing context');
28 var doc = newHTMLDocument();
29 var proto = newHTMLElementPrototype();
30 doc.registerElement('x-b', {prototype: proto});
31 doc.body.innerHTML = '<x-b></x-b>';
32 assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached ' +
33 'should not be called in documents that do not have a browsing context');
34 }, 'Test attached callback if custom element is created via innerHTML property. ' +
35 'Document has no browsing context');
39 var doc = newHTMLDocument();
40 doc.body.innerHTML = '<x-c></x-c>';
41 var proto = newHTMLElementPrototype();
42 doc.registerElement('x-c', {prototype: proto});
43 assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached ' +
44 'should not be called in documents that do not have a browsing context');
45 }, 'Test attached callback if custom element is created via innerHTML property before ' +
46 'registration. Document has no browsing context');
50 var doc = newHTMLDocument();
51 doc.body.innerHTML = '<x-d id="x-d"></x-d>';
52 var customElement = doc.querySelector('#x-d');
54 var proto = newHTMLElementPrototype();
55 var GeneratedConstructor = doc.registerElement('x-d', {prototype: proto});
57 customElement.constructor.prototype = proto;
58 assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached should ' +
59 'not be called for unregistered custom element in document without browsing context');
60 }, 'Test attached callback if custom element is unregistered');
63 testInIFrame('../../resources/x-element.html', function(doc) {
64 var proto = newHTMLElementPrototype();
65 doc.registerElement('x-element', {prototype: proto});
66 assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should be ' +
67 'called in documents with browsing context');
68 }, 'Test attached callback. Document has browsing context');
71 testInIFrame('../../resources/blank.html', function(doc) {
72 var proto = newHTMLElementPrototype();
73 doc.registerElement('x-element', {prototype: proto});
75 var x = doc.createElement('x-element');
76 assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached should not ' +
77 'be called before element is added to document with browsing context');
79 doc.body.appendChild(x);
80 assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should be called ' +
81 'in documents with browsing context');
82 }, 'Test attached callback. Registered element is created via document.createElement(). ' +
83 'Document has browsing context');
86 testInIFrame('../../resources/blank.html', function(doc) {
87 var x = doc.createElement('x-element');
88 doc.body.appendChild(x);
89 var proto = newHTMLElementPrototype();
90 doc.registerElement('x-element', {prototype: proto});
91 assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should ' +
92 'be called in documents with browsing context');
93 }, 'Test attached callback. Unregistered element is created via document.createElement(). ' +
94 'Document has browsing context');
97 testInIFrame('../../resources/blank.html', function(doc) {
98 var proto = newHTMLElementPrototype();
99 doc.registerElement('x-element', {prototype: proto});
100 doc.body.innerHTML = '<x-element></x-element>';
101 assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should ' +
102 'be called in documents with browsing context');
103 }, 'Test attached callback. Registered element is created via innerHTML property. ' +
104 'Document has browsing context');
107 testInIFrame('../../resources/blank.html', function(doc) {
108 doc.body.innerHTML = '<x-element></x-element>';
109 var proto = newHTMLElementPrototype();
110 doc.registerElement('x-element', {prototype: proto});
111 assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should ' +
112 'be called in documents with browsing context');
113 }, 'Test attached callback. Unresolved element is created via innerHTML property. ' +
114 'Document has browsing context');