summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/speech/scripted/start-exception.html
blob: c21ff433696c6281b4c1c99a2548cdb2e5b66819 (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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description('Test getting an exception when calling start() in the Speech JavaScript API');

function run() {
    // Check availability of constructors.
    shouldBeTrue("'webkitSpeechRecognition' in self");
    shouldBeFalse("webkitSpeechRecognition == null");

    doubleStart();
}

function doubleStart() {
    debug('\ndoubleStart():');
    evalAndLog("window.r = new webkitSpeechRecognition()");

    // Set default handlers.
    for (var prop in r) {
        if (prop.match('^on')) {
            r[prop] = function() {
                debug('on' + event.type);

                if (event.type === 'end') {
                    shouldNotThrow("r.start()");
                    evalAndLog("r.abort()");

                    r.onend = function() {
                        debug('onend');
                        finishJSTest();
                    }
                } else {
                    shouldThrow("r.start()", '"InvalidStateError: Failed to execute \'start\' on \'SpeechRecognition\': recognition has already started."');
                }
            }
        }
    }

    shouldNotThrow("r.start()");
    shouldThrow("r.start()", '"InvalidStateError: Failed to execute \'start\' on \'SpeechRecognition\': recognition has already started."');
}

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