| <!DOCTYPE html> |
| <title>SpeechRecognition installOnDevice</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; |
| |
| // Test that it returns a promise. |
| const validResultPromise = SpeechRecognition.installOnDevice(validLang); |
| assert_true( |
| validResultPromise instanceof Promise, |
| "installOnDevice 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 installOnDevice promise should be a boolean." |
| ); |
| |
| // Verify that the method returns true when called with a supported language code. |
| assert_equals( |
| validResult, |
| true, |
| "installOnDevice should resolve with `true` when called with a supported language code." |
| ); |
| |
| // Verify that the newly installed language pack is available. |
| const availableOnDeviceResultPromise = SpeechRecognition.availableOnDevice(validLang); |
| assert_true( |
| availableOnDeviceResultPromise instanceof Promise, |
| "availableOnDevice should return a Promise." |
| ); |
| |
| const availableOnDeviceResult = await availableOnDeviceResultPromise; |
| assert_true( |
| typeof availableOnDeviceResult === "string", |
| "The resolved value of the availableOnDevice promise should be a string." |
| ); |
| |
| assert_true(availableOnDeviceResult === "available", |
| "The resolved value of the availableOnDevice promise should be available." |
| ); |
| |
| // Verify that installing an already installed language pack resolves to true. |
| const secondResultPromise = SpeechRecognition.installOnDevice(validLang); |
| const secondResult = await secondResultPromise; |
| assert_equals( |
| secondResult, |
| true, |
| "installOnDevice should resolve with `true` if the language is already installed." |
| ); |
| |
| // Test that it returns a promise. |
| const invalidResultPromise = SpeechRecognition.installOnDevice(invalidLang); |
| const invalidResult = await invalidResultPromise; |
| assert_equals( |
| invalidResult, |
| false, |
| "installOnDevice should resolve with `false` when called with an unsupported language code." |
| ); |
| }, "SpeechRecognition.installOnDevice resolves with a boolean 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.installOnDevice("en-US"), |
| ); |
| }, "SpeechRecognition.installOnDevice rejects in a detached context."); |
| </script> |