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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<!DOCTYPE html>
<title>Custom Elements: CEReactions on HTMLSourceElement interface</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<meta name="assert" content="src, type, srcset, sizes, media of
HTMLSourceElement interface must have CEReactions">
<meta name="help" content="https://html.spec.whatwg.org/#the-source-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/custom-elements-helpers.js"></script>
<script src="../resources/reactions.js"></script>
<video controls id='video' width='5' height='5'></video>
<picture id='pic'>
<img src='/images/green-1x1.png'>
</picture>
<body>
<script>
function getParentElement(id) {
let element = document.getElementById(id);
return element;
}
testReflectAttributeWithParentNode(
'src', 'src', '/media/video.ogv',
'/media/white.mp4', 'src on HTMLSourceElement', 'source',
() => getParentElement('video'), HTMLSourceElement
);
testReflectAttributeWithDependentAttributes(
'type', 'type', 'video/mp4; codecs="mp4v.20.240, mp4a.40.2"',
'video/mp4; codecs="mp4v.20.8, mp4a.40.2"', 'type on HTMLSourceElement',
'source',
() => getParentElement('video'),
instance => instance.setAttribute('src', '/media/white.mp4'), HTMLSourceElement
);
function testReflectAttributeWithContentValuesAndParentNode(
jsAttributeName, contentAttributeName, validValue1,
contentValue1, validValue2, contentValue2,
name, elementName, getParentElement,
interfaceName) {
let parentElement = getParentElement();
test(() => {
let element = define_build_in_custom_element(
[contentAttributeName], interfaceName, elementName
);
let instance = document.createElement(elementName, { is: element.name });
assert_array_equals(element.takeLog().types(), ['constructed']);
// source element as a child of a picture element, before the img element
parentElement.prepend(instance);
assert_array_equals(element.takeLog().types(), ['connected']);
instance[jsAttributeName] = validValue1;
let logEntries = element.takeLog();
assert_array_equals(logEntries.types(), ['attributeChanged']);
assert_attribute_log_entry(
logEntries.last(),
{ name: contentAttributeName, oldValue: null,
newValue: contentValue1, namespace: null
}
);
}, name + ' must enqueue an attributeChanged reaction when adding a new attribute');
test(() => {
let element = define_build_in_custom_element(
[contentAttributeName], interfaceName, elementName
);
let instance = document.createElement(elementName, { is: element.name });
// source element as a child of a picture element, before the img element
parentElement.prepend(instance);
assert_array_equals(element.takeLog().types(), ['constructed', 'connected']);
instance[jsAttributeName] = validValue1;
assert_array_equals(element.takeLog().types(), ['attributeChanged']);
instance[jsAttributeName] = validValue2;
let logEntries = element.takeLog();
assert_array_equals(logEntries.types(), ['attributeChanged']);
assert_attribute_log_entry(
logEntries.last(),
{ name: contentAttributeName, oldValue: contentValue1,
newValue: contentValue2, namespace: null
}
);
}, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
}
function testReflectAttributeWithParentNode(
jsAttributeName, contentAttributeName, validValue1,
validValue2, name, elementName,
getParentElement, interfaceName) {
testReflectAttributeWithContentValuesAndParentNode(
jsAttributeName, contentAttributeName, validValue1,
validValue1, validValue2, validValue2,
name, elementName, getParentElement,
interfaceName
);
}
function testReflectAttributeWithContentValuesAndDependentAttributes(
jsAttributeName, contentAttributeName, validValue1,
contentValue1, validValue2, contentValue2,
name, elementName, getParentElement,
setAttributes, interfaceName) {
let parentElement = getParentElement();
test(() => {
let element = define_build_in_custom_element(
[contentAttributeName], interfaceName, elementName
);
let instance = document.createElement(elementName, { is: element.name });
assert_array_equals(element.takeLog().types(), ['constructed']);
// source element as a child of a picture element, before the img element
parentElement.prepend(instance);
assert_array_equals(element.takeLog().types(), ['connected']);
setAttributes(instance);
instance[jsAttributeName] = validValue1;
let logEntries = element.takeLog();
assert_array_equals(logEntries.types(), ['attributeChanged']);
assert_attribute_log_entry(
logEntries.last(),
{ name: contentAttributeName, oldValue: null,
newValue: contentValue1, namespace: null
}
);
}, name + ' must enqueue an attributeChanged reaction when adding a new attribute');
test(() => {
let element = define_build_in_custom_element(
[contentAttributeName], interfaceName, elementName
);
let instance = document.createElement(elementName, { is: element.name });
// source element as a child of a picture element, before the img element
parentElement.prepend(instance);
setAttributes(instance);
instance[jsAttributeName] = validValue1;
assert_array_equals(
element.takeLog().types(),
['constructed', 'connected', 'attributeChanged']
);
instance[jsAttributeName] = validValue2;
let logEntries = element.takeLog();
assert_array_equals(logEntries.types(), ['attributeChanged']);
assert_attribute_log_entry(
logEntries.last(),
{ name: contentAttributeName, oldValue: contentValue1,
newValue: contentValue2, namespace: null
}
);
}, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
}
function testReflectAttributeWithDependentAttributes(
jsAttributeName, contentAttributeName, validValue1,
validValue2, name, elementName,
getParentElement, setAttributes, interfaceName) {
testReflectAttributeWithContentValuesAndDependentAttributes(
jsAttributeName, contentAttributeName, validValue1,
validValue1, validValue2, validValue2,
name, elementName, getParentElement,
setAttributes, interfaceName);
}
testReflectAttributeWithParentNode(
'srcset', 'srcset', '/images/green.png',
'/images/green-1x1.png', 'srcset on HTMLSourceElement', 'source',
() => getParentElement('pic'), HTMLSourceElement
);
testReflectAttributeWithDependentAttributes(
'sizes', 'sizes', '(max-width: 32px) 28px',
'(max-width: 48px) 44px', 'sizes on HTMLSourceElement', 'source',
() => getParentElement('pic'),
instance => instance.setAttribute('srcset', '/images/green.png 3x'),
HTMLSourceElement
);
testReflectAttributeWithDependentAttributes(
'media', 'media', '(max-width: 7px)',
'(max-width: 9px)', 'media on HTMLSourceElement', 'source',
() => getParentElement('pic'),
instance => instance.setAttribute('srcset', '/images/green.png 3x'),
HTMLSourceElement
);
</script>
</body>
|