1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<!DOCTYPE html>
<html>
<head>
<title>Test face framing support</title>
<link rel="help" href="https://w3c.github.io/mediacapture-extensions/">
</head>
<body>
<h1 class="instructions">Description</h1>
<p class="instructions">This test checks face framing support.</p>
<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
"use strict";
const constraintSet = {
faceFraming: true
};
Object.keys(constraintSet).forEach(property => {
test(t => {
const supportedConstraints =
navigator.mediaDevices.getSupportedConstraints();
assert_implements_optional(
supportedConstraints[property],
`Optional property ${property} not in supported constraints`);
}, `Test getSupportedConstraints().${property}`);
promise_test(async t => {
const supportedConstraints =
navigator.mediaDevices.getSupportedConstraints();
const stream = await navigator.mediaDevices.getUserMedia({video: true});
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
const [videoTrack] = stream.getVideoTracks();
assert_equals(typeof videoTrack.getCapabilities, 'function');
const capabilities = videoTrack.getCapabilities();
assert_equals(typeof capabilities, 'object');
if (!supportedConstraints[property]) {
assert_false(property in capabilities);
}
assert_implements_optional(
property in capabilities,
`Optional property ${property} not in capabilities`);
// Accept [false], [false, true], [true] and [true, false].
assert_array_equals(
capabilities[property],
capabilities[property].length == 1
? [!!capabilities[property][0]]
: [!!capabilities[property][0], !capabilities[property][0]]);
}, `Test getCapabilities().${property}`);
promise_test(async t => {
const supportedConstraints =
navigator.mediaDevices.getSupportedConstraints();
const stream = await navigator.mediaDevices.getUserMedia({video: true});
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
const [videoTrack] = stream.getVideoTracks();
const capabilities = videoTrack.getCapabilities();
assert_equals(typeof videoTrack.getSettings, 'function');
const settings = videoTrack.getSettings();
assert_equals(typeof settings, 'object');
if (!supportedConstraints[property] || !(property in capabilities))
assert_false(property in settings);
assert_implements_optional(
property in capabilities,
`Optional property ${property} not in capabilities`);
assert_in_array(settings[property], capabilities[property]);
}, `Test getSettings().${property}`);
promise_test(async t => {
const supportedConstraints =
navigator.mediaDevices.getSupportedConstraints();
const stream = await navigator.mediaDevices.getUserMedia({video: true});
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
const [videoTrack] = stream.getVideoTracks();
const capabilities = videoTrack.getCapabilities();
const constraints = {
[property]: {exact: constraintSet[property]}
};
const oldSettings = videoTrack.getSettings();
if (supportedConstraints[property] && !(property in capabilities)) {
// The user agent supports |constraints| but |videoTrack| is not capable
// to apply them.
await videoTrack.applyConstraints(constraints).then(
() => {
assert_unreached('Unexpected success applying constraints');
},
error => {});
} else {
// The user agent does not support |constraints| and will ignore them or
// the user agent supports |constraints| and |videoTrack| is capable to
// apply them.
await videoTrack.applyConstraints(constraints).then(
() => {},
error => {
assert_unreached(`Error applying constraints: ${error.message}`);
});
}
assert_equals(typeof videoTrack.getConstraints, 'function');
const appliedConstraints = videoTrack.getConstraints();
assert_equals(typeof appliedConstraints, 'object');
const newSettings = videoTrack.getSettings();
if (!supportedConstraints[property] || !(property in capabilities)) {
// The user agent does not support |constraints| and ignored them or
// the user agent supports |constraints| but |videoTrack| was not capable
// to apply them.
assert_object_equals(appliedConstraints, {});
} else {
// The user agent supports |constraints| and |videoTrack| was capable to
// apply them.
assert_object_equals(appliedConstraints, constraints);
}
if (!supportedConstraints[property] || !(property in capabilities) ||
!capabilities[property].includes(constraintSet[property])) {
// The user agent does not support |constraints| and ignored them or
// the user agent supports |constraints| but |videoTrack| was not capable
// to apply them or the user agent supports |constraints| and
// |videoTrack| was capable to apply them but could not satisfy advanced
// constraints and skipped them.
assert_object_equals(newSettings, oldSettings);
} else {
// The user agent supports |constraints| and |videoTrack| was capable to
// apply them and could satisfy advanced constraints.
assert_equals(newSettings[property], constraintSet[property]);
}
}, `Test applyConstraints() with ${property}`);
});
</script>
</body>
</html>
|