Skip to content

Commit

Permalink
Test when the muted IDL attribute is updated from the content attribute
Browse files Browse the repository at this point in the history
Blink/WebKit has a bug here and fails the last two parser tests.
  • Loading branch information
foolip committed Mar 7, 2014
1 parent 5986cf1 commit 83fa234
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<title>muted</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<style>video { display: none; }</style>
<div id=log></div>

<!-- These tests are inside <video> so that the steps for updating the
muted IDL attribute cannot be delayed until </video>. -->

<video id=v1>
<script>
test(function() {
var v = document.getElementById('v1');
assert_false(v.muted);
}, 'muted for parser-created video');
</script>
</video>

<video id=v2 muted>
<script>
test(function() {
var v = document.getElementById('v2');
assert_true(v.muted);
}, 'muted for parser-created video with muted attribute');
</script>
</video>

<!-- Negative test to ensure that the load algorithm does not update the
muted IDL attribute to match the content attribute. -->

<video id=v3 muted></video>
<script>
async_test(function(t) {
var v = document.getElementById('v3');
assert_true(v.muted);
v.muted = false;
v.src = 'data:,'; // invokes load()
v.addEventListener('error', t.step_func(function() {
assert_false(v.muted);
t.done();
}));
}, 'muted for parser-created video with muted attribute after load');
</script>

<!-- Negative tests for script-created elements, where the muted content
attribute should have no effect. -->

<script>
test(function() {
var v = document.createElement('video');
assert_false(v.muted);
}, 'muted for script-created video');

test(function() {
var v = document.createElement('video');
v.setAttribute('muted', '');
assert_false(v.muted);

This comment has been minimized.

Copy link
@qjia7

qjia7 Mar 7, 2014

Since you have set muted attribute, here should be assert_true(v.muted) ?

This comment has been minimized.

Copy link
@foolip

foolip Mar 7, 2014

Author Owner

Per spec the muted attribute only has an effect if present when the element is created, which is only possible for parser-created elements. Note that Firefox and Opera 12.16 (Presto) gets this right, while Blink/WebKit does not.

This comment has been minimized.

Copy link
@qjia7

qjia7 Mar 10, 2014

Sorry, I'm still not very clear. I think the bellow scripts' function

  var v = document.createElement('video');
  v.setAttribute('muted', '');

is same with video id=v2 muted. However, the former you use assert_false to check. The latter you use assert_true to check. Why they are not consistent? Would you please point out where the spec shows that 'the muted attribute only has an effect if present when the element is created'.

Quote your words "The muted content attribute is reflected in the defaultMuted IDL attribute, the
muted IDL attribute can change independent of the content attribute." So, if muted attribute presents in the media element, v.defaultMuted should be true. But v.muted should be false before beginning to load resource. Therefore, the latter situation shoud use 'assert_false' to check?

This comment has been minimized.

Copy link
@foolip

foolip Mar 11, 2014

Author Owner

It's in http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#user-interface

"When a media element is created, if it has a muted attribute specified, the user agent must mute the media element's audio output, overriding any user preference."

When one creates an element using createElement, it doesn't have the muted attribute at that time, and there's nothing in the spec to set the muted IDL attribute when the muted content attribute is added/modified at any other time.

This is a bit weird, but it's very much intentional since scripts that want to mute can just set v.muted = true. Here's the original discussion which led to the current design: https://www.w3.org/Bugs/Public/show_bug.cgi?id=10419

If you want to simplify the spec by letting any setting of the muted content attribute set the muted IDL attribute, please file a spec bug. FWIW, this would be easier to implement than the current spec, and I wouldn't be opposed.

This comment has been minimized.

Copy link
@qjia7

qjia7 Mar 12, 2014

Hi, @foolip Thanks for your reply. I have understood it now. For 'When a media element is created, if it has a muted attribute specified, the user agent must mute the media element's audio output, overriding any user preference', I don't know if I can understand it like this: 'the user agent must mute the media element's audio output' will results in v.muted = true. But v.muted = true would happen in any time before successfully loading audio/video source. So we don't have to set v.muted=true immediately as long as we can ensure that when beginning to load audio/video source, v.muted is equal to true. If the hypothesis is true, the current design of Webkit/blink is correct. So some test cases such as 'muted for parser-created video with muted attribute' and 'muted for script-created video with muted attribute' are meaningless.

This comment has been minimized.

Copy link
@foolip

foolip Mar 12, 2014

Author Owner

I'm pretty sure that's not what's intended, and it isn't what Presto and Gecko have implemented. I've filed a bug for the spec to be more explicit: https://www.w3.org/Bugs/Public/show_bug.cgi?id=25019

}, 'muted for script-created video with muted attribute');
</script>

0 comments on commit 83fa234

Please sign in to comment.