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

--HG--
extra : rebase_source : cdd61c7fe128089458fd93f18d6b133a52b9b8aa
This commit is contained in:
Bryce Van Dyk 2017-09-04 07:07:54 +12:00
parent 9fec9bfac9
commit 521b6759e8
3 changed files with 22 additions and 14 deletions

View File

@ -26,7 +26,7 @@ function startTest() {
'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;
};

View File

@ -45,6 +45,8 @@ SpecialPowers.pushPrefEnv({"set": [["media.ogg.enabled", false]]},
'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',
@ -56,13 +58,17 @@ SpecialPowers.pushPrefEnv({"set": [["media.ogg.enabled", false]]},
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);
}
);

View File

@ -24,9 +24,8 @@ function startTest() {
// 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);
@ -37,19 +36,22 @@ function startTest() {
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.');
@ -58,7 +60,7 @@ function startTest() {
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');
@ -69,7 +71,7 @@ function startTest() {
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();
};