Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / speech / scripted / speechrecognition-basics.html
blob95aaa44220f49b63b57cf169b4b5d8cd67ca51c0
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script type="text/javascript">
8 description('Test basic interaction with the Speech JavaScript API');
10 function run() {
11 // Check availability of constructors.
12 shouldBeTrue("'webkitSpeechRecognition' in self");
13 shouldBeFalse("webkitSpeechRecognition == null");
15 oneMatchTest();
18 function oneMatchTest() {
19 debug('\noneMatchTest():');
20 var r = new webkitSpeechRecognition();
21 window.count = 0;
23 r.onstart = function() { debug('onstart'); shouldBe('count', '0'); ++count; }
24 r.onaudiostart = function() { debug('onaudiostart'); shouldBe('count', '1'); ++count; }
25 r.onsoundstart = function() { debug('onsoundstart'); shouldBe('count', '2'); ++count; }
26 r.onspeechstart = function() { debug('onspeechstart'); shouldBe('count', '3'); ++count; }
28 r.onresult = function() {
29 debug('onresult');
30 shouldBe('count', '4');
31 ++count;
32 shouldBeNull('event.emma');
33 shouldBeNull('event.interpretation');
34 shouldBe('event.results.length', '1');
35 shouldBeNull('event.results.item(-1)');
36 shouldBe('event.results[0].length', '1');
37 shouldBe('event.results[0].isFinal', 'true');
38 shouldBeEqualToString('event.results[0].item(0).transcript', 'hello, world');
39 shouldBeCloseTo('event.results[0].item(0).confidence', 0.42, 1e-3);
40 shouldBeNull('event.results[0].item(-1)');
43 r.onspeechend = function() { debug('onspeechend'); shouldBe('count', '5'); ++count; }
44 r.onsoundend = function() { debug('onsoundend'); shouldBe('count', '6'); ++count; }
45 r.onaudioend = function() { debug('onaudioend'); shouldBe('count', '7'); ++count; }
47 r.onend = function() {
48 debug('onend');
49 shouldBe('count', '8');
50 ++count;
51 noMatchTest();
54 if (window.testRunner) {
55 testRunner.addMockSpeechRecognitionResult('hello, world', 0.42);
57 r.start();
60 function noMatchTest() {
61 debug('\nnoMatchTest():');
62 var r = new webkitSpeechRecognition();
63 window.count = 0;
65 r.onstart = function() { debug('onstart'); shouldBe('count', '0'); ++count; }
66 r.onaudiostart = function() { debug('onaudiostart'); shouldBe('count', '1'); ++count; }
67 r.onsoundstart = function() { debug('onsoundstart'); shouldBe('count', '2'); ++count; }
68 r.onspeechstart = function() { debug('onspeechstart'); shouldBe('count', '3'); ++count; }
70 r.onnomatch = function() {
71 debug('onnomatch');
72 shouldBe('count', '4');
73 ++count;
74 shouldBe('event.results', 'null');
77 r.onspeechend = function() { debug('onspeechend'); shouldBe('count', '5'); ++count; }
78 r.onsoundend = function() { debug('onsoundend'); shouldBe('count', '6'); ++count; }
79 r.onaudioend = function() { debug('onaudioend'); shouldBe('count', '7'); ++count; }
81 r.onend = function() {
82 debug('onend');
83 shouldBe('count', '8');
84 ++count;
85 finishJSTest();
88 r.start();
91 window.onload = run;
92 window.jsTestIsAsync = true;
93 </script>
94 </body>
95 </html>