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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<!DOCTYPE html>
<html>
<head>
<title>Attached callback of a custom element should be called </title>
<meta name="timeout" content="long">
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="attached callback ... must be enqueued whenever custom element is inserted into a 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>
test(function() {
var doc = newHTMLDocument();
var proto = newHTMLElementPrototype();
var GeneratedConstructor = doc.registerElement('x-a', {prototype: proto});
var customElement = new GeneratedConstructor();
assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached ' +
'should not be called in documents that do not have a browsing context');
}, 'Test attached callback if custom element is instantiated via constructor. ' +
'Document has no browsing context');
test(function() {
var doc = newHTMLDocument();
var proto = newHTMLElementPrototype();
doc.registerElement('x-b', {prototype: proto});
doc.body.innerHTML = '<x-b></x-b>';
assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached ' +
'should not be called in documents that do not have a browsing context');
}, 'Test attached callback if custom element is created via innerHTML property. ' +
'Document has no browsing context');
test(function() {
var doc = newHTMLDocument();
doc.body.innerHTML = '<x-c></x-c>';
var proto = newHTMLElementPrototype();
doc.registerElement('x-c', {prototype: proto});
assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached ' +
'should not be called in documents that do not have a browsing context');
}, 'Test attached callback if custom element is created via innerHTML property before ' +
'registration. Document has no browsing context');
test(function() {
var doc = newHTMLDocument();
doc.body.innerHTML = '<x-d id="x-d"></x-d>';
var customElement = doc.querySelector('#x-d');
var proto = newHTMLElementPrototype();
var GeneratedConstructor = doc.registerElement('x-d', {prototype: proto});
customElement.constructor.prototype = proto;
assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached should ' +
'not be called for unregistered custom element in document without browsing context');
}, 'Test attached callback if custom element is unregistered');
testInIFrame('../../resources/x-element.html', function(doc) {
var proto = newHTMLElementPrototype();
doc.registerElement('x-element', {prototype: proto});
assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should be ' +
'called in documents with browsing context');
}, 'Test attached callback. Document has browsing context');
testInIFrame('../../resources/blank.html', function(doc) {
var proto = newHTMLElementPrototype();
doc.registerElement('x-element', {prototype: proto});
var x = doc.createElement('x-element');
assert_equals(proto.attachedCallbackCalledCounter, 0, 'Callback attached should not ' +
'be called before element is added to document with browsing context');
doc.body.appendChild(x);
assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should be called ' +
'in documents with browsing context');
}, 'Test attached callback. Registered element is created via document.createElement(). ' +
'Document has browsing context');
testInIFrame('../../resources/blank.html', function(doc) {
var x = doc.createElement('x-element');
doc.body.appendChild(x);
var proto = newHTMLElementPrototype();
doc.registerElement('x-element', {prototype: proto});
assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should ' +
'be called in documents with browsing context');
}, 'Test attached callback. Unregistered element is created via document.createElement(). ' +
'Document has browsing context');
testInIFrame('../../resources/blank.html', function(doc) {
var proto = newHTMLElementPrototype();
doc.registerElement('x-element', {prototype: proto});
doc.body.innerHTML = '<x-element></x-element>';
assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should ' +
'be called in documents with browsing context');
}, 'Test attached callback. Registered element is created via innerHTML property. ' +
'Document has browsing context');
testInIFrame('../../resources/blank.html', function(doc) {
doc.body.innerHTML = '<x-element></x-element>';
var proto = newHTMLElementPrototype();
doc.registerElement('x-element', {prototype: proto});
assert_equals(proto.attachedCallbackCalledCounter, 1, 'Callback attached should ' +
'be called in documents with browsing context');
}, 'Test attached callback. Unresolved element is created via innerHTML property. ' +
'Document has browsing context');
</script>
</body>
</html>
|