Skip to content

Commit 08e7b4e

Browse files
annevkzcorpan
authored andcommitted
HTML: make muted attribute no longer rely on non-existing element creation-time
For whatwg/html#12389.
1 parent 2827ad1 commit 08e7b4e

2 files changed

Lines changed: 56 additions & 10 deletions

File tree

css/selectors/media/sound-state.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,30 @@
4343
assert_equals(document.querySelector("video:muted"), video);
4444
assert_equals(document.querySelector("video:not(:muted)"), null);
4545
}, "Test :muted pseudo-class");
46+
47+
test((t) => {
48+
assert_implements(CSS.supports("selector(:muted)"), ":muted is not supported");
49+
50+
const video = document.createElement("video");
51+
document.body.appendChild(video);
52+
t.add_cleanup(() => video.remove());
53+
54+
assert_false(video.muted);
55+
assert_false(video.matches(":muted"));
56+
57+
video.setAttribute("muted", "");
58+
assert_true(video.muted);
59+
assert_true(video.matches(":muted"));
60+
61+
video.removeAttribute("muted");
62+
assert_false(video.muted);
63+
assert_false(video.matches(":muted"));
64+
65+
video.setAttribute("muted", "");
66+
assert_true(video.muted);
67+
video.muted = false;
68+
assert_false(video.muted);
69+
assert_false(video.matches(":muted"));
70+
}, "Test :muted matches .muted for content attribute default");
4671
</script>
4772
</body>

html/semantics/embedded-content/media-elements/user-interface/muted.html

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
}
2222
</script>
2323

24-
<!-- These tests are inside <audio>/<video> so that the steps for updating the
25-
muted IDL attribute cannot be delayed until the end tag is parsed. -->
24+
<!-- These tests are inside <audio>/<video> so that the parser-created
25+
elements are available for testing before the closing tag. -->
2626

2727
<audio id=a1>
2828
<script>
@@ -80,8 +80,8 @@
8080
</script>
8181
</video>
8282

83-
<!-- Negative test to ensure that the load algorithm does not update the
84-
muted IDL attribute to match the content attribute. -->
83+
<!-- Negative test to ensure that the load algorithm does not reset the
84+
muted state. -->
8585

8686
<video id=v3 muted></video>
8787
<script>
@@ -112,25 +112,22 @@
112112
test(function() {
113113
var m = document.createElement(tagName);
114114
m.setAttribute('muted', '');
115-
assert_false(m.muted);
115+
assert_true(m.muted);
116116
}, 'getting ' + tagName + '.muted with muted="" (script-created)');
117117

118118
test(function() {
119119
var m = document.createElement(tagName);
120120
m.setAttribute('muted', '');
121-
test_setting(m, false, true);
121+
test_setting(m, true, true);
122122
}, 'setting ' + tagName + '.muted with muted="" (script-created)');
123123

124-
// Spec bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=25153
125-
/*
126124
test(function() {
127125
var m = document.createElement(tagName);
128126
m.setAttribute('muted', '');
129127
m = m.cloneNode(false);
130128
assert_true(m.hasAttribute('muted'));
131-
assert_false(m.muted);
129+
assert_true(m.muted);
132130
}, 'getting ' + tagName + '.muted with muted="" (cloneNode-created)');
133-
*/
134131

135132
test(function() {
136133
var div = document.createElement('div');
@@ -165,5 +162,29 @@
165162
var c = m.cloneNode(true);
166163
assert_true(c.muted);
167164
}, 'cloning ' + tagName + ' propagates muted (innerHTML-created)');
165+
166+
test(function() {
167+
var m = document.createElement(tagName);
168+
assert_false(m.muted);
169+
m.setAttribute('muted', '');
170+
assert_true(m.muted);
171+
m.removeAttribute('muted');
172+
assert_false(m.muted);
173+
}, 'adding/removing muted attribute dynamically affects ' + tagName + '.muted');
174+
175+
test(function() {
176+
var m = document.createElement(tagName);
177+
m.muted = false;
178+
m.setAttribute('muted', '');
179+
assert_false(m.muted);
180+
}, 'adding muted attribute has no effect on ' + tagName + '.muted after setter');
181+
182+
test(function() {
183+
var m = document.createElement(tagName);
184+
m.setAttribute('muted', '');
185+
m.muted = true;
186+
m.removeAttribute('muted');
187+
assert_true(m.muted);
188+
}, 'removing muted attribute has no effect on ' + tagName + '.muted after setter');
168189
});
169190
</script>

0 commit comments

Comments
 (0)