Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-getConstraints.html

Issue 1910463002: Implement MediaStreamTrack.getConstraints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding global-interface-listing entry Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script>
6 </head>
7 <body>
8 <script>
9
10
11 // If a constraint is specified, it should come back in getConstraints().
12 promise_test(function() {
13 return navigator.mediaDevices.getUserMedia({audio: { echoCancellation: { exact : true}}})
14 .then(function(s) {
15 constraints = s.getAudioTracks()[0].getConstraints();
16 assert_equals(Object.keys(constraints).length, 1, "constraints(1): " + JSON. stringify(constraints));
17 assert_equals(constraints.echoCancellation.exact, true, "constraints(2): " + JSON.stringify(constraints));
Peter Beverloo 2016/04/21 14:11:45 Could make this a bit more explicit: assert_true(
hta - Chromium 2016/04/24 09:58:25 Done.
18 });
19 }, 'A set constraint is returned on getConstraints');
20
21 promise_test(function() {
22 return navigator.mediaDevices.getUserMedia({audio: { echoCancellation: { exact : true}, notKnownName: { exact: true }}})
23 .then(function(s) {
24 constraints = s.getAudioTracks()[0].getConstraints();
25 assert_equals(Object.keys(constraints).length, 1, "constraints(1): " + JSON. stringify(constraints));
26 assert_equals(constraints.echoCancellation.exact, true, "constraints(2): " + JSON.stringify(constraints));
Peter Beverloo 2016/04/21 14:11:45 assert_false(constraints.hasOwnProperty('notKnownN
hta - Chromium 2016/04/24 09:58:25 Done.
27 });
28 }, 'An unknown constraint is NOT returned on getConstraints');
29
30 function constraintElementsEqual(a, b) {
31 if (a === b) return true;
32 if (!(a instanceof Object)) return false;
33 if (!(b instanceof Object)) return false;
34 if (Object.keys(a).length != Object.keys(b).length) return false;
35 for (var p in a) {
36 if (!a.hasOwnProperty(p)) continue;
37 if (!b.hasOwnProperty(p)) return false;
38 if (a[p] instanceof Object && b[p] instanceof Object) {
39 if (!constraintElementsEqual(a[p], b[p])) return false;
40 continue;
41 }
42 if (a[p] !== b[p]) return false;;
43 }
44 return true;
45 }
46
47
48 promise_test(function() {
49 // We construct a constraint set that covers all defined constraints.
50 // All these constraints make sense for video.
51 complexConstraintSet = {
52 width: { min: 30, max: 480 },
53 height: { min: 30, max: 480, exact: 350 },
54 aspectRatio: { ideal: 1.3333333, exact: 1.4444 },
55 frameRate: { exact: 30.0 },
56 facingMode: { ideal: [ "user" ] }
57 };
58 // These constraints are syntactically valid, but may cause rejection.
59 // They are included in an "advanced" constraint.
60 ignorableConstraintSet = {
61 volume: { exact: 1.0 },
62 sampleRate: { exact: 42 },
63 sampleSize: { exact: 3 },
64 echoCancellation: { exact: false },
65 latency: { exact: 0.22 },
66 channelCount: { exact: 2 },
67 deviceId: { exact: ["foo"] },
68 groupId: { exact: ["bar"] }
69 };
70 complexConstraints = complexConstraintSet;
71 complexConstraints.advanced = [ ignorableConstraintSet ];
Peter Beverloo 2016/04/21 14:11:45 nit: Please prefix these variables with `let` or `
hta - Chromium 2016/04/24 09:58:25 Done.
72
73 return navigator.mediaDevices.getUserMedia({video: complexConstraints})
74 .then(function(s) {
75 constraints = s.getVideoTracks()[0].getConstraints();
76 assert_true(constraintElementsEqual(constraints, complexConstraints),
77 "Unexpected result:" + JSON.stringify(constraints, null, 2));
78 });
79 }, 'All valid keys are returned for complex constraints');
80
81
82
83 </script>
84 </body>
85 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698