test_mediarecorder_record_startstopstart.html (2413B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test MediaRecorder crash on sequence start stop start method</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <pre id="test"> 10 <div id="content" style="display: none"> 11 </div> 12 <script class="testbody" type="text/javascript"> 13 14 function startTest() { 15 var ac = new window.AudioContext(); 16 var dest = ac.createMediaStreamDestination(); 17 var recorder = new MediaRecorder(dest.stream); 18 var stopCount = 0; 19 var dataavailable = 0; 20 var expectedMimeType = 'audio/ogg; codecs=opus'; 21 recorder.onstop = function () { 22 info('onstop fired'); 23 is(recorder.stream, dest.stream, 24 'Media recorder stream = element stream post recording'); 25 stopCount++; 26 if (stopCount == 2) { 27 if (dataavailable >= 2) { 28 SimpleTest.finish(); 29 } else { 30 ok(false, 'Should have at least two dataavailable events'); 31 } 32 } 33 } 34 recorder.ondataavailable = function (evt) { 35 info('ondataavailable fired'); 36 ok(evt instanceof BlobEvent, 37 'Events fired from ondataavailable should be BlobEvent'); 38 is(evt.type, 'dataavailable', 39 'Event type should dataavailable'); 40 // If script runs slower, it may generate header data in blob from encoder 41 if (evt.data.size > 0) { 42 info('blob size = ' + evt.data.size); 43 is(evt.data.type, expectedMimeType, 44 'Blob data received should have type = ' + expectedMimeType); 45 } 46 dataavailable++; 47 } 48 recorder.onerror = function () { 49 ok(false, 'it should execute normally without exception'); 50 } 51 recorder.onwarning = function() { 52 ok(false, 'onwarning unexpectedly fired'); 53 }; 54 55 recorder.start(2000); 56 is(recorder.state, 'recording', 'Media recorder should be recording'); 57 recorder.stop(); 58 is(recorder.state, 'inactive', 'check recording status is inactive'); 59 recorder.start(10000); // This bug would crash on this line without this fix. 60 is(recorder.state, 'recording', 'check recording status is recording'); 61 // Simulate delay stop, only delay stop no no stop can trigger crash. 62 setTimeout(function() { 63 recorder.stop(); 64 is(recorder.state, 'inactive','check recording status is recording'); 65 }, 1000); 66 } 67 68 SimpleTest.requestFlakyTimeout("untriaged"); 69 startTest(); 70 SimpleTest.waitForExplicitFinish(); 71 </script> 72 </pre> 73 </body> 74 </html>