Support arbitrary video resolution in getUserMedia API
[WebKit-https.git] / LayoutTests / fast / mediastream / apply-constraints-video.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="../../resources/js-test-pre.js"></script>
5         <script src="resources/apply-constraints-utils.js"></script>
6         <script>
7
8             let tests = [
9                 {
10                     message: "set width, height, and frame rate to valid values.",
11                     constraint: { width: 640, height: 480, frameRate: 30 }, 
12                     expected: { width: 640, height: 480, frameRate: 30 }, 
13                 },
14                 {
15                     message: "change width and height, frame rate should remain unchanged.",
16                     constraint: { width: 320, height: 240 }, 
17                     expected: { width: 320, height: 240, frameRate: 30 }, 
18                 },
19                 {
20                     message: "the 'exact' constraint can't be satisfied, promise should reject and no settings should change.",
21                     constraint: { width: { exact: 2000 } }, 
22                     expected: { width: 320, height: 240, frameRate: 30 },
23                     error: "width",
24                 },
25                 {
26                     message: "the 'min' constraint can't be satisfied, promise should reject and no settings should change.",
27                     constraint: { width: 640, height: {min: 3000}, }, 
28                     expected: { width: 320, height: 240, frameRate: 30 },
29                     error: "height",
30                 },
31                 {
32                     message: "the 'max' constraint can't be satisfied, promise should reject and no settings should change.",
33                     constraint: { frameRate: {max: 8}, }, 
34                     expected: { frameRate: 30 },
35                     error: "frameRate",
36                 },
37                 {
38                     message: "the 'exact' constraint can be satisfied.",
39                     constraint: { width: { exact: 640 } },
40                     expected: { width: 640, height: 480 },
41                 },
42                 {
43                     message: "the 'ideal' constraint can't be satisfied but the 'min' can, maximum value should be chosen.",
44                     constraint: { width: {min: 300, ideal: 5000} }, 
45                     expected: { width: 1280, height: 720 },
46                 },
47                 {
48                     message: "'ideal' and 'min' constraints can be satisfied, 'ideal' should be chosen.",
49                     constraint: { width: {min: 320, ideal: 640}, height: {min: 480, ideal: 720}, }, 
50                     expected: { width: 640, height: 720 },
51                 },
52                 {
53                     message: "ideal width is greater than track capability, should be clamped to the maximum value.",
54                     constraint: { width: 5000 },
55                     expected: { width: 1280},
56                 },
57                 {
58                     message: "all values are less than track capabilities, should be clamped to the minimum values.",
59                     constraint: { width: 100, height: 100, frameRate: 4 },
60                     expected: { width: 112, height: 112, frameRate: 5 },
61                 },
62                 {
63                     message: "set frame rate, width and height should remain unchanged",
64                     constraint: { frameRate: 20 }, 
65                     expected: { width: 112, height: 112, frameRate: 20 },
66                 },
67                 {
68                     message: "illegal facing mode value should be ignored, height should change.",
69                     constraint: { facingMode: "xnvironment", height: 720 },
70                     expected: { facingMode: "user", width: 1280, height: 720 },
71                 },
72                 {
73                     message: "unknown constraint should be ignored, frame rate should change.",
74                     constraint: { WITDH: 400, frameRate: 30 }, 
75                     expected: { width: 1280, frameRate: 30 },
76                 },
77             ];
78
79             let tester = new ConstraintsTest({ video: true }, tests, "Tests applyConstraints on a video stream track.")
80                 .onStreamReady((s) => {
81                     stream = s;
82                     shouldBe('stream.getVideoTracks().length', '1');
83                     shouldBe('stream.getAudioTracks().length', '0');
84                     tester.setStreamTrack(stream.getVideoTracks()[0]);
85                 })
86                 .onVideoReady((v) => {
87                     video = v;
88                     shouldBe('video.videoTracks.length', '1');
89                     shouldBe('video.audioTracks.length', '0');
90                 })
91                 .start();
92
93         </script>
94         <script src="../../resources/js-test-post.js"></script>
95     </head>
96     <body>
97         <video controls id="video"</video>
98         <br>
99         <div id="div"></div>
100
101     </body>
102 </html>
103