Skip to content

Commit

Permalink
Add WPT for Web Speech API events
Browse files Browse the repository at this point in the history
This CL adds some basic web platform tests to ensure that the onstart, onend, and onerror events are fired for the Web Speech API.

Change-Id: Ieeaab551b95b56503917e468f9ec33d857790dad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6137598
Commit-Queue: Evan Liu <[email protected]>
Reviewed-by: Yiren Wang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1402727}
  • Loading branch information
evliu-google authored and chromium-wpt-export-bot committed Jan 7, 2025
1 parent f13ebbb commit 9ff4054
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
27 changes: 27 additions & 0 deletions speech-api/SpeechRecognition-onerror.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>SpeechRecognition onerror event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();

// Promise that resolves when the 'error' event is fired.
const errorPromise = new Promise(resolve => {
recognition.onerror = (event) => {
assert_equals("audio-capture", event.error);
resolve();
};
});

// Start speech recognition.
recognition.start();

// Wait for the 'error' event.
await errorPromise;

// Stop speech recognition.
recognition.stop();
}, 'Speech recognition onerror event is called.');
</script>
36 changes: 36 additions & 0 deletions speech-api/SpeechRecognition-onstart-onend.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<title>SpeechRecognition onstart and onend events</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();

// Promise that resolves when the 'start' event is fired.
const startPromise = new Promise(resolve => {
recognition.onstart = () => {
resolve();
};
});

// Promise that resolves when the 'end' event is fired.
const endPromise = new Promise(resolve => {
recognition.onend = () => {
resolve();
};
});

// Start speech recognition.
recognition.start();

// Wait for the 'start' event.
await startPromise;

// Stop speech recognition.
recognition.stop();

// Wait for the 'end' event.
await endPromise;
}, 'Speech recognition onstart and onend events are called.');
</script>

0 comments on commit 9ff4054

Please sign in to comment.