Commit 3dcd7356 authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Commit Bot

Make speech layout tests use testharness.js

Makes the tests simpler in many cases and also removes the -expected
files.

Bug: 781655
Change-Id: I15957ca318c56f4904bb68bc085880e70823d202
Reviewed-on: https://chromium-review.googlesource.com/1111910
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570760}
parent e609e9ce
Tests the basics of the Speech JavaScript API
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS 'webkitSpeechRecognition' in self is true
PASS webkitSpeechRecognition == null is false
PASS speechReco == null is false
PASS 'grammars' in speechReco is true
PASS speechReco.grammars == null is false
PASS speechReco.grammars.length === 0 is true
PASS 'lang' in speechReco is true
PASS 'continuous' in speechReco is true
PASS 'interimResults' in speechReco is true
PASS 'maxAlternatives' in speechReco is true
PASS 'start' in speechReco is true
PASS 'stop' in speechReco is true
PASS 'abort' in speechReco is true
PASS 'onaudiostart' in speechReco is true
PASS 'onsoundstart' in speechReco is true
PASS 'onspeechstart' in speechReco is true
PASS 'onspeechend' in speechReco is true
PASS 'onsoundend' in speechReco is true
PASS 'onaudioend' in speechReco is true
PASS 'onresult' in speechReco is true
PASS 'onnomatch' in speechReco is true
PASS 'onerror' in speechReco is true
PASS 'onstart' in speechReco is true
PASS 'onend' in speechReco is true
PASS 'addEventListener' in speechReco is true
PASS 'removeEventListener' in speechReco is true
PASS 'dispatchEvent' in speechReco is true
PASS speechReco.lang is ''
PASS speechReco.continuous is false
PASS speechReco.maxAlternatives is 1
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description('Tests the basics of the Speech JavaScript API');
<!doctype html>
<title>Tests the basics of the Speech JavaScript API</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
function run() {
// Check availability of constructors.
shouldBeTrue("'webkitSpeechRecognition' in self");
shouldBeFalse("webkitSpeechRecognition == null");
test(() => {
assert_true("webkitSpeechRecognition" in self);
assert_not_equals(webkitSpeechRecognition, null);
}, "Check availability of constructors");
// Check for members of SpeechRecognition.
window.speechReco = new webkitSpeechRecognition();
shouldBeFalse("speechReco == null");
shouldBeTrue("'grammars' in speechReco");
shouldBeFalse("speechReco.grammars == null");
shouldBeTrue("speechReco.grammars.length === 0");
shouldBeTrue("'lang' in speechReco");
shouldBeTrue("'continuous' in speechReco");
shouldBeTrue("'interimResults' in speechReco");
shouldBeTrue("'maxAlternatives' in speechReco");
shouldBeTrue("'start' in speechReco");
shouldBeTrue("'stop' in speechReco");
shouldBeTrue("'abort' in speechReco");
shouldBeTrue("'onaudiostart' in speechReco");
shouldBeTrue("'onsoundstart' in speechReco");
shouldBeTrue("'onspeechstart' in speechReco");
shouldBeTrue("'onspeechend' in speechReco");
shouldBeTrue("'onsoundend' in speechReco");
shouldBeTrue("'onaudioend' in speechReco");
shouldBeTrue("'onresult' in speechReco");
shouldBeTrue("'onnomatch' in speechReco");
shouldBeTrue("'onerror' in speechReco");
shouldBeTrue("'onstart' in speechReco");
shouldBeTrue("'onend' in speechReco");
test(() => {
var speechReco = new webkitSpeechRecognition();
assert_not_equals(speechReco, null);
assert_true("grammars" in speechReco);
assert_not_equals(speechReco.grammars, null);
assert_equals(speechReco.grammars.length, 0);
assert_true("lang" in speechReco);
assert_true("continuous" in speechReco);
assert_true("interimResults" in speechReco);
assert_true("maxAlternatives" in speechReco);
assert_true("start" in speechReco);
assert_true("stop" in speechReco);
assert_true("abort" in speechReco);
assert_true("onaudiostart" in speechReco);
assert_true("onsoundstart" in speechReco);
assert_true("onspeechstart" in speechReco);
assert_true("onspeechend" in speechReco);
assert_true("onsoundend" in speechReco);
assert_true("onaudioend" in speechReco);
assert_true("onresult" in speechReco);
assert_true("onnomatch" in speechReco);
assert_true("onerror" in speechReco);
assert_true("onstart" in speechReco);
assert_true("onend" in speechReco);
shouldBeTrue("'addEventListener' in speechReco");
shouldBeTrue("'removeEventListener' in speechReco");
shouldBeTrue("'dispatchEvent' in speechReco");
assert_true("addEventListener" in speechReco);
assert_true("removeEventListener" in speechReco);
assert_true("dispatchEvent" in speechReco);
}, "Check members of SpeechRecognition");
// Check default values.
// FIXME: The spec should say what the default value for .grammars is.
shouldBe("speechReco.lang", "''");
shouldBe("speechReco.continuous", "false");
shouldBe("speechReco.maxAlternatives", "1");
test(() => {
var speechReco = new webkitSpeechRecognition();
assert_equals(speechReco.lang, "");
assert_equals(speechReco.continuous, false);
assert_equals(speechReco.maxAlternatives, 1);
}, "Check default values of SpeechRecognition");
finishJSTest();
}
window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>
'use strict';
// MockSpeechRecognizer is a mock implementation of mojom::SpeechRecognizer and
// the browser speech recognition service. It currently only supports running
// one recognition session at a time. Mock results can be set using
// the browser speech recognition service. Mock results can be set using
// addMockSpeechRecognitionResult, and setMockSpeechRecognitionError can be used
// to simulate an error state. If no mock results are set, a NoMatch error is
// sent to the client.
......@@ -116,7 +115,5 @@ class MockSpeechRecognitionSession {
stop() {}
abort() {
this.recognizer_.session_client_.ended();
}
abort() {}
}
Tests the basics of SpeechGrammar and SpeechGrammarList
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS 'webkitSpeechGrammar' in window is true
PASS webkitSpeechGrammar == null is false
PASS 'webkitSpeechGrammarList' in window is true
PASS webkitSpeechGrammarList == null is false
window.g = new webkitSpeechGrammar()
PASS g == null is false
PASS g.weight is 1.0
PASS g.src is ''
g.weight = 2
PASS g.weight is 2.0
PASS g.weight = NaN threw exception TypeError: Failed to set the 'weight' property on 'SpeechGrammar': The provided float value is non-finite..
PASS g.weight = Infinity threw exception TypeError: Failed to set the 'weight' property on 'SpeechGrammar': The provided float value is non-finite..
PASS g.weight is 2.0
g.src = 'grammar.xml'
PASS g.src is base + 'grammar.xml'
g.src = 'http://example.tld/grammar.xml'
PASS g.src is 'http://example.tld/grammar.xml'
g.src = 'foo bar'
PASS g.src is base + 'foo%20bar'
window.gs = new webkitSpeechGrammarList()
PASS gs == null is false
PASS gs.length is 0
PASS gs.item(0) == null is true
PASS gs[0] == undefined is true
PASS gs.item(-1) is null
PASS gs[-1] == undefined is true
gs.addFromUri('grammar', 2)
PASS gs.length is 1
PASS gs.item(1) == null is true
PASS gs[1] == undefined is true
PASS gs.item(-1) is null
PASS gs[-1] == undefined is true
PASS gs[0] is gs.item(0)
PASS gs.item(0).src is base + 'grammar'
PASS gs.item(0).weight is 2
gs.addFromUri('http://foo.tld/grammar.xml', 3)
PASS gs.length is 2
PASS gs[1] is gs.item(1)
PASS gs.item(1).src is 'http://foo.tld/grammar.xml'
PASS gs.item(1).weight is 3
gs.addFromString('foo', 4)
PASS gs.length is 3
PASS gs[2] is gs.item(2)
PASS gs.item(2).src is 'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'
PASS gs.item(2).weight is 4
PASS gs[2].src is 'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'
PASS gs[2].weight is 4
PASS gs.addFromUri('http://foo.tld/grammar.xml', NaN) threw exception TypeError: Failed to execute 'addFromUri' on 'SpeechGrammarList': The provided float value is non-finite..
PASS gs.addFromUri('http://foo.tld/grammar.xml', Infinity) threw exception TypeError: Failed to execute 'addFromUri' on 'SpeechGrammarList': The provided float value is non-finite..
PASS gs.addFromString('foo', NaN) threw exception TypeError: Failed to execute 'addFromString' on 'SpeechGrammarList': The provided float value is non-finite..
PASS gs.addFromString('foo', Infinity) threw exception TypeError: Failed to execute 'addFromString' on 'SpeechGrammarList': The provided float value is non-finite..
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description('Tests the basics of SpeechGrammar and SpeechGrammarList');
<!doctype html>
<title>Tests the basics of SpeechGrammar and SpeechGrammarList</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
const base = document.baseURI.substring(0,
document.baseURI.lastIndexOf('/') + 1);
function run() {
window.base = document.baseURI.substring(0, document.baseURI.lastIndexOf('/') + 1);
test(() => {
assert_true('webkitSpeechGrammar' in window);
assert_false(webkitSpeechGrammar == null);
assert_true('webkitSpeechGrammarList' in window);
assert_false(webkitSpeechGrammarList == null);
}, "Check availablility of constructors");
// Check availability of constructors.
shouldBeTrue("'webkitSpeechGrammar' in window");
shouldBeFalse("webkitSpeechGrammar == null");
shouldBeTrue("'webkitSpeechGrammarList' in window");
shouldBeFalse("webkitSpeechGrammarList == null");
test(() => {
var g = new webkitSpeechGrammar();
assert_false(g == null);
assert_equals(g.weight, 1.0);
assert_equals(g.src, "");
}, "Creating a grammar explicitly");
// Test creating a grammar explicitly.
evalAndLog("window.g = new webkitSpeechGrammar()");
shouldBeFalse("g == null");
shouldBe("g.weight", "1.0");
shouldBe("g.src", "''");
test(() => {
var g = new webkitSpeechGrammar();
g.weight = 2;
assert_equals(g.weight, 2.0);
assert_throws({name: "TypeError"}, () => g.weight = NaN);
assert_throws({name: "TypeError"}, () => g.weight = Infinity);
assert_equals(g.weight, 2.0);
g.src = "grammar.xml";
assert_equals(g.src, base + "grammar.xml");
g.src = "http://example.tld/grammar.xml"
assert_equals(g.src, "http://example.tld/grammar.xml");
g.src = "foo bar";
assert_equals(g.src, base + "foo%20bar");
}, "Setting grammar attributes");
// Test setting the attributes.
evalAndLog("g.weight = 2");
shouldBe("g.weight", "2.0");
shouldThrow("g.weight = NaN");
shouldThrow("g.weight = Infinity");
shouldBe("g.weight", "2.0");
evalAndLog("g.src = 'grammar.xml'");
shouldBe("g.src", "base + 'grammar.xml'");
evalAndLog("g.src = 'http://example.tld/grammar.xml'");
shouldBe("g.src", "'http://example.tld/grammar.xml'");
evalAndLog("g.src = 'foo bar'");
shouldBe("g.src", "base + 'foo%20bar'");
test(() => {
gs = new webkitSpeechGrammarList();
assert_false(gs == null);
assert_equals(gs.length, 0);
assert_equals(gs.item(0), null);
assert_equals(gs[0], undefined);
assert_equals(gs.item(-1), null);
assert_equals(gs[-1], undefined);
// Test creating a grammar list.
evalAndLog("window.gs = new webkitSpeechGrammarList()");
shouldBeFalse("gs == null");
shouldBe("gs.length", "0");
shouldBeTrue("gs.item(0) == null");
shouldBeTrue("gs[0] == undefined");
shouldBeNull("gs.item(-1)");
shouldBeTrue("gs[-1] == undefined");
gs.addFromUri("grammar", 2);
assert_equals(gs.length, 1);
assert_equals(gs.item(1), null);
assert_equals(gs[1], undefined);
assert_equals(gs.item(-1), null);
assert_equals(gs[-1], undefined);
assert_equals(gs[0], gs.item(0));
assert_equals(gs.item(0).src, base + "grammar");
assert_equals(gs.item(0).weight, 2);
evalAndLog("gs.addFromUri('grammar', 2)");
shouldBe("gs.length", "1");
shouldBeTrue("gs.item(1) == null");
shouldBeTrue("gs[1] == undefined");
shouldBeNull("gs.item(-1)");
shouldBeTrue("gs[-1] == undefined");
shouldBe("gs[0]", "gs.item(0)");
shouldBe("gs.item(0).src", "base + 'grammar'");
shouldBe("gs.item(0).weight", "2");
gs.addFromUri("http://foo.tld/grammar.xml", 3);
assert_equals(gs.length, 2);
assert_equals(gs[1], gs.item(1));
assert_equals(gs.item(1).src, "http://foo.tld/grammar.xml");
assert_equals(gs.item(1).weight, 3);
evalAndLog("gs.addFromUri('http://foo.tld/grammar.xml', 3)");
shouldBe("gs.length", "2");
shouldBe("gs[1]", "gs.item(1)");
shouldBe("gs.item(1).src", "'http://foo.tld/grammar.xml'");
shouldBe("gs.item(1).weight", "3");
gs.addFromString('<grammar>foo</grammar>', 4);
assert_equals(gs.length, 3);
assert_equals(gs[2], gs.item(2));
assert_equals(gs.item(2).src,
"data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E");
assert_equals(gs.item(2).weight, 4);
assert_equals(gs[2].src,
"data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E");
assert_equals(gs[2].weight, 4);
evalAndLog("gs.addFromString('<grammar>foo</grammar>', 4)");
shouldBe("gs.length", "3");
shouldBe("gs[2]", "gs.item(2)");
shouldBe("gs.item(2).src", "'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'");
shouldBe("gs.item(2).weight", "4");
shouldBe("gs[2].src", "'data:application/xml,%3Cgrammar%3Efoo%3C/grammar%3E'");
shouldBe("gs[2].weight", "4");
assert_throws({name: "TypeError"},
() => gs.addFromUri("http://foo.tld/grammar.xml", NaN));
assert_throws({name: "TypeError"},
() => gs.addFromUri("http://foo.tld/grammar.xml", Infinity));
assert_throws({name: "TypeError"},
() => gs.addFromString("foo", NaN));
assert_throws({name: "TypeError"},
() => gs.addFromString("foo", Infinity));
}, "Creating a grammar list");
shouldThrow("gs.addFromUri('http://foo.tld/grammar.xml', NaN)");
shouldThrow("gs.addFromUri('http://foo.tld/grammar.xml', Infinity)");
shouldThrow("gs.addFromString('foo', NaN)");
shouldThrow("gs.addFromString('foo', Infinity)");
finishJSTest();
}
window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>
Test basic interaction with the Speech JavaScript API
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS 'webkitSpeechRecognition' in self is true
PASS webkitSpeechRecognition == null is false
oneMatchTest():
onstart
PASS count is 0
onaudiostart
PASS count is 1
onsoundstart
PASS count is 2
onspeechstart
PASS count is 3
onresult
PASS count is 4
PASS event.emma is null
PASS event.interpretation is null
PASS event.results.length is 1
PASS event.results.item(-1) is null
PASS event.results[0].length is 1
PASS event.results[0].isFinal is true
PASS event.results[0].item(0).transcript is "hello, world"
PASS event.results[0].item(0).confidence is within 0.001 of 0.42
PASS event.results[0].item(-1) is null
onspeechend
PASS count is 5
onsoundend
PASS count is 6
onaudioend
PASS count is 7
onend
PASS count is 8
noMatchTest():
onstart
PASS count is 0
onaudiostart
PASS count is 1
onsoundstart
PASS count is 2
onspeechstart
PASS count is 3
onnomatch
PASS count is 4
PASS event.results is null
onspeechend
PASS count is 5
onsoundend
PASS count is 6
onaudioend
PASS count is 7
onend
PASS count is 8
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<!doctype html>
<title>Test basic interaction with the Speech JavaScript API</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/speech/speech_recognizer.mojom.js"></script>
<script src="mock-speechrecognizer.js"></script>
</head>
<body>
<script type="text/javascript">
description('Test basic interaction with the Speech JavaScript API');
<script>
function run() {
// Check availability of constructors.
shouldBeTrue("'webkitSpeechRecognition' in self");
shouldBeFalse("webkitSpeechRecognition == null");
test(() => {
assert_true('webkitSpeechRecognition' in self);
assert_false(webkitSpeechRecognition == null);
}, "Check constructors");
oneMatchTest();
}
async_test(t => {
var r = new webkitSpeechRecognition();
var count = 0;
function oneMatchTest() {
debug('\noneMatchTest():');
var r = new webkitSpeechRecognition();
window.count = 0;
r.onstart = t.step_func(() => { assert_equals(count, 0); count++; });
r.onaudiostart = t.step_func(() => { assert_equals(count, 1); count++ });
r.onsoundstart = t.step_func(() => { assert_equals(count, 2); count++ });
r.onspeechstart = t.step_func(() => { assert_equals(count, 3); count++ });
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 = t.step_func((event) => {
assert_equals(count, 4);
count++;
assert_equals(event.emma, null);
assert_equals(event.interpretation, null);
assert_equals(event.results.length, 1);
assert_equals(event.results.item(-1), null);
assert_equals(event.results[0].length, 1);
assert_true(event.results[0].isFinal);
assert_equals(event.results[0].item(0).transcript, 'hello, world');
assert_approx_equals(event.results[0].item(0).confidence, 0.42, 1e-3);
assert_equals(event.results[0].item(-1), null);
});
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 = t.step_func(() => { assert_equals(count, 5); count++; });
r.onsoundend = t.step_func(() => { assert_equals(count, 6); count++; });
r.onaudioend = t.step_func(() => { assert_equals(count, 7); count++; });
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 = t.step_func_done(() => {
assert_equals(count, 8);
count++;
});
r.onend = function() {
debug('onend');
shouldBe('count', '8');
++count;
noMatchTest();
}
mockSpeechRecognizer.addMockSpeechRecognitionResult('hello, world', 0.42);
r.start();
}
mockSpeechRecognizer.addMockSpeechRecognitionResult('hello, world', 0.42);
r.start();
}, "One match test");
function noMatchTest() {
debug('\nnoMatchTest():');
var r = new webkitSpeechRecognition();
window.count = 0;
async_test(t => {
var r = new webkitSpeechRecognition();
var 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.onstart = t.step_func(() => { assert_equals(count, 0); count++; });
r.onaudiostart = t.step_func(() => { assert_equals(count, 1); count++ });
r.onsoundstart = t.step_func(() => { assert_equals(count, 2); count++ });
r.onspeechstart = t.step_func(() => { assert_equals(count, 3); count++ });
r.onnomatch = function() {
debug('onnomatch');
shouldBe('count', '4');
++count;
shouldBe('event.results', 'null');
}
r.onnomatch = t.step_func((event) => {
assert_equals(count, 4);
count++;
assert_equals(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.onspeechend = t.step_func(() => { assert_equals(count, 5); count++; });
r.onsoundend = t.step_func(() => { assert_equals(count, 6); count++; });
r.onaudioend = t.step_func(() => { assert_equals(count, 7); count++; });
r.onend = function() {
debug('onend');
shouldBe('count', '8');
finishJSTest();
}
r.onend = t.step_func_done(() => {
assert_equals(count, 8);
count++;
});
r.start();
}
r.start();
});
window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>
Accessing SpeechRecognition on a detached window should not crash.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS recognition.start() is undefined.
PASS recognition.stop() is undefined.
PASS recognition.abort() is undefined.
PASS recognition = new constructor() did not throw exception.
PASS recognition.start() is undefined.
PASS recognition.stop() is undefined.
PASS recognition.abort() is undefined.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<!doctype html>
<title>Accessing SpeechRecognition on a detached window should not crash.</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/speech/speech_recognizer.mojom.js"></script>
<script src="mock-speechrecognizer.js"></script>
</head>
<body>
<script>
description("Accessing SpeechRecognition on a detached window should not crash.");
window.jsTestIsAsync = true;
async_test(t => {
var w = window.open('../../../resources/window-postmessage-open-close.html');
var constructor;
var recognition;
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
testRunner.setCanOpenWindows();
}
var w;
var recognition;
var constructor;
function processMessage(event) {
window.addEventListener('message', t.step_func(event => {
if (event.data == "opened") {
constructor = w.webkitSpeechRecognition;
recognition = new constructor();
w.close();
constructor = w.webkitSpeechRecognition;
recognition = new constructor();
w.close();
} else if (event.data == "closed") {
shouldBeUndefined("recognition.start()");
shouldBeUndefined("recognition.stop()");
shouldBeUndefined("recognition.abort()");
// Create SpeechRecognition for a page-detached window/document.
shouldNotThrow("recognition = new constructor()");
shouldBeUndefined("recognition.start()");
shouldBeUndefined("recognition.stop()");
shouldBeUndefined("recognition.abort()");
finishJSTest();
recognition.start();
recognition.stop();
recognition.abort();
recognition = new constructor();
recognition.start();
recognition.stop();
recognition.abort();
t.done();
}
}
}), false);
});
w = window.open('../../../resources/window-postmessage-open-close.html');
window.addEventListener("message", processMessage, false);
</script>
</body>
</html>
Test Speech JavaScript API errors
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS 'webkitSpeechRecognition' in self is true
PASS webkitSpeechRecognition == null is false
notAllowedTest():
onerror
PASS count is 0
PASS event.error is "not-allowed"
PASS event.message is ""
PASS event.type is "error"
onend
PASS count is 1
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<!doctype html>
<title>Test Speech JavaScript API errors</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/speech/speech_recognizer.mojom.js"></script>
<script src="mock-speechrecognizer.js"></script>
</head>
<body>
<script type="text/javascript">
description('Test Speech JavaScript API errors');
<script>
function run() {
// Check availability of constructors.
shouldBeTrue("'webkitSpeechRecognition' in self");
shouldBeFalse("webkitSpeechRecognition == null");
async_test(t => {
var r = new webkitSpeechRecognition();
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();
mockSpeechRecognizer.setMockSpeechRecognitionError(blink.mojom.SpeechRecognitionErrorCode.kNotAllowed);
// Check that we get an error event.
r.onerror = function() {
debug('onerror');
shouldBe('count', '0');
count++;
shouldBeEqualToString('event.error', 'not-allowed');
shouldBeEqualToString('event.message', '');
shouldBeEqualToString('event.type', 'error');
}
// Check that we get an end event after the error event.
r.onend = function() {
debug('onend');
shouldBe('count', '1');
finishJSTest();
for (var prop in r) {
if (prop.match('^on')) {
r[prop] = function() {
assert_unreached('unexpected ' + event.type + ' event!');
}
}
}
}
var count = 0;
r.start();
mockSpeechRecognizer.setMockSpeechRecognitionError(
blink.mojom.SpeechRecognitionErrorCode.kNotAllowed);
// Check that we get an error event.
r.onerror = t.step_func(event => {
assert_equals(count, 0);
count++;
assert_equals(event.error, 'not-allowed');
assert_equals(event.message, '');
assert_equals(event.type, 'error');
});
// Check that we get an end event after the error event.
r.onend = t.step_func_done(() => {
assert_equals(count, 1);
});
}, 'Not-allowed error test');
window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>
Verify that multiple overlapping start() calls is well-behaved.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<!doctype html>
<title>Verify that multiple overlapping start() calls is well-behaved.</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/speech/speech_recognizer.mojom.js"></script>
<script src="mock-speechrecognizer.js"></script>
</head>
<body>
<script>
description("Verify that multiple overlapping start() calls is well-behaved.");
self.jsTestIsAsync = true;
async_test(t => {
var r1 = new webkitSpeechRecognition();
r1.onend = () => r1.start();
r1.start();
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var r2 = new webkitSpeechRecognition();
r2.onend = () => setTimeout(() => t.done());
r2.start();
});
var r1 = new webkitSpeechRecognition();
r1.onend = function() {
r1.start();
};
r1.start();
var r2 = new webkitSpeechRecognition();
r2.onend = function() {
setTimeout(finishJSTest);
};
r2.start();
</script>
</body>
</html>
Verify that calling start() during onend does not crash.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<!doctype html>
<title>Verify that calling start() during onend does not crash</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
description("Verify that calling start() during onend does not crash.");
self.jsTestIsAsync = true;
async_test(t => {
var recog = new webkitSpeechRecognition();
recog.onend = () => {
recog.start();
setTimeout(() => t.done());
};
recog.start();
});
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var recog = new webkitSpeechRecognition();
recog.onend = function () { recog.start(); setTimeout(finishJSTest); };
recog.start();
</script>
</body>
</html>
Tests the basics of the SpeechRecognitionError interface
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS 'webkitSpeechRecognitionError' in window is true
PASS webkitSpeechRecognitionError == null is false
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script type="text/javascript">
description('Tests the basics of the SpeechRecognitionError interface');
<!doctype html>
<title>Tests the basics of the SpeechRecognitionError interface</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script>
function run() {
// Check availability of constructor.
shouldBeTrue("'webkitSpeechRecognitionError' in window");
shouldBeFalse("webkitSpeechRecognitionError == null");
test(() => {
assert_true('webkitSpeechRecognitionError' in window);
assert_false(webkitSpeechRecognitionError == null);
}, "Check availability of constructor");
finishJSTest();
}
window.onload = run;
window.jsTestIsAsync = true;
</script>
</body>
</html>
Verify that multiple SpeechRecognition objects can co-exist in tests.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<!doctype html>
<title>Verify that multiple SpeechRecognition objects can co-exist in tests</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/speech/speech_recognizer.mojom.js"></script>
<script src="mock-speechrecognizer.js"></script>
<script>
description("Verify that multiple SpeechRecognition objects can co-exist in tests.");
async_test(t => {
var objectCount = 4;
var count = objectCount;
self.jsTestIsAsync = true;
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
var objectCount = 4;
var count = objectCount;
for (var i = 0; i < objectCount; ++i) {
var recog = new webkitSpeechRecognition();
recog.onend = () => {
if (--count == 0)
setTimeout(finishJSTest);
};
recog.start();
}
for (var i = 0; i < objectCount; ++i) {
var recog = new webkitSpeechRecognition();
recog.onend = t.step_func(() => {
if (--count == 0)
t.done();
});
recog.start();
}
});
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment