WebRTC: Navigator.webkitGetUserMedia() requires three arguments
[WebKit-https.git] / LayoutTests / fast / mediastream / getusermedia.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3     <head>
4         <script src="../../resources/js-test-pre.js"></script>
5     </head>
6     <body>
7         <p id="description"></p>
8         <div id="console"></div>
9         <script>
10             description("Tests webkitGetUserMedia.");
11
12             function setUserMediaPermission(isGranted) {
13                 if (window.testRunner)
14                     testRunner.setUserMediaPermission(isGranted);
15                 else
16                     debug("This test can not be run without the testRunner");
17             }
18
19             var stream;
20             var errorArg;
21
22             function error() {
23                 testFailed('Error callback called.');
24                 finishJSTest();
25             }
26
27             function gotStreamInError(s) {
28                 testFailed('Stream generated.');
29                 finishJSTest();
30             }
31
32             function gotStream5(s) {
33                 stream = s;
34                 testPassed('Stream generated.');
35                 shouldBe('stream.getAudioTracks().length', '1');
36                 shouldBe('stream.getVideoTracks().length', '1');
37                 finishJSTest();
38             }
39
40             function error1(e) {
41                 errorArg = e;
42                 testPassed('Error callback called.');
43                 shouldBeEqualToString('errorArg.name', 'ConstraintNotSatisfiedError');
44                 shouldBeEqualToString('errorArg.constraintName', 'valid_but_unsupported_1');
45
46                 shouldThrow("navigator.webkitGetUserMedia({audio:{mandatory:{'valid_and_supported_1':1}, optional:[{'valid_but_unsupported_1':0}]}, video:true}, gotStream5, 0);");
47                 shouldNotThrow("navigator.webkitGetUserMedia({audio:{mandatory:{'valid_and_supported_1':1}, optional:[{'valid_but_unsupported_1':0}]}, video:true}, gotStream5, error);");
48             }
49
50             function gotStream4(s) {
51                 stream = s;
52                 testPassed('Stream generated.');
53                 shouldBe('stream.getAudioTracks().length', '1');
54                 shouldBe('stream.getVideoTracks().length', '1');
55
56                 shouldThrow("navigator.webkitGetUserMedia({audio:{mandatory:{'valid_but_unsupported_1':0}, optional:[]}, video:true}, gotStreamInError, null);");
57                 shouldNotThrow("navigator.webkitGetUserMedia({audio:{mandatory:{'valid_but_unsupported_1':0}, optional:[]}, video:true}, gotStreamInError, error1);");
58             }
59
60             function gotStream3(s) {
61                 stream = s;
62                 testPassed('Stream generated.');
63                 shouldBe('stream.getAudioTracks().length', '1');
64                 shouldBe('stream.getVideoTracks().length', '1');
65
66                 shouldThrow("navigator.webkitGetUserMedia({audio:{mandatory:{}, optional:[]}, video:true}, gotStream4, null);");
67                 shouldNotThrow("navigator.webkitGetUserMedia({audio:{mandatory:{}, optional:[]}, video:true}, gotStream4, error);");
68             }
69
70             function gotStream2(s) {
71                 stream = s;
72                 testPassed('Stream generated.');
73                 shouldBe('stream.getAudioTracks().length', '0');
74                 shouldBe('stream.getVideoTracks().length', '1');
75
76                 shouldThrow("navigator.webkitGetUserMedia({audio:true, video:true}, gotStream3, null);");
77                 shouldNotThrow("navigator.webkitGetUserMedia({audio:true, video:true}, gotStream3, error);");
78             }
79
80             function gotStream1(s) {
81                 stream = s;
82                 testPassed('Stream generated.');
83                 shouldBe('stream.getAudioTracks().length', '1');
84                 shouldBe('stream.getVideoTracks().length', '0');
85
86                 shouldThrow("navigator.webkitGetUserMedia({video:true}, gotStream2, null);")
87                 shouldNotThrow("navigator.webkitGetUserMedia({video:true}, gotStream2, error);")
88             }
89
90             shouldThrow("navigator.webkitGetUserMedia({audio:false, video:false}, error, error);")
91             shouldThrow("navigator.webkitGetUserMedia({audio:false, video:false}, error, null);")
92
93             setUserMediaPermission(true);
94             shouldNotThrow("navigator.webkitGetUserMedia({audio:true}, gotStream1, error);");
95
96             window.jsTestIsAsync = true;
97             window.successfullyParsed = true;
98         </script>
99         <script src="../../resources/js-test-post.js"></script>
100     </body>
101 </html>