| <!DOCTYPE html> |
| <title>SpeechRecognition availableOnDevice</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; |
| |
| // Test that it returns a promise. |
| const resultPromise = SpeechRecognition.availableOnDevice(lang); |
| assert_true( |
| resultPromise instanceof Promise, |
| "availableOnDevice should return a Promise." |
| ); |
| |
| // Verify the resolved value is a string. |
| const result = await resultPromise; |
| assert_true( |
| typeof result === "string", |
| "The resolved value of the availableOnDevice promise should be a string." |
| ); |
| |
| assert_true( |
| result === "unavailable" || result === "downloadable" || |
| result === "downloading" || result === "available", |
| "The resolved value of the availableOnDevice promise should be a valid value." |
| ); |
| }, "SpeechRecognition.availableOnDevice resolves with a string value."); |
| |
| promise_test(async (t) => { |
| const iframe = document.createElement("iframe"); |
| document.body.appendChild(iframe); |
| const frameWindow = iframe.contentWindow; |
| const frameDOMException = frameWindow.DOMException; |
| const frameSpeechRecognition = |
| frameWindow.SpeechRecognition || frameWindow.webkitSpeechRecognition; |
| |
| iframe.remove(); |
| await promise_rejects_dom( |
| t, |
| "InvalidStateError", |
| frameDOMException, |
| frameSpeechRecognition.availableOnDevice("en-US"), |
| ); |
| }, "SpeechRecognition.availableOnDevice rejects in a detached context."); |
| </script> |