OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Test "defaultMuted" IDL, "muted" IDL and content attributes.</title> |
3 <head> | 3 <script src="../resources/testharness.js"></script> |
4 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 4 <script src="../resources/testharnessreport.js"></script> |
5 (Please avoid writing new tests using video-test.js) --> | 5 <script src="media-file.js"></script> |
6 <script src=video-test.js></script> | 6 <script> |
7 <script src=media-file.js></script> | 7 test(function() { |
8 <script> | 8 var video = document.createElement("video"); |
9 var index = 0; | 9 // Test that "defaultMuted" IDL attribute reflects "muted" content attribute
and |
| 10 // that "muted" IDL attribute is not affected by content attribute. |
| 11 assert_false(video.muted); |
| 12 assert_false(video.defaultMuted); |
| 13 video.setAttribute("muted", "muted"); |
| 14 assert_false(video.muted); |
| 15 assert_true(video.defaultMuted); |
| 16 video.removeAttribute("muted", "muted"); |
| 17 assert_false(video.muted); |
| 18 assert_false(video.defaultMuted); |
10 | 19 |
11 function testMuted(expectedMuted, expectedDefaultMuted) | 20 // Test that "muted" IDL attribute is not affected by "defaultMuted" IDL att
ribute. |
12 { | 21 video.defaultMuted = true; |
13 testExpected("video.muted", expectedMuted); | 22 assert_false(video.muted); |
14 testExpected("video.defaultMuted", expectedDefaultMuted); | 23 }, "Test 'defaultMuted' and 'muted' IDL attributes"); |
15 } | |
16 | 24 |
17 function test(defaultMuted) | 25 async_test(function(t) { |
18 { | 26 var video = document.createElement("video"); |
19 consoleWrite("<br><br><b>*** Test <em>" + (defaultMuted ? "with"
: "without") + "</em> 'muted' content attribute</b><br>"); | 27 // Set "muted" content attribute and it should set "muted" IDL attribute on
video load. |
| 28 // This is wrong per spec. See https://crbug.com/350303 for details. |
| 29 video.setAttribute("muted", "muted"); |
20 | 30 |
21 run("video = document.createElement('video')"); | 31 video.onloadedmetadata = t.step_func_done(function() { |
22 run("video.setAttribute('controls', 'controls')"); | 32 // "muted" IDL attribute should have been set. |
23 video.setAttribute('width', '300'); | 33 assert_true(video.muted); |
24 if (defaultMuted) | 34 }); |
25 run("video.setAttribute('muted', 'muted')"); | |
26 document.getElementById('parent').appendChild(video); | |
27 | 35 |
28 consoleWrite("<br>*** Test before setting src, IDL attribute sho
uld default to false"); | 36 video.src = findMediaFile("audio", "content/test"); |
29 testMuted(false, defaultMuted); | 37 }, "Test 'muted' content and IDL attributes on video load"); |
30 | 38 </script> |
31 var loadedmetadata = function(evt) | |
32 { | |
33 consoleWrite("<br>EVENT(" + evt.type + ")"); | |
34 | |
35 consoleWrite("<br>*** After setting url, content attribute s
hould have set IDL attribute"); | |
36 testMuted(defaultMuted, defaultMuted); | |
37 | |
38 consoleWrite("<br>*** Change 'defaultMuted', IDL attribute s
hould not change but content attribute should."); | |
39 var newDefaultMuted = !defaultMuted; | |
40 run("video.defaultMuted = " + newDefaultMuted); | |
41 testMuted(defaultMuted, newDefaultMuted); | |
42 testExpected("video.hasAttribute('muted')", newDefaultMuted)
; | |
43 | |
44 consoleWrite("<br>*** Change 'muted' IDL attribute, content
attribute should not change"); | |
45 run("video.muted = false"); | |
46 testMuted(false, newDefaultMuted); | |
47 testExpected("video.hasAttribute('muted')", newDefaultMuted)
; | |
48 | |
49 var action = defaultMuted ? "Remove" : "Add"; | |
50 consoleWrite("<br>*** " + action + " 'muted' content attribu
te, it should have no effect on IDL attribute"); | |
51 if (defaultMuted) | |
52 run("video.removeAttribute('muted')"); | |
53 else | |
54 run("video.setAttribute('muted', 'muted')"); | |
55 testMuted(false, video.hasAttribute('muted')); | |
56 | |
57 runNextTest(); | |
58 } | |
59 video.addEventListener('loadedmetadata', loadedmetadata); | |
60 video.src = findMediaFile("audio", "content/test"); | |
61 } | |
62 | |
63 function runNextTest() | |
64 { | |
65 if (video) { | |
66 video.parentNode.removeChild(video); | |
67 video = null; | |
68 } | |
69 | |
70 switch (++index) | |
71 { | |
72 case 1: | |
73 test(true); | |
74 break; | |
75 case 2: | |
76 test(false); | |
77 break; | |
78 case 3: | |
79 consoleWrite(""); | |
80 endTest(); | |
81 break; | |
82 } | |
83 } | |
84 | |
85 </script> | |
86 </head> | |
87 | |
88 <body onload="runNextTest()"> | |
89 <div id="parent"></div> | |
90 <p>Test 'muted' content attribute<p> | |
91 </body> | |
92 </html> | |
OLD | NEW |