chromium/third_party/blink/web_tests/fast/mediastream/MediaStream-stop.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Test cloning mediastreams onactive/oninactive callbacks.");

var cloned_stream;

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

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

function onStreamActive() {
    testPassed('Clone stream active.');
    shouldBeTrue('cloned_stream.active');
    finishJSTest();
}

function gotStream2(s) {
    cloned_stream.onactive = onStreamActive;
    cloned_stream.addTrack(s.getVideoTracks()[0]);
}

function onStreamInactive() {
    testPassed('Clone stream inactive.');
    shouldBeFalse('cloned_stream.active');

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

function gotStream(s) {
    var stream = s;

    cloned_stream = stream.clone();
    // oninactive doesn't fire. crbug.com/78176
    // cloned_stream.oninactive = onStreamInactive;
    shouldBeTrue('cloned_stream.active');
    shouldBe('cloned_stream.getVideoTracks().length', '1');
    shouldBe('cloned_stream.getAudioTracks().length', '1');
    cloned_stream.getVideoTracks()[0].stop();
    cloned_stream.getAudioTracks()[0].stop();
    finishJSTest();
}

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

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