931c0a2fff5ad92cae351216e4ae85c4039629b4
[WebKit-https.git] / LayoutTests / media / video-defaultmuted.html
1 <!doctype html>
2 <html>
3     <head>
4         <script src=video-test.js></script>
5         <script src=media-file.js></script>
6         <script>
7             var index = 0;
8
9             function testMuted(expectedMuted, expectedDefaultMuted)
10             {
11                 testExpected("video.muted", expectedMuted);
12                 testExpected("video.defaultMuted", expectedDefaultMuted);
13             }
14
15             function test(defaultMuted)
16             {
17                 consoleWrite("<br><br><b>*** Test <em>" + (defaultMuted ? "with" : "without") + "</em> 'muted' content attribute</b><br>");
18
19                 run("video = document.createElement('video')");
20                 run("video.setAttribute('controls', 'controls')");
21                 video.setAttribute('width', '300');
22                 if (defaultMuted)
23                     run("video.setAttribute('muted', 'muted')");
24                 document.getElementById('parent').appendChild(video);
25
26                 consoleWrite("<br>*** Test before setting src, IDL attribute should default to false");
27                 testMuted(false, defaultMuted);
28
29                 var loadedmetadata = function(evt)
30                 {
31                     consoleWrite("<br>EVENT(" + evt.type + ")");
32
33                     consoleWrite("<br>*** After setting url, content attribute should have set IDL attribute");
34                     testMuted(defaultMuted, defaultMuted);
35
36                     consoleWrite("<br>*** Change 'defaultMuted', IDL attribute should not change but content attribute should.");
37                     var newDefaultMuted = !defaultMuted;
38                     run("video.defaultMuted = " + newDefaultMuted);
39                     testMuted(defaultMuted, newDefaultMuted);
40                     testExpected("video.hasAttribute('muted')", newDefaultMuted);
41     
42                     consoleWrite("<br>*** Change 'muted' IDL attribute, content attribute should not change");
43                     run("video.muted = false");
44                     testMuted(false, newDefaultMuted);
45                     testExpected("video.hasAttribute('muted')", newDefaultMuted);
46
47                     var action = defaultMuted ? "Remove" : "Add";
48                     consoleWrite("<br>*** " + action + " 'muted' content attribute, it should have no effect on IDL attribute");
49                     if (defaultMuted)
50                         run("video.removeAttribute('muted')");
51                     else
52                         run("video.setAttribute('muted', 'muted')");
53                     testMuted(false, video.hasAttribute('muted'));
54
55                     runNextTest();
56                 }
57                 video.addEventListener('loadedmetadata', loadedmetadata);
58                 video.src = findMediaFile("audio", "content/test");
59             }
60
61             function runNextTest()
62             {
63                 if (video) {
64                     video.parentNode.removeChild(video);
65                     video = null;
66                 }
67
68                 switch (++index)
69                 {
70                 case 1:
71                     test(true);
72                     break;
73                 case 2:
74                     test(false);
75                     break;
76                 case 3:
77                     consoleWrite("");
78                     endTest();
79                     break;
80                 }
81             }
82
83         </script>
84     </head>
85
86     <body onload="runNextTest()">
87         <div id="parent"></div>
88         <p>Test 'muted' content attribute<p>
89     </body>
90 </html>