summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack.html
blob: 807b6710b304a9d247ee2803cdd4eebafc498ff9 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests MediaStreamTrack callbacks.");

// Note that the below behaviour doesn't reflect how it works outside of LayoutTests.
// The underlying mock is modified to trigger the events when certain functions are called.
// This modified behaviour allows us to test the MediaStreamTrack class properly.

var track;

function error() {
    testFailed('Stream generation failed.');
    finishJSTest();
}

function getUserMedia(constraints, callback) {
    try {
        navigator.webkitGetUserMedia(constraints, callback, error);
    } catch (e) {
        testFailed('webkitGetUserMedia threw exception :' + e);
        finishJSTest();
    }
}

function onTrackEnded() {
    testPassed('Track onended callback succeeded.');

    shouldBeEqualToString('track.readyState', 'ended');

    finishJSTest();
}

function onTrackUnmute() {
    testPassed('Track onunmute callback succeeded.');

    shouldBeEqualToString('track.readyState', 'live');

    track.stop();
}

function onTrackMute() {
    testPassed('Track onmute callback succeeded.');

    shouldBeEqualToString('track.readyState', 'muted');

    track.enabled = true;
}

function gotStream(stream) {
    testPassed('getUserMedia succeeded.');

    track = stream.getVideoTracks()[0];

    shouldBeEqualToString('track.readyState', 'live');

    track.onunmute = onTrackUnmute;
    track.onmute = onTrackMute;
    track.onended = onTrackEnded;

    track.enabled = false;
}

getUserMedia({audio:true, video:true}, gotStream);

window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
</body>
</html>