blob: 773031970d2735b752e3bafbddc02dd74fd296c6 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description('Test basic interaction with the Speech JavaScript API');
function run() {
// Check availability of constructors.
shouldBeTrue("'webkitSpeechRecognition' in self");
shouldBeFalse("webkitSpeechRecognition == null");
oneMatchTest();
}
function oneMatchTest() {
debug('\noneMatchTest():');
var r = new webkitSpeechRecognition();
window.count = 0;
r.onstart = function() { debug('onstart'); shouldBe('count', '0'); ++count; }
r.onaudiostart = function() { debug('onaudiostart'); shouldBe('count', '1'); ++count; }
r.onsoundstart = function() { debug('onsoundstart'); shouldBe('count', '2'); ++count; }
r.onspeechstart = function() { debug('onspeechstart'); shouldBe('count', '3'); ++count; }
r.onresult = function() {
debug('onresult');
shouldBe('count', '4');
++count;
shouldBeNull('event.emma');
shouldBeNull('event.interpretation');
shouldBe('event.results.length', '1');
shouldBeNull('event.results.item(-1)');
shouldBe('event.results[0].length', '1');
shouldBe('event.results[0].isFinal', 'true');
shouldBeEqualToString('event.results[0].item(0).transcript', 'hello, world');
shouldBeCloseTo('event.results[0].item(0).confidence', 0.42, 1e-3);
shouldBeNull('event.results[0].item(-1)');
}
r.onspeechend = function() { debug('onspeechend'); shouldBe('count', '5'); ++count; }
r.onsoundend = function() { debug('onsoundend'); shouldBe('count', '6'); ++count; }
r.onaudioend = function() { debug('onaudioend'); shouldBe('count', '7'); ++count; }
r.onend = function() {
debug('onend');
shouldBe('count', '8');
++count;
noMatchTest();
}
if (window.testRunner) {
testRunner.addMockSpeechRecognitionResult('hello, world', 0.42);
}
r.start();
}
function noMatchTest() {
debug('\nnoMatchTest():');
var r = new webkitSpeechRecognition();
window.count = 0;
r.onstart = function() { debug('onstart'); shouldBe('count', '0'); ++count; }
r.onaudiostart = function() { debug('onaudiostart'); shouldBe('count', '1'); ++count; }
r.onsoundstart = function() { debug('onsoundstart'); shouldBe('count', '2'); ++count; }
r.onspeechstart = function() { debug('onspeechstart'); shouldBe('count', '3'); ++count; }
r.onnomatch = function() {
debug('onnomatch');
shouldBe('count', '4');
++count;
shouldBe('event.results', 'null');
}
r.onspeechend = function() { debug('onspeechend'); shouldBe('count', '5'); ++count; }
r.onsoundend = function() { debug('onsoundend'); shouldBe('count', '6'); ++count; }
r.onaudioend = function() { debug('onaudioend'); shouldBe('count', '7'); ++count; }
r.onend = function() {
debug('onend');
shouldBe('count', '8');
++count;
handleEmptyGrammarTest();
}
r.start();
}
// See crbug.com/545855 for details.
function handleEmptyGrammarTest() {
debug('\nhandleEmptyGrammarTest():');
var r = new webkitSpeechRecognition("");
r.grammars = "";
r.onend = function() {
debug('onend');
finishJSTest();
}
r.start();
}
window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>