-
Notifications
You must be signed in to change notification settings - Fork 8
/
navigator.getusermedia_test.js
54 lines (41 loc) · 1.61 KB
/
navigator.getusermedia_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*global QUnit:true, module:true, test:true, asyncTest:true, expect:true*/
/*global start:true, stop:true ok:true, equal:true, notEqual:true, deepEqual:true*/
/*global notDeepEqual:true, strictEqual:true, notStrictEqual:true, raises:true*/
(function( window, navigator ) {
test("navigator.getUserMedia", 1, function() {
equal(typeof navigator.getUserMedia, "function", "navigator.getUserMedia() is a function");
});
// Only run this in a real browser
if ( window.opera || window.chrome || navigator.mozGetUserMedia ) {
// This test is questionable, as it will prompt for sharing your camera
asyncTest("Really works", 1, function() {
var video = document.querySelector("#test-target");
navigator.getUserMedia({ video: true }, function( stream ) {
video.src = stream;
video.play();
video.addEventListener("canplaythrough", function(e) {
ok( true, "playing!!" );
start();
}, false);
});
});
} else {
// This test is questionable, as it will prompt for sharing your camera
asyncTest("first param is object, no exceptions", 1, function() {
// Needs to be tested in a real browser
if ( !/Phantom/.test(navigator.userAgent) ) {
try {
navigator.getUserMedia({ video: true, audio: true }, function() {}, function() {});
ok( true, "No Exception thrown" );
} catch(e) {
ok( false, "Exception thrown" );
} finally {
start();
}
} else {
ok( true, "not tested in phantomjs" );
start();
}
});
}
} ( this, this.navigator ) );