forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WPT for installOnDeviceSpeechRecognition and onDeviceSpeechRecogn…
…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
1 parent
7134137
commit 4df4ce2
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
speech-api/SpeechRecognition-installOnDeviceSpeechRecognition.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
speech-api/SpeechRecognition-onDeviceWebSpeechAvailable.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |