blob: 5da6271cab35a75cff92943b354d5f8da8a2fc17 [file] [log] [blame]
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +00001<!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
jer.noble@apple.com02993042014-01-28 17:49:58 +000015 function testAddedToDocument()
16 {
17 consoleWrite("<br><br><em>*** Test that the 'muted' content attribute reflects the 'muted' IDL attribute before the element"
18 + " is added to the document, and does not reflect after</em></br>");
19
20 run("video = document.createElement('video')");
21 run("video.setAttribute('controls', 'controls')");
22 video.setAttribute('width', '300');
23 testMuted(false, false);
24
25 consoleWrite("<br>*** Change 'muted' content attribute, IDL attribute should change.");
26 run("video.setAttribute('muted', 'muted')");
27 testMuted(true, true);
28 run("document.getElementById('parent').appendChild(video)");
29
30 consoleWrite("<br>*** Change 'muted' content attribute, IDL attribute should not change.");
31 video.removeAttribute('muted');
32 testMuted(true, false);
33
34 runNextTest();
35 }
36
37 function testExplicitlySetBeforeAddedToDocument()
38 {
39 consoleWrite("<br><br><em>*** Test that setting the 'muted' IDL attribute means that changes to "
40 + "the 'muted' content attribute are no longer reflected.</em></br>");
41
42 run("video = document.createElement('video')");
43 run("video.setAttribute('controls', 'controls')");
44 video.setAttribute('width', '300');
45 testMuted(false, false);
46
47 consoleWrite("<br>*** Change 'muted' content attribute, IDL attribute should change.");
48 run("video.setAttribute('muted', 'muted')");
49 testMuted(true, true);
50
51 consoleWrite("<br>*** Change 'muted' IDL attribute, then the content attribute. IDL attribute should not change.");
52 run("video.muted = true");
53 video.removeAttribute('muted');
54 testMuted(true, false);
55
56 runNextTest();
57 }
58
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +000059 function test(defaultMuted)
60 {
jer.noble@apple.com02993042014-01-28 17:49:58 +000061 consoleWrite("<br><br><em>*** Test <em>" + (defaultMuted ? "with" : "without") + "</em> 'muted' content attribute</em><br>");
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +000062
63 run("video = document.createElement('video')");
64 run("video.setAttribute('controls', 'controls')");
65 video.setAttribute('width', '300');
66 if (defaultMuted)
67 run("video.setAttribute('muted', 'muted')");
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +000068
jer.noble@apple.com02993042014-01-28 17:49:58 +000069 consoleWrite("<br>*** Test before setting src, muted IDL attribute should default to muted content attribute");
70 testMuted(defaultMuted, defaultMuted);
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +000071
72 var loadedmetadata = function(evt)
73 {
74 consoleWrite("<br>EVENT(" + evt.type + ")");
75
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +000076 consoleWrite("<br>*** Change 'defaultMuted', IDL attribute should not change but content attribute should.");
77 var newDefaultMuted = !defaultMuted;
78 run("video.defaultMuted = " + newDefaultMuted);
79 testMuted(defaultMuted, newDefaultMuted);
80 testExpected("video.hasAttribute('muted')", newDefaultMuted);
jer.noble@apple.com02993042014-01-28 17:49:58 +000081
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +000082 consoleWrite("<br>*** Change 'muted' IDL attribute, content attribute should not change");
83 run("video.muted = false");
84 testMuted(false, newDefaultMuted);
85 testExpected("video.hasAttribute('muted')", newDefaultMuted);
86
87 var action = defaultMuted ? "Remove" : "Add";
88 consoleWrite("<br>*** " + action + " 'muted' content attribute, it should have no effect on IDL attribute");
89 if (defaultMuted)
90 run("video.removeAttribute('muted')");
91 else
92 run("video.setAttribute('muted', 'muted')");
93 testMuted(false, video.hasAttribute('muted'));
94
95 runNextTest();
96 }
97 video.addEventListener('loadedmetadata', loadedmetadata);
98 video.src = findMediaFile("audio", "content/test");
99 }
100
101 function runNextTest()
102 {
jer.noble@apple.com02993042014-01-28 17:49:58 +0000103 if (video && video.parentNode) {
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +0000104 video.parentNode.removeChild(video);
105 video = null;
106 }
107
108 switch (++index)
109 {
110 case 1:
111 test(true);
112 break;
113 case 2:
114 test(false);
115 break;
116 case 3:
jer.noble@apple.com02993042014-01-28 17:49:58 +0000117 testAddedToDocument();
118 break;
119 case 4:
120 testExplicitlySetBeforeAddedToDocument();
121 break;
122 case 5:
eric.carlson@apple.comcced8be2011-09-01 18:10:51 +0000123 consoleWrite("");
124 endTest();
125 break;
126 }
127 }
128
129 </script>
130 </head>
131
132 <body onload="runNextTest()">
133 <div id="parent"></div>
134 <p>Test 'muted' content attribute<p>
135 </body>
136</html>