feat: Expose renderer spellcheck API (#25060)

This commit is contained in:
Lishid 2020-10-19 07:48:16 -04:00 committed by GitHub
parent 321395d96e
commit 05b5c197ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 2 deletions

View file

@ -13,7 +13,10 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
beforeEach(async () => {
w = new BrowserWindow({
show: false
show: false,
webPreferences: {
nodeIntegration: true
}
});
await w.loadFile(path.resolve(__dirname, './fixtures/chromium/spellchecker.html'));
});
@ -62,6 +65,20 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
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()');
// Wait for spellchecker to load
await delay(500);
const callWebFrameFn = (expr: string) => w.webContents.executeJavaScript('require("electron").webFrame.' + expr);
expect(await callWebFrameFn('isWordMisspelled("test")')).to.equal(false);
expect(await callWebFrameFn('isWordMisspelled("testt")')).to.equal(true);
expect(await callWebFrameFn('getWordSuggestions("test")')).to.be.empty();
expect(await callWebFrameFn('getWordSuggestions("testt")')).to.not.be.empty();
});
describe('custom dictionary word list API', () => {
let ses: Session;