forked from mirrors/gecko-dev
Automatic update from web-platform-tests Use webdriver to set permission on getUserMedia calls (#31847) * Remove fake-ui from chrome wptrunner Rely instead of SetPermission webdriver hook; this allows testing permission denial. * Use webdriver to set permission on getUserMedia calls Rewrite mediacapture-streams using async/await for consistency in the process Move a couple of manual tests back to automated as a result * Catch web driver error more specifically when setting permission per https://github.com/web-platform-tests/wpt/pull/31847#pullrequestreview-824508906 * Rename setPermission in setMediaPermission per https://github.com/web-platform-tests/wpt/pull/31847#issuecomment-987261583 * Limit media capture permissions to what is strictly needed for the test per https://github.com/web-platform-tests/wpt/pull/31847#issuecomment-987261583 * Align quoting styles for script loading -- wpt-commits: 319a0a7580aaee957801545901150a0dabd9e735 wpt-pr: 31847
100 lines
3.4 KiB
HTML
100 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src=/resources/testdriver.js></script>
|
|
<script src=/resources/testdriver-vendor.js></script>
|
|
<script src='../mediacapture-streams/permission-helper.js'></script>
|
|
<script>
|
|
|
|
// This test verifies that ImageCapture can be created (or not) with different
|
|
// Media Stream Track types (audio, video).
|
|
|
|
function makeAsyncTest(modifyTrack, message) {
|
|
async_test(function(test) {
|
|
|
|
const gotStream = test.step_func(function(stream) {
|
|
assert_equals(stream.getAudioTracks().length, 0);
|
|
assert_equals(stream.getVideoTracks().length, 1);
|
|
|
|
var videoTrack = stream.getVideoTracks()[0];
|
|
assert_equals(videoTrack.readyState, 'live');
|
|
assert_true(videoTrack.enabled);
|
|
assert_false(videoTrack.muted);
|
|
|
|
var capturer = new ImageCapture(videoTrack);
|
|
assert_equals(capturer.track, videoTrack);
|
|
|
|
modifyTrack(videoTrack);
|
|
|
|
promise_rejects_dom(test,
|
|
'InvalidStateError',
|
|
capturer.grabFrame(),
|
|
'Should throw InvalidStateError.')
|
|
.then(() => test.done());
|
|
});
|
|
|
|
const onError = test.unreached_func('Error creating MediaStream.');
|
|
// both permissions are needed at some point, asking for both at once
|
|
setMediaPermission()
|
|
.then(() => navigator.mediaDevices.getUserMedia({video: true}))
|
|
.then(gotStream)
|
|
.catch(onError);
|
|
|
|
}, message);
|
|
}
|
|
|
|
var disableTrack = function(videoTrack) {
|
|
// grabFrame() is rejected if the associated video track is disabled.
|
|
videoTrack.enabled = false;
|
|
};
|
|
|
|
var stopTrack = function(videoTrack) {
|
|
// grabFrame() is rejected if the associated video track is ended.
|
|
videoTrack.stop();
|
|
assert_equals(videoTrack.readyState, 'ended');
|
|
};
|
|
|
|
// Create the rejection tests. Note that grabFrame() would also be rejected if
|
|
// the video Track was muted but that's a read-only property of the Track.
|
|
makeAsyncTest(disableTrack, 'grabFrame() of a disabled Track');
|
|
makeAsyncTest(stopTrack, 'grabFrame() of an ended Track');
|
|
|
|
|
|
var testAudio = async_test(function() {
|
|
navigator.mediaDevices.getUserMedia({audio:true})
|
|
.then(
|
|
this.step_func(function(stream) {
|
|
assert_equals(stream.getAudioTracks().length, 1);
|
|
assert_equals(stream.getVideoTracks().length, 0);
|
|
assert_throws_dom("NotSupportedError",
|
|
function() {
|
|
var capturer = new ImageCapture(stream.getAudioTracks()[0]);
|
|
},
|
|
'an ImageCapturer can only be created from a video track');
|
|
|
|
this.done();
|
|
}))
|
|
.catch(
|
|
this.unreached_func('Error creating MediaStream.'));
|
|
}, 'verifies that an ImageCapture cannot be created out of an Audio Track');
|
|
|
|
var testParameter = test(function() {
|
|
const invalidParameters = [
|
|
"invalid",
|
|
null,
|
|
123,
|
|
{},
|
|
"",
|
|
true
|
|
];
|
|
assert_throws_js(TypeError,
|
|
function() { var capturer = new ImageCapture(); },
|
|
'an ImageCapturer cannot be created with no parameter');
|
|
invalidParameters.map(parameter => {
|
|
assert_throws_js(TypeError,
|
|
function() { var capturer = new ImageCapture(parameter); },
|
|
`an ImageCapturer cannot be created with a ${parameter} parameter`);
|
|
});
|
|
}, 'throw "TypeError" if parameter is not MediaStreamTrack.');
|
|
|
|
</script>
|