summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/v0/instantiating/extensions-to-document-interface/created-callback-create-element-ns.html
blob: 7bf09601cb8d6e2e86c86a01a973d1cd01829aaa (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
<!DOCTYPE html>
<html>
<head>
<title>Document.createElementNS() must enqueue created callback for registered custom element type</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="Document.createElementNS() must enqueue created callback for registered custom element type">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#extensions-to-document-interface-to-instantiate">
<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();
    var name = 'x-a';

    doc.registerElement(name, {prototype: proto});
    var customElement = doc.createElementNS(HTML_NAMESPACE, name);
    assert_equals(proto.createdCallbackCalledCounter, 1,
        'Callback created should be enqueued by Document.createElementNS()');
}, 'Test Document.createElementNS() without typeExtension argument enqueues created callback');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    var name = 'x-b';

    doc.registerElement(name, {prototype: proto});
    var customElement = doc.createElementNS(HTML_NAMESPACE, name, name);
    assert_equals(proto.createdCallbackCalledCounter, 1,
        'Callback created should be enqueued by Document.createElementNS()');
}, 'Test Document.createElementNS() with typeExtension argument enqueues created callback');


test(function() {
    var doc = newHTMLDocument();
    var proto = newHTMLElementPrototype();
    var name = 'x-c';
    var customElement = doc.createElementNS(HTML_NAMESPACE, name);
    assert_equals(proto.createdCallbackCalledCounter, 0,
        'Document.createElementNS() should not enqueue created callback ' +
        'for unresolved custom element');

    doc.registerElement(name, {prototype: proto});
    assert_equals(proto.createdCallbackCalledCounter, 1,
        'Callback created should be called after custom element is registered');
}, 'Document.createElementNS() should not enqueue created callback ' +
    'for unresolved custom element');


test(function() {
    var doc = newHTMLDocument();
    HTML5_ELEMENTS.forEach(function(tagName) {
        var obj = doc.createElement(tagName);
        var name = 'x-d-' + tagName;
        var proto = newCustomElementPrototype(Object.create(obj.constructor.prototype));
        doc.registerElement(name, {prototype: proto, extends: tagName});
        var customElement = doc.createElementNS(HTML_NAMESPACE, tagName, name);

        assert_equals(proto.createdCallbackCalledCounter, 1,
            'Callback created should be enqueued by Document.createElementNS()');
    });
}, 'Test Document.createElementNS() enqueues created callback for custom elements ' +
    'that are extensions of HTML5 elements');
</script>
</body>
</html>