Skip to content

Commit

Permalink
Add WPT for installOnDeviceSpeechRecognition and onDeviceSpeechRecogn…
Browse files Browse the repository at this point in the history
…itionAvailable

This CL adds web platform tests for the installOnDeviceSpeechRecognition and onDeviceSpeechRecognitionAvailable methods of the Web Speech API.

Change-Id: If3c9d54bca005dbbd8aa625df5821884761a446e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6150488
Commit-Queue: Evan Liu <evliu@google.com>
Reviewed-by: Frank Liberato <liberato@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1403950}
  • Loading branch information
evliu-google authored and chromium-wpt-export-bot committed Jan 9, 2025
1 parent 7134137 commit 4df4ce2
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<title>SpeechRecognition installOnDeviceSpeechRecognition</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async (t) => {
const validLang = "en-US";
const invalidLang = "invalid language code";
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const speechRecognition = new SpeechRecognition();

// Ensure the installOnDeviceSpeechRecognition method exists.
assert_true(
"installOnDeviceSpeechRecognition" in speechRecognition,
"SpeechRecognition should have the installOnDeviceSpeechRecognition method."
);

// Test that it returns a promise.
const validResultPromise = speechRecognition.installOnDeviceSpeechRecognition(validLang);
assert_true(
validResultPromise instanceof Promise,
"installOnDeviceSpeechRecognition should return a Promise."
);

// Verify the resolved value is a boolean.
const validResult = await validResultPromise;
assert_true(
typeof validResult === "boolean",
"The resolved value of the installOnDeviceSpeechRecognition promise should be a boolean."
);

// Verify that the method returns true when called with a supported language code.
assert_equals(
validResult,
true,
"installOnDeviceSpeechRecognition should resolve with `true` when called with a supported language code."
);

// Test that it returns a promise.
const invalidResultPromise = speechRecognition.installOnDeviceSpeechRecognition(invalidLang);
const invalidResult = await invalidResultPromise;
assert_equals(
invalidResult,
false,
"installOnDeviceSpeechRecognition should resolve with `false` when called with an unsupported language code."
);
}, "SpeechRecognition.installOnDeviceSpeechRecognition resolves with a boolean value.");
</script>
38 changes: 38 additions & 0 deletions speech-api/SpeechRecognition-onDeviceWebSpeechAvailable.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<title>SpeechRecognition onDeviceWebSpeechAvailable</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async (t) => {
const lang = "en-US";
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const speechRecognition = new SpeechRecognition();

// Ensure the onDeviceWebSpeechAvailable method exists.
assert_true(
"onDeviceWebSpeechAvailable" in speechRecognition,
"SpeechRecognition should have the onDeviceWebSpeechAvailable method."
);

// Test that it returns a promise.
const resultPromise = speechRecognition.onDeviceWebSpeechAvailable(lang);
assert_true(
resultPromise instanceof Promise,
"onDeviceWebSpeechAvailable should return a Promise."
);

// Verify the resolved value is a boolean.
const result = await resultPromise;
assert_true(
typeof result === "boolean",
"The resolved value of the onDeviceWebSpeechAvailable promise should be a boolean."
);

// Verify that method returns false if on-device speech recognition is not installed.
assert_equals(
result,
false,
"onDeviceWebSpeechAvailable should resolve with `false` if on-device speech recognition is not installed."
);
}, "SpeechRecognition.onDeviceWebSpeechAvailable resolves with a boolean value.");
</script>

0 comments on commit 4df4ce2

Please sign in to comment.