summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/created-callback-element-prototype-test.html
blob: 188957c1ac0757565be3603ee7bacd401f1aeda5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<title>The custom element prototype must be set just prior to invoking created callback</title>
<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="The custom element prototype must be set just prior to invoking callback.">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#types-of-callbacks">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();

    doc.body.innerHTML = '<x-a></x-a>';
    doc.registerElement('x-a', {prototype: proto});
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'in HTML before registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();

    doc.registerElement('x-b', {prototype: proto});
    doc.body.innerHTML = '<x-b></x-b>';
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'in HTML after registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    var customElement = doc.createElement('x-c');

    doc.body.appendChild(customElement);
    doc.registerElement('x-c', {prototype: proto});
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'via document.createElement() before registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-d', {prototype: proto});

    var customElement = doc.createElement('x-d');
    doc.body.appendChild(customElement);
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'via document.createElement() after registration of a custom element');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    var GeneratedConstructor = doc.registerElement('x-e', {prototype: proto});
    var customElement = new GeneratedConstructor();

    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'via constructor returned by method registerElement');


testInIFrame('../../resources/x-element.html', function(doc) {
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-element', {prototype: proto});
    assert_equals(proto.createdCallbackThis.constructor.prototype, proto,
        'The custom element prototype is incorrect inside created callback');
}, 'Test custom element prototype inside created callback when custom element is created ' +
    'by UA parser before registration of a custom element');
</script>
</body>
</html>