Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / w3c / web-platform-tests / custom-elements / custom-element-lifecycle / types-of-callbacks / attached-callback-test.html
1 <!DOCTYPE html>
2 <html>
3 <head>
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">
12 </head>
13 <body>
14 <div id="log"></div>
15 <script>
16 test(function() {
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');
25
26
27 test(function() {
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');
36
37
38 test(function() {
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');
47
48
49 test(function() {
50     var doc = newHTMLDocument();
51     doc.body.innerHTML = '<x-d id="x-d"></x-d>';
52     var customElement = doc.querySelector('#x-d');
53
54     var proto = newHTMLElementPrototype();
55     var GeneratedConstructor = doc.registerElement('x-d', {prototype: proto});
56
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');
61
62
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');
69
70
71 testInIFrame('../../resources/blank.html', function(doc) {
72     var proto = newHTMLElementPrototype();
73     doc.registerElement('x-element', {prototype: proto});
74
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');
78
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');
84
85
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');
95
96
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');
105
106
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');
115 </script>
116 </body>
117 </html>