Bug 1388909 - Update tests to reflect updated MediaRecorder error handling. r?pehrsons
The MediaRecorder should now transition to inactive immediately upon an error
being encountered. This contrasts with the previous behaviour where onerror
would be called before performing this transition. This changeset updates
tests to reflect this new behaviour.
MozReview-Commit-ID: 5V2JkoMb0wB
--- a/dom/media/test/test_mediarecorder_creation_fail.html
+++ b/dom/media/test/test_mediarecorder_creation_fail.html
@@ -21,17 +21,17 @@ function startTest() {
mediaRecorder.onerror = function (e) {
is(callbackStep, 0, 'should fired onstop callback');
is(e.error.name, 'UnknownError', 'error name should be UnknownError');
ok(e.error.stack.includes('test_mediarecorder_creation_fail.html'),
'Events fired from onerror should include an error with a stack trace indicating ' +
'an error in this test');
is(mediaRecorder.mimeType, '', 'mimetype should be empty');
- is(mediaRecorder.state, 'recording', 'state is recording');
+ is(mediaRecorder.state, 'inactive', 'state is inactive');
info('onerror callback fired');
callbackStep = 1;
};
mediaRecorder.onwarning = function () {
ok(false, 'Unexpected onwarning callback fired');
};
--- a/dom/media/test/test_mediarecorder_getencodeddata.html
+++ b/dom/media/test/test_mediarecorder_getencodeddata.html
@@ -40,33 +40,39 @@ SpecialPowers.pushPrefEnv({"set": [["med
is(evt.data.size, 0,
'Blob data size received is equal to zero');
is(evt.data.type, expectedMimeType,
'Blob data received should have type = ' + expectedMimeType);
is(evt.target.mimeType, expectedMimeType,
'Mime type in ondataavailable = ' + expectedMimeType);
};
mediaRecorder.onerror = function(evt) {
+ is(evt.target.state, 'inactive',
+ 'Media recorder is inactive after firing error');
ok(evt instanceof MediaRecorderErrorEvent,
'Events fired from onerror should be MediaRecorderErrorEvent');
is(evt.type, 'error',
'Event type is error');
ok(evt.error instanceof DOMException,
'Events fired from onerror should have a DOMException in their error member');
is(evt.error.name, 'UnknownError', 'Error name should be UnknownError.');
is(evt.error.message, 'The operation failed for an unknown transient reason');
ok(evt.error.stack.includes('test_mediarecorder_getencodeddata.html'),
'Events fired from onerror should include an error with a stack trace indicating ' +
'an error in this test');
+ try {
+ mediaRecorder.requestData();
+ ok(false, 'requestdata should fire an exception if called on an inactive recorder');
+ } catch (e) {
+ ok(e instanceof DOMException, 'requestdata should fire an exception ' +
+ 'if called on an inactive recorder');
+ is(e.name, 'InvalidStateError', 'Exception name should be InvalidStateError');
+ }
onErrorFired = true;
};
mediaRecorder.start(0);
- is(mediaRecorder.state, 'recording', 'Media recorder should be recording');
- is(mediaRecorder.stream, stream,
- 'Media recorder stream = element stream at the start of recording');
- mediaRecorder.requestData();
}, 100);
}
);
</script>
</pre>
</body>
</html>
--- a/dom/media/test/test_mediarecorder_unsupported_src.html
+++ b/dom/media/test/test_mediarecorder_unsupported_src.html
@@ -19,62 +19,64 @@ function startTest() {
ok(!MediaRecorder.isTypeSupported("video/webm"), 'Should not support video/webm');
ok(!MediaRecorder.isTypeSupported("video/mp4"), 'Should not support video/mp4');
navigator.mozGetUserMedia({audio: false, video: true, fake: true},
function(stream) {
// Expected callback sequence should be:
// 1. onerror (from start)
- // 2. onerror (from pause)
- // 3. ondataavailable
- // 4. onstop
+ // 2. ondataavailable
+ // 3. onstop
var callbackStep = 0;
var mediaRecorder = new MediaRecorder(stream);
is(mediaRecorder.stream, stream, 'Stream should be provided on creation');
mediaRecorder.onerror = function (e) {
callbackStep++;
if (callbackStep == 1) {
try {
mediaRecorder.pause();
+ ok(false, 'pause should fire an exception if called on an inactive recorder');
} catch(e) {
- ok(false, 'Should not get exception in pause call.');
+ ok(e instanceof DOMException, 'pause should fire an exception ' +
+ 'if called on an inactive recorder');
+ is(e.name, 'InvalidStateError', 'Exception name should be InvalidStateError');
}
}
- ok(callbackStep < 3, 'onerror callback fired as expected.');
+ ok(callbackStep == 1, 'onerror callback should handle be the 1st event fired');
is(e.error.name, 'UnknownError', 'Error name should be UnknownError.');
ok(e.error.stack.includes('test_mediarecorder_unsupported_src.html'),
'Events fired from onerror should include an error with a stack trace indicating ' +
'an error in this test');
is(mediaRecorder.mimeType, '', 'mimetype should be empty');
- is(mediaRecorder.state, 'recording', 'state is recording');
+ is(mediaRecorder.state, 'inactive', 'state is inactive');
info('onerror callback fired');
- }
+ };
mediaRecorder.onwarning = function () {
ok(false, 'Unexpected onwarning callback fired.');
};
mediaRecorder.ondataavailable = function (evt) {
callbackStep++;
info('ondataavailable callback fired');
- is(callbackStep, 3, 'should fired ondataavailable callback');
+ is(callbackStep, 2, 'ondataavailable callback should handle the 2nd event fired');
is(evt.data.size, 0, 'data size should be zero');
ok(evt instanceof BlobEvent,
'Events fired from ondataavailable should be BlobEvent');
is(evt.data.type, '', 'encoder start fail, blob miemType should be empty');
};
mediaRecorder.onstop = function() {
callbackStep++;
info('onstop callback fired');
is(mediaRecorder.state, 'inactive', 'state should be inactive');
- is(callbackStep, 4, 'should fired onstop callback');
+ is(callbackStep, 3, 'onstop callback should handle the 3rd event fired');
SimpleTest.finish();
};
try {
mediaRecorder.start();
} catch(e) {
ok(false, 'Should not get exception in start call.');
}