summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/detached-callback-with-browsing-context-test.html
blob: 31b06a9079cc00d50b8bd12891388e52050040d3 (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
<!DOCTYPE html>
<html>
<head>
<title>Detached callback of a custom element should be called if document has browsing context</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
<meta name="assert" content="detached callback ... must be enqueued whenever custom element is removed from the document and this document has a browsing context.">
<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>
testInIFrame('../../resources/x-element.html', function(doc) {
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-element', {prototype: proto});
    var customElement = doc.querySelector('#x-element');
    doc.body.removeChild(customElement);
    assert_equals(proto.detachedCallbackCalledCounter, 1, 'Callback detached should be ' +
        'called if custom element is removed from the document with browsing context');
}, 'Test detached callback is called if custom element is removed by method removeChild() ' +
    'from document with browsing context');


testInIFrame('../../resources/blank.html', function(doc) {
    doc.body.innerHTML = '<div id="x-a-parent"><x-a id="x-a"></x-a></div>';
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-a', {prototype: proto});
    var div = doc.querySelector('#x-a-parent');
    doc.body.removeChild(div);
    assert_equals(proto.detachedCallbackCalledCounter, 1, 'Callback detached should be ' +
        'called if custom element is removed from the document with browsing context');
}, 'Test detached callback is called if ancestor node of custom element ' +
    'is removed by method removeChild() from document with browsing context');


testInIFrame('../../resources/x-element.html', function(doc) {
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-element', {prototype: proto});
    var customElement = doc.querySelector('#x-element');
    var div = doc.createElement('div');
    doc.body.replaceChild(div, customElement);
    assert_equals(proto.detachedCallbackCalledCounter, 1, 'Callback detached should be ' +
        'called if custom element is removed from the document with browsing context');
}, 'Test detached callback is called if custom element is removed by method replaceChild() ' +
    'from document with browsing context');


testInIFrame('../../resources/blank.html', function(doc) {
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-b', {prototype: proto});
    doc.body.innerHTML = '<div id="x-b-parent"><x-b id="x-b"></x-b></div>';
    var parent = doc.querySelector('#x-b-parent');
    var replacement = doc.createElement('div');
    doc.body.replaceChild(replacement, parent);
    assert_equals(proto.detachedCallbackCalledCounter, 1, 'Callback detached should be ' +
        'called if custom element is removed from the document with browsing context');
}, 'Test detached callback is called if ancestor node of custom element ' +
    'is removed by method replaceChild() from document with browsing context');


testInIFrame('../../resources/x-element.html', function(doc) {
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-element', {prototype: proto});
    doc.body.innerHTML = '';
    assert_equals(proto.detachedCallbackCalledCounter, 1, 'Callback detached should be ' +
        'called if custom element is removed from the document with browsing context');
}, 'Test detached callback is called after changing custom element direct parent ' +
    'innerHTML property in the document with browsing context');


testInIFrame('../../resources/blank.html', function(doc) {
    doc.body.innerHTML = '<div><x-c></x-c></div>';
    var proto = newHTMLElementPrototype();
    doc.registerElement('x-c', {prototype: proto});
    doc.body.innerHTML = '';
    assert_equals(proto.detachedCallbackCalledCounter, 1, 'Callback detached should be ' +
        'called if custom element is removed from the document with browsing context');
}, 'Test detached callback is called after changing custom element ancestor ' +
    'innerHTML property in the document with browsing context');
</script>
</body>
</html>