refactor: move text-to-speech out of chromium_src (#15024)

* chore: add tts patch and buildflag, makes tts work again

* chore: add tts patch and buildflag, makes tts work again

* fix: make things compile

* build: add relevant tts files for linux

* fix: update patch and patch description, should now compile on mac

* build: move chrome specific sources under chromium_src:chrome target

* build: enable_extensions again

We are depending on them, check `//electron/chromium_src:chrome` target
for more info.

* fix: update tts.patch to receive notifications about browser context destruction

* fix: extend browser process from chrome layer

The global state g_browser_process is shared between //chrome
and //electron.

* spec: add basic speech synthesis test

* spec: skip speech tests on ci

* build: fix compilation on windows
This commit is contained in:
Heilig Benedek 2018-10-11 15:52:12 +02:00 committed by Charles Kerr
parent 5788600c46
commit 95696c9456
39 changed files with 625 additions and 3139 deletions

View file

@ -1,4 +1,6 @@
const assert = require('assert')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const fs = require('fs')
const http = require('http')
const path = require('path')
@ -12,6 +14,9 @@ const { app, BrowserWindow, ipcMain, protocol, session, webContents } = remote
const isCI = remote.getGlobal('isCi')
const features = process.atomBinding('features')
const { expect } = chai
chai.use(dirtyChai)
/* Most of the APIs here don't use standard callbacks */
/* eslint-disable standard/no-callback-literal */
@ -1269,4 +1274,41 @@ describe('chromium feature', () => {
})
})
})
describe('SpeechSynthesis', () => {
before(function () {
if (isCI || !features.isTtsEnabled()) {
this.skip()
}
})
it('should emit lifecycle events', async () => {
const sentence = `long sentence which will take at least a few seconds to
utter so that it's possible to pause and resume before the end`
const utter = new SpeechSynthesisUtterance(sentence)
// Create a dummy utterence so that speech synthesis state
// is initialized for later calls.
speechSynthesis.speak(new SpeechSynthesisUtterance())
speechSynthesis.cancel()
speechSynthesis.speak(utter)
// paused state after speak()
expect(speechSynthesis.paused).to.be.false()
await new Promise((resolve) => { utter.onstart = resolve })
// paused state after start event
expect(speechSynthesis.paused).to.be.false()
speechSynthesis.pause()
// paused state changes async, right before the pause event
expect(speechSynthesis.paused).to.be.false()
await new Promise((resolve) => { utter.onpause = resolve })
expect(speechSynthesis.paused).to.be.true()
speechSynthesis.resume()
await new Promise((resolve) => { utter.onresume = resolve })
// paused state after resume event
expect(speechSynthesis.paused).to.be.false()
await new Promise((resolve) => { utter.onend = resolve })
})
})
})