summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/speech/scripted/speechrecognition-errors.html
blob: ca396b696b4f80e42b8df5d42166ac273cf9a547 (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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<script type="text/javascript">
description('Test Speech JavaScript API errors');

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

    notAllowedTest();
}

function setDefaultHandlers(r) {
    for (var prop in r) {
        if (prop.match('^on')) {
            r[prop] = function() {
                testFailed('unexpected ' + event.type + ' event!');
                finishJSTest();
            }
        }
    }
}

function notAllowedTest() {
    debug('\nnotAllowedTest():');
    var r = new webkitSpeechRecognition();
    setDefaultHandlers(r);
    window.count = 0;

    r.start();
    testRunner.setMockSpeechRecognitionError("NotAllowedError", "not allowed");

    // Check that we get an error event.
    r.onerror = function() {
        debug('onerror');
        shouldBe('count', '0');
        count++;
        shouldBeEqualToString('event.error', 'not-allowed');
        shouldBeEqualToString('event.message', 'not allowed');
        shouldBeEqualToString('event.type', 'error');
    }

    // Check that we get an end event after the error event.
    r.onend = function() {
        debug('onend');
        shouldBe('count', '1');
        finishJSTest();
    }
}

window.onload = run;
window.jsTestIsAsync = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>