OLD | NEW |
---|---|
(Empty) | |
1 <video autoplay controls></video> | |
2 <script src=media-file.js></script> | |
3 <script src=video-test.js></script> | |
4 <body> | |
5 <pre> | |
6 Check if the autoplay gesture override experiment works. There are a lot | |
7 of config options, so this test just runs all of them. | |
8 | |
9 The "results" table contains one row per config tested. | |
10 == Test Inputs == | |
11 # - config number, in case you'd like to run just one. | |
12 Flags - autoplay experiment setting being tested. | |
13 a - "foraudio" | |
14 v - "forvideo" | |
15 M - "ifmuted" | |
16 p - "playmuted" | |
17 For example, EM means "enabled-ifmuted". | |
18 This test does not check -ifmobile since that check always | |
19 fails outside of android. | |
20 Type - audio or video element? | |
21 audio - <audio> | |
22 video - <video> | |
23 Play w/- how is play requested? | |
24 none - play is not requested. | |
25 attr - autoplay attribute is set on the element. | |
26 play() - play() called after media is ready to play. | |
27 Mute - how is media muted? | |
philipj_slow
2015/09/04 09:24:27
This really amounts to testing for bugs in our mut
liberato (no reviews please)
2015/09/08 21:58:01
gladly removed, this test is too big. done. (exce
philipj_slow
2015/09/10 09:58:59
Yay :)
| |
28 none - media is not muted. | |
29 attr - muted attribute is set on the element. | |
30 js - muted property is set after media is ready to play. | |
31 | |
32 == Test Outputs == | |
33 Played? - did playback start by the conclusion of the test? | |
34 Muted? - was the media muted? If the media didn't play, then this is | |
35 reported as "-". | |
36 | |
37 </pre> | |
38 <table id="results"> | |
39 <tr> | |
40 <td>#</td> | |
41 <td>Flags</td> | |
42 <td>Type</td> | |
43 <td>Play w/</td> | |
44 <td>Mute</td> | |
45 <td>Played?</td> | |
46 <td>Muted?</td> | |
47 </tr> | |
48 </table> | |
49 </body> | |
50 | |
51 <script> | |
52 | |
53 // Starting configuration number. This should be zero normally. | |
54 var configNumber = 0; | |
55 | |
56 var mediaFile = findMediaFile("video", "content/test"); | |
57 var onscreenParent = document.createElement("div"); | |
58 document.body.insertBefore(onscreenParent, document.body.firstChild); | |
59 | |
60 function didPlaybackStart(video) | |
61 { | |
62 // We say that the video started if it's not paused or if it played and | |
63 // already ended. | |
64 return !video.paused || video.ended; | |
philipj_slow
2015/09/04 09:24:26
Same video.played.length test can be used here.
liberato (no reviews please)
2015/09/08 21:58:01
Always returned false, so i kept it this way.
| |
65 } | |
66 | |
67 function addResultsRow(spec) | |
68 { | |
69 // Add a row to the results table. | |
70 var row = document.getElementById("results").insertRow(-1); | |
philipj_slow
2015/09/04 09:24:27
Since you're always appending rows and cells and t
liberato (no reviews please)
2015/09/08 21:58:01
neat. i thought that chrome prepended by default.
| |
71 var td = row.insertCell(0); | |
72 | |
73 // Add experiment number | |
74 row.insertCell(-1).innerText = (""+spec["experimentNumber"]); | |
philipj_slow
2015/09/04 09:24:26
You can always replace spec["foo"] with spec.foo.
liberato (no reviews please)
2015/09/08 21:58:01
Done.
| |
75 | |
76 // Process experiment type specially. | |
77 var type = spec["experimentType"]; | |
78 var smallType = ""; | |
79 smallType += (type.indexOf("-forvideo")>-1)?"v":""; | |
80 smallType += (type.indexOf("-foraudio")>-1)?"a":""; | |
81 smallType += (type.indexOf("-ifmuted")>-1)?"M":""; | |
82 smallType += (type.indexOf("-playmuted")>-1)?"p":""; | |
83 row.insertCell(-1).innerText = smallType; | |
84 | |
85 // Add remaining fields. | |
86 var fields = [ "elementType", "autoplayType", "mutedType", "played", | |
87 "muted"]; | |
88 for(idx in fields) | |
89 row.insertCell(-1).innerText = spec[fields[idx]].substring(0,7); | |
90 } | |
91 | |
92 function configureVideoViaScript(element, spec) | |
93 { | |
94 if (spec.mutedType == "js") | |
95 element.muted = true; | |
96 if(spec.autoplayType == "play()") | |
97 element.play(); | |
98 } | |
99 | |
100 function queueNextExperiment() | |
101 { | |
102 // Start the next config, but let the event queue drain. | |
103 setTimeout(runNextConfig, 0); | |
104 } | |
105 | |
106 function checkElementStatus(element) | |
107 { | |
108 // Update the spec with the results. | |
109 var didStart = didPlaybackStart(element); | |
110 element.spec.played = didStart ? "played" : "no"; | |
111 element.spec.muted = didStart ? (element.muted ? "muted" : "unmuted") : "-"; | |
112 | |
113 addResultsRow(element.spec); | |
114 element.parentElement.removeChild(element); | |
philipj_slow
2015/09/04 09:24:26
Can use element.remove()
liberato (no reviews please)
2015/09/08 21:58:01
Done.
| |
115 | |
116 queueNextExperiment(); | |
117 } | |
118 | |
119 function runOneConfig(spec) | |
120 { | |
121 internals.settings.setAutoplayExperimentMode(spec.experimentType); | |
122 | |
123 // Create, configure, and attach a media element. | |
124 var element = document.createElement(spec.elementType); | |
125 | |
126 onscreenParent.appendChild(element); | |
127 | |
128 // Set any attributes before canPlayThrough. | |
129 if (spec.mutedType == "attr") | |
130 element.setAttribute("muted", "true"); | |
philipj_slow
2015/09/04 09:24:27
element.muted = true and element.autoplay = true b
liberato (no reviews please)
2015/09/08 21:58:01
Done.
| |
131 if (spec.autoplayType == "attr") | |
132 element.setAttribute("autoplay", "true"); | |
133 | |
134 // Record the spec in the element, so that we can display the | |
135 // results later. | |
136 element.spec = spec; | |
137 | |
138 // Wait for canplaythrough before continuing, so that the media | |
139 // might actually be playing. | |
140 element.addEventListener("canplaythrough", function() | |
141 { | |
142 // Now that we can play, if we're supposed to play / mute via js do so. | |
143 configureVideoViaScript(element, spec); | |
144 | |
145 // Record the results. | |
146 checkElementStatus(element); | |
147 }); | |
148 | |
149 // Set the source, which will eventually lead to canPlayThrough. | |
150 element.src=mediaFile; | |
philipj_slow
2015/09/04 09:24:26
Missing whitespace
liberato (no reviews please)
2015/09/08 21:58:01
this was the original, just-once was the copy...
| |
151 } | |
152 | |
153 var experimentTypes = [ | |
154 "none", | |
155 "enabled-forvideo", | |
philipj_slow
2015/09/04 09:24:26
Is it possible to test -ifmobile?
liberato (no reviews please)
2015/09/08 21:58:01
that's cool. it seems that it now is possible. w
| |
156 "enabled-forvideo-ifmuted", | |
157 "enabled-forvideo-playmuted", | |
158 "enabled-foraudio", | |
159 ]; | |
160 var elementTypes = ["video", "audio"]; | |
161 var autoplayTypes = ["none", "attr", "play()"]; | |
162 var mutedTypes = ["none", "attr", "js"]; | |
163 | |
164 function runNextConfig() | |
165 { | |
166 // Convert configNumber into a spec, and run it. | |
167 var exp = configNumber; | |
168 | |
169 // Convert this experiment number into settings. | |
170 var spec = {}; | |
171 spec.elementType = elementTypes[exp % elementTypes.length]; | |
172 exp = Math.floor(exp / elementTypes.length); | |
173 spec.experimentType = experimentTypes[exp % experimentTypes.length]; | |
174 exp = Math.floor(exp / experimentTypes.length); | |
175 spec.autoplayType = autoplayTypes[exp % autoplayTypes.length]; | |
176 exp = Math.floor(exp / autoplayTypes.length); | |
177 spec.mutedType = mutedTypes[exp % mutedTypes.length]; | |
178 exp = Math.floor(exp / mutedTypes.length); | |
179 spec.experimentNumber = configNumber; | |
180 | |
181 // exp>0 here indicates that we've wrapped around. | |
182 if (exp > 0) { | |
183 endTest(); | |
184 } | |
185 | |
186 configNumber++; | |
187 | |
188 // To keep the test fast, skip a few combinations. | |
189 var skip = false; | |
190 if (spec.experimentType.indexOf("-ifmuted") == -1 && spec.mutedType != "none ") | |
191 skip = true; | |
192 | |
193 if (skip) | |
194 queueNextExperiment(); | |
195 else | |
196 runOneConfig(spec); | |
197 } | |
198 | |
199 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); | |
200 runNextConfig(); | |
201 | |
202 </script> | |
OLD | NEW |