|
@@ -1410,6 +1410,111 @@ describe('chromium feature', () => {
|
|
|
await new Promise((resolve) => { utter.onend = resolve })
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('focus handling', () => {
|
|
|
+ let webviewContents = null
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: true
|
|
|
+ })
|
|
|
+
|
|
|
+ const webviewReady = emittedOnce(w.webContents, 'did-attach-webview')
|
|
|
+ await w.loadFile(path.join(fixtures, 'pages', 'tab-focus-loop-elements.html'))
|
|
|
+ const [, wvContents] = await webviewReady
|
|
|
+ webviewContents = wvContents
|
|
|
+ await emittedOnce(webviewContents, 'did-finish-load')
|
|
|
+ w.focus()
|
|
|
+ })
|
|
|
+
|
|
|
+ afterEach(() => {
|
|
|
+ webviewContents = null
|
|
|
+ })
|
|
|
+
|
|
|
+ const expectFocusChange = async () => {
|
|
|
+ const [, focusedElementId] = await emittedOnce(ipcMain, 'focus-changed')
|
|
|
+ return focusedElementId
|
|
|
+ }
|
|
|
+
|
|
|
+ describe('a TAB press', () => {
|
|
|
+ const tabPressEvent = {
|
|
|
+ type: 'keyDown',
|
|
|
+ keyCode: 'Tab'
|
|
|
+ }
|
|
|
+
|
|
|
+ it('moves focus to the next focusable item', async () => {
|
|
|
+ let focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(tabPressEvent)
|
|
|
+ let focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-1', `should start focused in element-1, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(tabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-2', `focus should've moved to element-2, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(tabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-wv-element-1', `focus should've moved to the webview's element-1, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ webviewContents.sendInputEvent(tabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-wv-element-2', `focus should've moved to the webview's element-2, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ webviewContents.sendInputEvent(tabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-3', `focus should've moved to element-3, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(tabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-1', `focus should've looped back to element-1, it's instead in ${focusedElementId}`)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('a SHIFT + TAB press', () => {
|
|
|
+ const shiftTabPressEvent = {
|
|
|
+ type: 'keyDown',
|
|
|
+ modifiers: ['Shift'],
|
|
|
+ keyCode: 'Tab'
|
|
|
+ }
|
|
|
+
|
|
|
+ it('moves focus to the previous focusable item', async () => {
|
|
|
+ let focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(shiftTabPressEvent)
|
|
|
+ let focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-3', `should start focused in element-3, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(shiftTabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-wv-element-2', `focus should've moved to the webview's element-2, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ webviewContents.sendInputEvent(shiftTabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-wv-element-1', `focus should've moved to the webview's element-1, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ webviewContents.sendInputEvent(shiftTabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-2', `focus should've moved to element-2, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(shiftTabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-1', `focus should've moved to element-1, it's instead in ${focusedElementId}`)
|
|
|
+
|
|
|
+ focusChange = expectFocusChange()
|
|
|
+ w.webContents.sendInputEvent(shiftTabPressEvent)
|
|
|
+ focusedElementId = await focusChange
|
|
|
+ assert.strictEqual(focusedElementId, 'BUTTON-element-3', `focus should've looped back to element-3, it's instead in ${focusedElementId}`)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('font fallback', () => {
|