Commit e6753b72 authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

ChromeVox voice switching: fix crash when checking available voices.

This patch fixes a crash that occurred when checking the available
voices. Previously, we were assuming that TtsVoice objects, returned by
chrome.tts.getVoices(), had a certain structure e.g. that the voice
property was always set. This is not always the case, and the
documentation states that all properties are actually optional.

We now perform an error check before accessing TtsVoice.lang, which
was the root of the issue. The test suite has been updated to check
this case as well.

Bug: 923068
Change-Id: I5936ab683c46add944bd915b7722733dbdf761bd
Relnotes: N/A
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2163153
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762095}
parent 89da4be9
...@@ -115,6 +115,9 @@ LocaleOutputHelper = class { ...@@ -115,6 +115,9 @@ LocaleOutputHelper = class {
const targetLanguage = components[0]; const targetLanguage = components[0];
for (const voice of this.availableVoices_) { for (const voice of this.availableVoices_) {
if (!voice.lang) {
continue;
}
const candidateLanguage = voice.lang.toLowerCase().split('-')[0]; const candidateLanguage = voice.lang.toLowerCase().split('-')[0];
if (candidateLanguage === targetLanguage) { if (candidateLanguage === targetLanguage) {
return true; return true;
......
...@@ -38,9 +38,11 @@ ChromeVoxLocaleOutputHelperTest = class extends ChromeVoxNextE2ETest { ...@@ -38,9 +38,11 @@ ChromeVoxLocaleOutputHelperTest = class extends ChromeVoxNextE2ETest {
// Mock this api to return a predefined set of voices. // Mock this api to return a predefined set of voices.
chrome.tts.getVoices = function(callback) { chrome.tts.getVoices = function(callback) {
callback([ callback([
{'lang': 'en-US'}, {'lang': 'fr-CA'}, {'lang': 'es-ES'}, // All properties of TtsVoice object are optional.
{'lang': 'it-IT'}, {'lang': 'ja-JP'}, {'lang': 'ko-KR'}, // https://developer.chrome.com/apps/tts#type-TtsVoice.
{'lang': 'zh-TW'}, {'lang': 'ast'}, {'lang': 'pt'} {}, {voiceName: 'Android'}, {'lang': 'en-US'}, {'lang': 'fr-CA'},
{'lang': 'es-ES'}, {'lang': 'it-IT'}, {'lang': 'ja-JP'},
{'lang': 'ko-KR'}, {'lang': 'zh-TW'}, {'lang': 'ast'}, {'lang': 'pt'}
]); ]);
}; };
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment