speech-synthesis-elapsed-time.html 1.29 KB
Newer Older
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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../../fast/js/resources/js-test-pre.js"></script>
</head>
<body id="body">

<div id="console"></div>

<script>

    if (window.internals)
        window.internals.enableMockSpeechSynthesizer();

    description("This tests that elapsed time is a number that is reasonable.");

    if (window.testRunner)
        testRunner.waitUntilDone();

    window.jsTestIsAsync = true;

    var u = new SpeechSynthesisUtterance("hello word");

    var startTime = 0;
    u.onstart = function(event) {
       startTime = event.elapsedTime;
       debug("Our start time for speech should be very small.");
       shouldBeTrue("startTime < .5");
    }
    u.onboundary = function(event) {
       debug("Word boundary received: startTime should be less than the current elapsed time.");
       shouldBeTrue("startTime < event.elapsedTime");
    }

    u.onend = function(event) {
       debug("The finished elapsed time should be small and the startTime should have occurred before the end.");
       shouldBeTrue("startTime < event.elapsedTime");
       shouldBeTrue("event.elapsedTime < 1");
       finishJSTest();
    }

    speechSynthesis.speak(u);

</script>

<script src="../../../../fast/js/resources/js-test-post.js"></script>
</body>
</html>