summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/v0/instantiating/prototype-is-interface-prototype-object.html
blob: ad7f454f50c071b8234a85b8143f05400d8d0c01 (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
<!DOCTYPE html>
<html>
<head>
<title>If prototype is already an interface prototype object, Document.registerElement() throws a NotSupportedError</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="If PROTOTYPE is already an interface prototype object for any interface object, throw a NotSupportedError and stop">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#instantiating-custom-elements">
<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();
    HTML5_ELEMENTS.forEach(function(tagName) {
        var obj = doc.createElement(tagName);
        var name = 'x-a-' + tagName;
        assert_throws('NotSupportedError', function() {
            doc.registerElement(name, {prototype: obj.constructor.prototype});
        }, 'Exception should be thrown in case of attempt to register element ' +
            'if prototype is already an interface prototype object (' + name + ')');
    });
}, 'Test Document.registerElement() throws NotSupportedError ' +
    'if prototype is already an interface prototype object');


test(function() {
    var doc = newHTMLDocument();
    var proto = Object.create(HTMLElement.prototype);
    doc.registerElement('x-b', {
        prototype: proto
    });
    assert_throws('NotSupportedError', function() {
        doc.registerElement('x-b', {
            prototype: proto
        });
    }, 'Exception should be thrown if registring custom element type with already used prototype');
}, 'Test Document.registerElement() throws NotSupportedError ' +
    'if prototype is already used for another custom element type');
</script>
</body>
</html>