autoplay.html (2552B)
1 <!doctype html> 2 <title>autoplay</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/media.js"></script> 6 <div id="log"></div> 7 <script> 8 function autoplay_test(tagName, src) { 9 function expect_events(t, e, expected_events) { 10 var actual_events = []; 11 var callback = t.step_func(function(ev) { 12 actual_events.push(ev.type); 13 assert_array_equals(actual_events, 14 expected_events.slice(0, actual_events.length)); 15 if (expected_events.length == actual_events.length) { 16 t.done(); 17 } 18 }); 19 ['canplay', 'canplaythrough', 20 'pause', 'play', 'playing', 'error'].forEach(function(type) { 21 e.addEventListener(type, callback); 22 }); 23 } 24 25 async_test(function(t) { 26 var e = document.createElement(tagName); 27 e.src = src; 28 e.autoplay = true; 29 expect_events(t, e, ['canplay', 'canplaythrough', 'play', 'playing']); 30 }, tagName + '.autoplay'); 31 32 async_test(function(t) { 33 var e = document.createElement(tagName); 34 e.src = src; 35 e.autoplay = true; 36 e.pause(); // sets the autoplaying flag to false 37 e.load(); // sets the autoplaying flag to true 38 expect_events(t, e, ['canplay', 'canplaythrough', 'play', 'playing']); 39 }, tagName + '.autoplay and load()'); 40 41 async_test(function(t) { 42 var e = document.createElement(tagName); 43 e.src = src; 44 e.autoplay = true; 45 e.play(); // sets the autoplaying flag to false 46 // play() also sets the paused attribute to false; there is no way for the 47 // autoplaying flag to be true when the paused attribute is false. 48 assert_equals(e.paused, false); 49 expect_events(t, e, ['play', 'canplay', 'playing', 'canplaythrough']); 50 }, tagName + '.autoplay and play()'); 51 52 async_test(function(t) { 53 var e = document.createElement(tagName); 54 e.src = src; 55 e.autoplay = true; 56 e.pause(); // sets the autoplaying flag to false 57 expect_events(t, e, ['canplay', 'canplaythrough']); 58 }, tagName + '.autoplay and pause()'); 59 60 async_test(function(t) { 61 var e = document.createElement(tagName); 62 e.src = src; 63 e.autoplay = true; 64 document.body.appendChild(e); 65 document.body.removeChild(e); 66 // in stable state, internal pause steps sets the autoplaying flag to false 67 expect_events(t, e, ['canplay', 'canplaythrough']); 68 }, tagName + '.autoplay and internal pause steps'); 69 } 70 71 autoplay_test('audio', getAudioURI('/media/sound_5')); 72 autoplay_test('video', getVideoURI('/media/movie_5')); 73 </script>