Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: re-enable the spellchecker when new language list set #26119

Merged
merged 2 commits into from Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions shell/browser/api/electron_api_session.cc
Expand Up @@ -957,6 +957,9 @@ void Session::SetSpellCheckerLanguages(
}
browser_context_->prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries,
language_codes);
// Enable spellcheck if > 0 languages, disable if no languages set
browser_context_->prefs()->SetBoolean(spellcheck::prefs::kSpellCheckEnable,
!languages.empty());
}

void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,
Expand Down
14 changes: 12 additions & 2 deletions spec-main/spec-helpers.ts
Expand Up @@ -2,9 +2,19 @@ import * as childProcess from 'child_process';
import * as path from 'path';
import * as http from 'http';
import * as v8 from 'v8';
import { SuiteFunction, TestFunction } from 'mocha';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff I just added because it was annoying me, you can now do ifdescribe().only


export const ifit = (condition: boolean) => (condition ? it : it.skip);
export const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip);
const addOnly = <T>(fn: Function): T => {
const wrapped = (...args: any[]) => {
return fn(...args);
};
(wrapped as any).only = wrapped;
(wrapped as any).skip = wrapped;
return wrapped as any;
};

export const ifit = (condition: boolean) => (condition ? it : addOnly<TestFunction>(it.skip));
export const ifdescribe = (condition: boolean) => (condition ? describe : addOnly<SuiteFunction>(describe.skip));

export const delay = (time: number = 0) => new Promise(resolve => setTimeout(resolve, time));

Expand Down
24 changes: 23 additions & 1 deletion spec-main/spellchecker-spec.ts
Expand Up @@ -15,9 +15,11 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
partition: `unique-spell-${Date.now()}`
}
});
w.webContents.session.setSpellCheckerLanguages(['en-US']);
await w.loadFile(path.resolve(__dirname, './fixtures/chromium/spellchecker.html'));
});

Expand Down Expand Up @@ -65,6 +67,26 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1);
});

ifit(shouldRun)('should detect incorrectly spelled words as incorrect after disabling all languages and re-enabling', async () => {
w.webContents.session.setSpellCheckerLanguages([]);
await delay(500);
w.webContents.session.setSpellCheckerLanguages(['en-US']);
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautifulllll asd asd"');
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu');
// Wait for spellchecker to load
await delay(500);
w.webContents.sendInputEvent({
type: 'mouseDown',
button: 'right',
x: 43,
y: 42
});
const contextMenuParams: Electron.ContextMenuParams = (await contextMenuPromise)[1];
expect(contextMenuParams.misspelledWord).to.eq('Beautifulllll');
expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1);
});

ifit(shouldRun)('should expose webFrame spellchecker correctly', async () => {
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautifulllll asd asd"');
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');
Expand Down