b8b60758a0bb7634561263d68415fa0ea446c91a
[WebKit-https.git] / LayoutTests / fast / mediastream / constraint-intrinsic-size.html
1 <!doctype html>
2 <html>
3     <head>
4         <meta charset="utf-8">
5         <title>video track width and height should be set correctly when only one constraint is passed to getDisplayMedia</title>
6         <script src="../../resources/testharness.js"></script>
7         <script src="../../resources/testharnessreport.js"></script>
8     </head>
9     <body>
10
11         <script>
12             if (window.testRunner)
13                 testRunner.setUserMediaPermission(true);
14             if (window.internals) {
15                 window.internals.setMockMediaCaptureDevicesEnabled(true);
16                 window.internals.settings.setScreenCaptureEnabled(true);
17             }
18
19             let defaultWidth;
20             let defaultHeight;
21             promise_test(async () => {
22                 stream = await navigator.mediaDevices.getDisplayMedia({ video: true });
23                 let settings = stream.getVideoTracks()[0].getSettings();
24                 defaultWidth = settings.width;
25                 defaultHeight = settings.height;
26             }, "setup");
27             
28             promise_test((test) => {
29                 return navigator.mediaDevices.getDisplayMedia({ video: { width: {ideal: 640} } })
30                     .then((stream) => {
31                         let settings = stream.getVideoTracks()[0].getSettings()
32                         assert_equals(settings.height, Math.floor(640 * (defaultHeight / defaultWidth)));
33                     })
34             }, "height calculated correctly only width is specified");
35
36             promise_test((test) => {
37
38                 return navigator.mediaDevices.getDisplayMedia({ video: { height: {ideal: 240} } })
39                     .then((stream) => {
40                         let settings = stream.getVideoTracks()[0].getSettings()
41                         assert_equals(settings.width, Math.floor(240 * (defaultWidth / defaultHeight)));
42                     })
43             }, "width calculated correctly only height is specified");
44
45         </script>
46     </body>
47 </html>