Bug 1295352 - Fix media mochitests to not end with active gUM. r=pehrsons

MozReview-Commit-ID: 9p5uHN1mPHK

--HG--
extra : rebase_source : 466be0b2c48c49c9842ce5b6ddb41ec72e706f7e
extra : intermediate-source : 572f17fd9e607b26f7a06d4b526bef50ab5074a0
extra : source : e8d6d5f8bcc93a488739635fe55ffdbd17dc206d
This commit is contained in:
Jan-Ivar Bruaroey 2016-08-12 15:18:51 -04:00
parent 5fc1422320
commit c0640cddba
13 changed files with 89 additions and 75 deletions

View File

@ -18,6 +18,7 @@ var spinEventLoop = () => new Promise(r => setTimeout(r, 0));
var stream;
var clone;
var newStream;
var tracks = [];
var addTrack = track => {
info("Adding track " + track.id);
@ -49,15 +50,15 @@ runTest(() => getUserMedia({audio: true, video: true})
})
.then(s => {
newStream = s;
info("Stopping an original track");
stopTrack(stream.getTracks()[0]);
// TODO: Uncomment once bug 1294605 is fixed
// info("Stopping an original track");
// stopTrack(stream.getTracks()[0]);
return spinEventLoop();
})
.then(() => {
info("Removing original tracks");
stream.getTracks().forEach(t => stream.removeTrack(t));
stream.getTracks().forEach(t => (stream.removeTrack(t), tracks.push(t)));
return spinEventLoop();
})
@ -89,6 +90,7 @@ runTest(() => getUserMedia({audio: true, video: true})
.then(() => {
info("Stopping originals");
stream.getTracks().forEach(t => stopTrack(t));
tracks.forEach(t => stopTrack(t));
return spinEventLoop();
})

View File

@ -31,7 +31,8 @@
ok(video.videoHeight > 0, "Expected nonzero video width");
resolve();
});
});
})
.then(() => stream.getTracks().forEach(t => t.stop()));
});
});

View File

@ -16,7 +16,7 @@
});
runTest(() => Promise.resolve()
.then(() => getUserMedia({audio:true, video: true})).then(stream => {
.then(() => getUserMedia({audio:true, video: true})).then(stream => {
info("Test addTrack()ing a video track to an audio-only gUM stream");
var video = createMediaElement("video", "test_video_track");
@ -24,7 +24,8 @@
video.play();
var h = new CaptureStreamTestHelper2D();
stream.removeTrack(stream.getVideoTracks()[0]);
var removedTrack = stream.getVideoTracks()[0];
stream.removeTrack(removedTrack);
video.onloadeddata = () => {
info("loadeddata");
var canvas = document.createElement("canvas");
@ -40,7 +41,10 @@
return listenUntil(video, "loadeddata", () => true)
.then(() => h.waitForPixelColor(video, h.grey, 5,
"The canvas track should be rendered by the media element"));
"The canvas track should be rendered by the media element"))
.then(() => {
[removedTrack, ...stream.getAudioTracks()].forEach(t => t.stop());
});
}));
</script>
</pre>

View File

@ -102,53 +102,50 @@ var mustFailWith = (msg, reason, constraint, f) =>
* test by verifying that the right resolution and rejection is fired.
*/
runTest(function() {
runTest(() => Promise.resolve()
.then(() => {
// Check supported constraints first.
var dict = navigator.mediaDevices.getSupportedConstraints();
var supported = Object.keys(dict);
// Check supported constraints first.
var dict = navigator.mediaDevices.getSupportedConstraints();
var supported = Object.keys(dict);
mustSupport.forEach(key => ok(supported.indexOf(key) != -1 && dict[key],
"Supports " + key));
mustSupport.forEach(key => ok(supported.indexOf(key) != -1 && dict[key],
"Supports " + key));
var unexpected = supported.filter(key => mustSupport.indexOf(key) == -1);
is(unexpected.length, 0,
"Unanticipated support (please update test): " + unexpected);
// Run constraint tests
var p = new Promise(resolve => SpecialPowers.pushPrefEnv({
set : [ ['media.getusermedia.browser.enabled', false],
['media.getusermedia.screensharing.enabled', false] ]
}, resolve));
return tests.reduce((p, test) =>
p.then(() => navigator.mediaDevices.getUserMedia(test.constraints))
.then(() => is(null, test.error, test.message), e => {
var unexpected = supported.filter(key => mustSupport.indexOf(key) == -1);
is(unexpected.length, 0,
"Unanticipated support (please update test): " + unexpected);
})
.then(() => pushPrefs(["media.getusermedia.browser.enabled", false],
["media.getusermedia.screensharing.enabled", false]))
.then(() => tests.reduce((p, test) => p.then(() => getUserMedia(test.constraints))
.then(stream => {
is(null, test.error, test.message);
stream.getTracks().forEach(t => t.stop());
}, e => {
is(e.name, test.error, test.message + ": " + e.message);
if (test.constraint) {
is(e.constraint, test.constraint,
test.message + " w/correct constraint.");
}
}), p)
.then(() => navigator.mediaDevices.getUserMedia({video: true, audio: true}))
.then(stream => stream.getVideoTracks()[0].applyConstraints({ width: 320 })
.then(() => stream.getAudioTracks()[0].applyConstraints({ })))
.then(() => ok(true, "applyConstraints code exercised"))
// TODO: Test outcome once fake devices support constraints (Bug 1088621)
.then(() => mustFailWith("applyConstraints fails on non-Gum tracks",
"OverconstrainedError", "",
() => (new AudioContext())
.createMediaStreamDestination().stream
.getAudioTracks()[0].applyConstraints()))
.then(() => mustFailWith(
"getUserMedia with unsatisfied required constraint",
"OverconstrainedError", "deviceId",
() => navigator.mediaDevices.getUserMedia({
audio: true,
video: { deviceId: { exact: "unheardof" } },
})));
});
}), Promise.resolve()))
.then(() => getUserMedia({video: true, audio: true}))
.then(stream => stream.getVideoTracks()[0].applyConstraints({ width: 320 })
.then(() => stream.getAudioTracks()[0].applyConstraints({ }))
.then(() => {
stream.getTracks().forEach(track => track.stop());
ok(true, "applyConstraints code exercised");
}))
// TODO: Test outcome once fake devices support constraints (Bug 1088621)
.then(() => mustFailWith("applyConstraints fails on non-Gum tracks",
"OverconstrainedError", "",
() => (new AudioContext())
.createMediaStreamDestination().stream
.getAudioTracks()[0].applyConstraints()))
.then(() => mustFailWith(
"getUserMedia with unsatisfied required constraint",
"OverconstrainedError", "deviceId",
() => getUserMedia({ audio: true,
video: { deviceId: { exact: "unheardof" } } }))));
</script>
</pre>

View File

@ -40,6 +40,7 @@
newStream.addTrack(videoTrack);
is(newStream.getTrackById(videoTrack.id), videoTrack,
"getTrackByid with matching id should return the track");
[audioTrack, videoTrack].forEach(t => t.stop());
});
});

View File

@ -24,11 +24,13 @@
var constraints = {video: true, audio: true};
return getUserMedia(constraints).then(stream => new Promise(resolve => {
v.srcObject = stream;
v.onloadedmetadata = resolve;
})).then(() => {
isnot(v.videoWidth, 0, "videoWidth shall be set on 'loadedmetadata'");
isnot(v.videoHeight, 0, "videoHeight shall be set on 'loadedmetadata'");
});
v.onloadedmetadata = () => {
isnot(v.videoWidth, 0, "videoWidth shall be set on 'loadedmetadata'");
isnot(v.videoHeight, 0, "videoHeight shall be set on 'loadedmetadata'");
resolve();
};
})
.then(() => stream.getTracks().forEach(t => t.stop())));
});
</script>

View File

@ -73,8 +73,9 @@
}))
.then(() => getUserMedia({audio: true, video: true})).then(stream => {
info("Test cloning a stream into inception");
var inceptionClone = stream.clone().clone().clone().clone().clone()
.clone().clone().clone().clone().clone();
var clone = stream;
var clones = Array(10).fill().map(() => clone = clone.clone());
var inceptionClone = clones.pop();
checkMediaStreamCloneAgainstOriginal(inceptionClone, stream);
stream.getTracks().forEach(t => (stream.removeTrack(t),
inceptionClone.addTrack(t)));
@ -85,7 +86,8 @@
var test = createMediaElement('video', 'testClonePlayback');
var playback = new MediaStreamPlayback(test, inceptionClone);
return playback.playMedia(false);
return playback.playMedia(false)
.then(() => clones.forEach(c => c.getTracks().forEach(t => t.stop())));
})
.then(() => getUserMedia({audio: true, video: true})).then(stream => {
info("Test adding tracks from many stream clones to the original stream");

View File

@ -40,8 +40,9 @@
.then(() => getUserMedia({video: true})).then(stream => {
info("Test cloning a track into inception");
var track = stream.getTracks()[0];
var inceptionClone = track.clone().clone().clone().clone().clone()
.clone().clone().clone().clone().clone();
var clone = track;
var clones = Array(10).fill().map(() => clone = clone.clone());
var inceptionClone = clones.pop();
checkMediaStreamTrackCloneAgainstOriginal(inceptionClone, track);
var cloneStream = new MediaStream();
@ -52,10 +53,16 @@
var test = createMediaElement('video', 'testClonePlayback');
var playback = new MediaStreamPlayback(test, cloneStream);
return playback.playMedia(false)
.then(() => info("Testing that clones of ended tracks are ended"))
.then(() => cloneStream.clone().getTracks().forEach(t =>
is(t.readyState, "ended", "Track " + t.id + " should be ended")));
return playback.playMedia(false).then(() => {
// TODO: Uncomment once bug 1294605 is fixed
// info("Testing that clones of ended tracks are ended");
// cloneStream.clone().getTracks().forEach(t =>
// is(t.readyState, "ended", "Track " + t.id + " should be ended"));
})
.then(() => {
clones.forEach(t => t.stop());
track.stop();
});
})
.then(() => getUserMedia({audio: true, video: true})).then(stream => {
info("Test adding many track clones to the original stream");

View File

@ -22,7 +22,7 @@ function theTest() {
.then(stream => Promise.all([
audioIsSilence(withConstraint, stream),
videoIsBlack(withConstraint, stream)
]));
]).then(() => stream.getTracks().forEach(t => t.stop())));
};
// both without and with the constraint

View File

@ -15,9 +15,8 @@
var testAudio = createMediaElement('audio', 'testAudio');
var playback = new LocalMediaStreamPlayback(testAudio, audioStream);
return playback.playMedia(false)
.then(() => playback.playMedia(true))
.then(() => audioStream.stop());
return playback.playMediaWithoutStoppingTracks(false)
.then(() => playback.playMedia(true));
});
});
</script>

View File

@ -15,9 +15,8 @@
var testVideo = createMediaElement('video', 'testVideo');
var playback = new LocalMediaStreamPlayback(testVideo, stream);
return playback.playMedia(false)
.then(() => playback.playMedia(true))
.then(() => stream.stop());
return playback.playMediaWithoutStoppingTracks(false)
.then(() => playback.playMedia(true));
});
});

View File

@ -15,9 +15,8 @@
var testVideo = createMediaElement('video', 'testVideo');
var streamPlayback = new LocalMediaStreamPlayback(testVideo, stream);
return streamPlayback.playMedia(false)
.then(() => streamPlayback.playMedia(true))
.then(() => stream.stop());
return streamPlayback.playMediaWithoutStoppingTracks(false)
.then(() => streamPlayback.playMedia(true));
});
});

View File

@ -13,10 +13,11 @@
runTest(() => {
var testAudio = createMediaElement('audio', 'testAudio');
return new Promise((resolve, reject) => {
navigator.mozGetUserMedia({ audio: true }, () => {
navigator.mozGetUserMedia({ audio: true }, stream => {
SpecialPowers.spinEventLoop(window);
ok(true, "Didn't crash");
resolve();
ok(true, "Didn't crash");
stream.getTracks().forEach(t => t.stop());
resolve();
}, () => {});
});
});