Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / imported / web-platform-tests / custom-elements / custom-element-lifecycle / types-of-callbacks / created-callback-element-prototype-test.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>The custom element prototype must be set just prior to invoking created callback</title>
5 <meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
6 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
7 <meta name="assert" content="The custom element prototype must be set just prior to invoking callback.">
8 <link rel="help" href="http://www.w3.org/TR/custom-elements/#types-of-callbacks">
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">
13 </head>
14 <body>
15 <div id="log"></div>
16 <script>
17 test(function() {
18     var doc = newHTMLDocument();
19     var proto = newHTMLElementPrototype();
20
21     doc.body.innerHTML = '<x-a></x-a>';
22     doc.registerElement('x-a', {prototype: proto});
23     assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
24         'The custom element prototype is incorrect inside created callback');
25 }, 'Test custom element prototype inside created callback when custom element is created ' +
26     'in HTML before registration of a custom element');
27
28
29 test(function() {
30     var doc = newHTMLDocument();
31     var proto = newHTMLElementPrototype();
32
33     doc.registerElement('x-b', {prototype: proto});
34     doc.body.innerHTML = '<x-b></x-b>';
35     assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
36         'The custom element prototype is incorrect inside created callback');
37 }, 'Test custom element prototype inside created callback when custom element is created ' +
38     'in HTML after registration of a custom element');
39
40
41 test(function() {
42     var doc = newHTMLDocument();
43     var proto = newHTMLElementPrototype();
44     var customElement = doc.createElement('x-c');
45
46     doc.body.appendChild(customElement);
47     doc.registerElement('x-c', {prototype: proto});
48     assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
49         'The custom element prototype is incorrect inside created callback');
50 }, 'Test custom element prototype inside created callback when custom element is created ' +
51     'via document.createElement() before registration of a custom element');
52
53
54 test(function() {
55     var doc = newHTMLDocument();
56     var proto = newHTMLElementPrototype();
57     doc.registerElement('x-d', {prototype: proto});
58
59     var customElement = doc.createElement('x-d');
60     doc.body.appendChild(customElement);
61     assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
62         'The custom element prototype is incorrect inside created callback');
63 }, 'Test custom element prototype inside created callback when custom element is created ' +
64     'via document.createElement() after registration of a custom element');
65
66
67 test(function() {
68     var doc = newHTMLDocument();
69     var proto = newHTMLElementPrototype();
70     var GeneratedConstructor = doc.registerElement('x-e', {prototype: proto});
71     var customElement = new GeneratedConstructor();
72
73     assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
74         'The custom element prototype is incorrect inside created callback');
75 }, 'Test custom element prototype inside created callback when custom element is created ' +
76     'via constructor returned by method registerElement');
77
78
79 testInIFrame('../../resources/x-element.html', function(doc) {
80     var proto = newHTMLElementPrototype();
81     doc.registerElement('x-element', {prototype: proto});
82     assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
83         'The custom element prototype is incorrect inside created callback');
84 }, 'Test custom element prototype inside created callback when custom element is created ' +
85     'by UA parser before registration of a custom element');
86 </script>
87 </body>
88 </html>