Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / mediastream / MediaStreamConstructor.html
blob324c389253cb938cf1e131bd89a62b1f5f5197c8
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10 description("Tests webkitMediaStream.");
12 var undefined;
13 var stream;
14 var newStream;
15 var nAudio;
16 var nVideo;
17 var idArray = new Array();
19 function checkIdAttribute(id) {
20 if (id.length != 36)
21 return false;
22 for (var i = 0; i < id.length; i++) {
23 charCode = id.charCodeAt(i);
24 if (charCode == 0x21
25 || (charCode >= 0x23 && charCode <= 0x27)
26 || (charCode >= 0x2A && charCode <= 0x2B)
27 || (charCode >= 0x2D && charCode <= 0x2E)
28 || (charCode >= 0x30 && charCode <= 0x39)
29 || (charCode >= 0x41 && charCode <= 0x5A)
30 || (charCode >= 0x5E && charCode <= 0x7E))
31 continue;
32 return false;
34 for (var i = 0; i < idArray.length; i++) {
35 if (id === idArray[i])
36 return false;
38 idArray.push(id);
40 return true;
43 function error() {
44 testFailed('Stream generation failed.');
45 finishJSTest();
48 function getUserMedia(dictionary, callback) {
49 try {
50 navigator.webkitGetUserMedia(dictionary, callback, error);
51 } catch (e) {
52 testFailed('webkitGetUserMedia threw exception :' + e);
53 finishJSTest();
57 function gotStream(s) {
58 localStream = s;
59 testPassed('Got local stream.');
60 shouldBe('localStream.getAudioTracks().length', '1');
61 shouldBe('localStream.getVideoTracks().length', '1');
63 shouldBeTrue("typeof webkitMediaStream === 'function'");
64 shouldBeTrue('checkIdAttribute(localStream.id)');
65 testConstructor(localStream);
68 function testConstructor(s) {
69 stream = s;
70 shouldThrow('new webkitMediaStream(document)');
71 shouldThrow('new webkitMediaStream([document])');
72 shouldThrow('new webkitMediaStream([stream.getAudioTracks()[0], document])');
73 shouldThrow('new webkitMediaStream([null])');
74 shouldThrow('new webkitMediaStream([undefined])');
75 shouldThrow('new webkitMediaStream(null)');
76 shouldThrow('new webkitMediaStream(undefined)');
78 verifyStream(new webkitMediaStream(), 0, 0);
79 verifyStream(new webkitMediaStream([]), 0, 0);
81 verifyStream(new webkitMediaStream(s), s.getAudioTracks().length, s.getVideoTracks().length);
83 verifyStream(new webkitMediaStream([s.getAudioTracks()[0]]), 1, 0);
84 verifyStream(new webkitMediaStream([s.getVideoTracks()[0]]), 0, 1);
85 verifyStream(new webkitMediaStream([s.getAudioTracks()[0], s.getVideoTracks()[0]]), 1, 1);
86 verifyStream(new webkitMediaStream([s.getVideoTracks()[0], s.getAudioTracks()[0], s.getVideoTracks()[0]]), 1, 1);
88 s.oninactive = function () {
89 verifyStream(new webkitMediaStream([s.getAudioTracks()[0]]), 0, 0);
90 verifyStream(new webkitMediaStream([s.getVideoTracks()[0]]), 0, 0);
91 verifyStream(new webkitMediaStream([s.getAudioTracks()[0], s.getVideoTracks()[0]]), 0, 0);
92 verifyStream(new webkitMediaStream(s), 0, 0);
94 finishJSTest();
97 s.stop();
100 function verifyStream(s, numAudioTracks, numVideoTracks) {
101 newStream = s;
102 nAudio = numAudioTracks;
103 nVideo = numVideoTracks;
105 testPassed('Stream constructed');
106 shouldBeNonNull(newStream);
107 shouldBeDefined(newStream);
108 shouldBe("newStream.constructor.name", "'MediaStream'");
109 shouldBe('newStream.getAudioTracks().length', 'nAudio');
110 shouldBe('newStream.getVideoTracks().length', 'nVideo');
112 if (!nAudio && !nVideo)
113 shouldBe('newStream.active', 'false');
114 else
115 shouldBe('newStream.active', 'true');
117 shouldBeTrue('checkIdAttribute(newStream.id)');
120 getUserMedia({video:true, audio:true}, gotStream);
122 window.jsTestIsAsync = true;
123 window.successfullyParsed = true;
124 </script>
125 </body>
126 </html>