-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add static SpeechRecognition isSourceSupported()
Spec issue: WebAudio/web-speech-api#126 Change-Id: I07b5551dcd570d32687e13fa0aa62adce16d0a0a Bug: 40286514
- Loading branch information
1 parent
4ea529d
commit 5b35f2c
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
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,66 @@ | ||
<!DOCTYPE html> | ||
<title>SpeechRecognition isSourceSupported</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
promise_test(async (t) => { | ||
window.SpeechRecognition = | ||
window.SpeechRecognition || window.webkitSpeechRecognition; | ||
|
||
// Ensure the isSourceSupported static method exists. | ||
assert_true( | ||
"isSourceSupported" in SpeechRecognition, | ||
"SpeechRecognition should have the isSourceSupported static method.", | ||
); | ||
|
||
// Verify the resolved supported value is true and options value match when source is valid. | ||
for (const source of ["microphone", "mediastreamtrack"]) { | ||
const resultPromise = SpeechRecognition.isSourceSupported({ source }); | ||
assert_true( | ||
resultPromise instanceof Promise, | ||
"isSourceSupported should return a Promise.", | ||
); | ||
|
||
const { supported, options } = await resultPromise; | ||
assert_true( | ||
supported, | ||
`The resolved supported value of the isSourceSupported promise should be true when source is "${source}".`, | ||
); | ||
assert_equals( | ||
options.source, | ||
source, | ||
`The resolved options source value of the isSourceSupported promise should be equal to "${source}".`, | ||
); | ||
} | ||
|
||
// Verify the resolved supported value is false and options value match when source is invalid. | ||
for (const source of ["foo", "Microphone", "", null]) { | ||
const resultPromise = SpeechRecognition.isSourceSupported({ source }); | ||
assert_true( | ||
resultPromise instanceof Promise, | ||
"isSourceSupported should return a Promise.", | ||
); | ||
|
||
const { supported, options } = await resultPromise; | ||
assert_false( | ||
supported, | ||
`The resolved supported value of the isSourceSupported promise should be false when source is "${source}".`, | ||
); | ||
assert_equals( | ||
options.source, | ||
String(source), | ||
`The resolved options source value of the isSourceSupported promise should be equal to "${source}".`, | ||
); | ||
} | ||
|
||
// Verify promise rejects with TypeError when options is invalid. | ||
for (const options of [undefined, null, {}, "foo", { source: undefined }]) { | ||
await promise_rejects_js( | ||
t, | ||
TypeError, | ||
SpeechRecognition.isSourceSupported(options), | ||
`isSourceSupported promise should reject with TypeError if options is ${JSON.stringify(options)}.`, | ||
); | ||
} | ||
}); | ||
</script> |