summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/v0/creating-and-passing-registries/share-registry-import-document.html
blob: 251e4f123ee416f50c884db2513edb0bcacd42c9 (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
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>When creating an import, use the registry of the master document</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="When creating an import, use the registry of the master document.">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#creating-and-passing-registries">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../testcommon.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var test1 = async_test('Registry of the imported document should be shared with master document. ' +
    'Import is asynchronous');
test1.step(function() {
    var iframe = newIFrame('../resources/import-master-async.html');
    document.body.appendChild(iframe);
    iframe.onload = test1.step_func(function() {
        var doc = iframe.contentDocument;
        var link = doc.querySelector('link[rel=import]');
        link.onload = test1.step_func(function() {
            try {
                var doc2 = link.import;
                var name = 'x-frame';
                doc.registerElement(name);
                assert_throws(
                    'NotSupportedError',
                    function() { doc2.registerElement(name); },
                    'Registering a custom element type name that is already registered in a shared ' +
                        'registry should throw an exception');
                test1.done();
            } finally {
                iframe.remove();
            }
        });
    });
});


var test2 = async_test('Registry of the master document should be shared with imported document. ' +
    'Import is asynchronous');
test2.step(function() {
    var iframe = newIFrame('../resources/import-master-async.html');
    document.body.appendChild(iframe);
    iframe.onload = test2.step_func(function() {
        var doc = iframe.contentDocument;
        var link = doc.querySelector('link[rel=import]');
        link.onload = test2.step_func(function() {
            try {
                var doc2 = link.import;
                var name = 'x-frame';
                doc2.registerElement(name);
                assert_throws(
                    'NotSupportedError',
                    function() { doc.registerElement(name); },
                    'Registering a custom element type name that is already registered in a shared ' +
                        'registry should throw an exception');
                test2.done();
            } finally {
                iframe.remove();
            }
        });
    });
});


testInIFrame('../resources/import-master.html', function(doc) {
    var link = doc.querySelector('link[rel=import]');
    var doc2 = link.import;
    var name = 'x-frame';
    doc.registerElement(name);
    assert_throws(
        'NotSupportedError',
        function() { doc2.registerElement(name); },
        'Registering a custom element type name that is already registered in a shared ' +
            'registry should throw an exception');
}, 'Registry of the imported document should be shared with master document. Import is syncronous');


testInIFrame('../resources/import-master.html', function(doc) {
    var link = doc.querySelector('link[rel=import]');
    var doc2 = link.import;
    var name = 'x-frame';
    doc2.registerElement(name);
    assert_throws(
        'NotSupportedError',
        function() { doc.registerElement(name); },
        'Registering a custom element type name that is already registered in a shared ' +
            'registry should throw an exception');
}, 'Registry of the master document should be shared with imported document. Import is syncronous');
</script>
</body>
</html>