chore: make macOS spellchecker fns formal no-ops (#35514)
* chore: make macOS spellchecker fns formal no-ops * docs: correct no-op note * test: add no-op specs
This commit is contained in:
parent
bf20aabb9e
commit
38a7da692a
3 changed files with 43 additions and 1 deletions
|
@ -986,7 +986,7 @@ Returns `string[]` - An array of language codes the spellchecker is enabled for.
|
||||||
will fallback to using `en-US`. By default on launch if this setting is an empty list Electron will try to populate this
|
will fallback to using `en-US`. By default on launch if this setting is an empty list Electron will try to populate this
|
||||||
setting with the current OS locale. This setting is persisted across restarts.
|
setting with the current OS locale. This setting is persisted across restarts.
|
||||||
|
|
||||||
**Note:** On macOS the OS spellchecker is used and has its own list of languages. This API is a no-op on macOS.
|
**Note:** On macOS the OS spellchecker is used and has its own list of languages. On macOS, this API will return whichever languages have been configured by the OS.
|
||||||
|
|
||||||
#### `ses.setSpellCheckerDictionaryDownloadURL(url)`
|
#### `ses.setSpellCheckerDictionaryDownloadURL(url)`
|
||||||
|
|
||||||
|
|
|
@ -1043,6 +1043,7 @@ base::Value Session::GetSpellCheckerLanguages() {
|
||||||
void Session::SetSpellCheckerLanguages(
|
void Session::SetSpellCheckerLanguages(
|
||||||
gin_helper::ErrorThrower thrower,
|
gin_helper::ErrorThrower thrower,
|
||||||
const std::vector<std::string>& languages) {
|
const std::vector<std::string>& languages) {
|
||||||
|
#if !BUILDFLAG(IS_MAC)
|
||||||
base::Value::List language_codes;
|
base::Value::List language_codes;
|
||||||
for (const std::string& lang : languages) {
|
for (const std::string& lang : languages) {
|
||||||
std::string code = spellcheck::GetCorrespondingSpellCheckLanguage(lang);
|
std::string code = spellcheck::GetCorrespondingSpellCheckLanguage(lang);
|
||||||
|
@ -1058,10 +1059,12 @@ void Session::SetSpellCheckerLanguages(
|
||||||
// Enable spellcheck if > 0 languages, disable if no languages set
|
// Enable spellcheck if > 0 languages, disable if no languages set
|
||||||
browser_context_->prefs()->SetBoolean(spellcheck::prefs::kSpellCheckEnable,
|
browser_context_->prefs()->SetBoolean(spellcheck::prefs::kSpellCheckEnable,
|
||||||
!languages.empty());
|
!languages.empty());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,
|
void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,
|
||||||
const GURL& url) {
|
const GURL& url) {
|
||||||
|
#if !BUILDFLAG(IS_MAC)
|
||||||
if (!url.is_valid()) {
|
if (!url.is_valid()) {
|
||||||
thrower.ThrowError(
|
thrower.ThrowError(
|
||||||
"The URL you provided to setSpellCheckerDictionaryDownloadURL is not a "
|
"The URL you provided to setSpellCheckerDictionaryDownloadURL is not a "
|
||||||
|
@ -1069,6 +1072,7 @@ void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SpellcheckHunspellDictionary::SetBaseDownloadURL(url);
|
SpellcheckHunspellDictionary::SetBaseDownloadURL(url);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ListWordsInSpellCheckerDictionary() {
|
v8::Local<v8::Promise> Session::ListWordsInSpellCheckerDictionary() {
|
||||||
|
|
|
@ -212,6 +212,44 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', function ()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ses.setSpellCheckerLanguages', () => {
|
||||||
|
const isMac = process.platform === 'darwin';
|
||||||
|
|
||||||
|
ifit(isMac)('should be a no-op when setSpellCheckerLanguages is called on macOS', () => {
|
||||||
|
expect(() => {
|
||||||
|
w.webContents.session.setSpellCheckerLanguages(['i-am-a-nonexistent-language']);
|
||||||
|
}).to.not.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
ifit(!isMac)('should throw when a bad language is passed', () => {
|
||||||
|
expect(() => {
|
||||||
|
w.webContents.session.setSpellCheckerLanguages(['i-am-a-nonexistent-language']);
|
||||||
|
}).to.throw(/Invalid language code provided: "i-am-a-nonexistent-language" is not a valid language code/);
|
||||||
|
});
|
||||||
|
|
||||||
|
ifit(!isMac)('should not throw when a recognized language is passed', () => {
|
||||||
|
expect(() => {
|
||||||
|
w.webContents.session.setSpellCheckerLanguages(['es']);
|
||||||
|
}).to.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SetSpellCheckerDictionaryDownloadURL', () => {
|
||||||
|
const isMac = process.platform === 'darwin';
|
||||||
|
|
||||||
|
ifit(isMac)('should be a no-op when a bad url is passed on macOS', () => {
|
||||||
|
expect(() => {
|
||||||
|
w.webContents.session.setSpellCheckerDictionaryDownloadURL('i-am-not-a-valid-url');
|
||||||
|
}).to.not.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
ifit(!isMac)('should throw when a bad url is passed', () => {
|
||||||
|
expect(() => {
|
||||||
|
w.webContents.session.setSpellCheckerDictionaryDownloadURL('i-am-not-a-valid-url');
|
||||||
|
}).to.throw(/The URL you provided to setSpellCheckerDictionaryDownloadURL is not a valid URL/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ses.removeWordFromSpellCheckerDictionary', () => {
|
describe('ses.removeWordFromSpellCheckerDictionary', () => {
|
||||||
it('should successfully remove words to custom dictionary', async () => {
|
it('should successfully remove words to custom dictionary', async () => {
|
||||||
const result1 = ses.addWordToSpellCheckerDictionary('foobar');
|
const result1 = ses.addWordToSpellCheckerDictionary('foobar');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue