From 4e2d7494bd672d5ff1b590cf5d372605a7309bae Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 5 Nov 2018 17:55:56 -0800 Subject: [PATCH] add test --- spec/chromium-spec.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 5cf0645699862..15276223ed3e1 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -10,6 +10,7 @@ const ChildProcess = require('child_process') const { ipcRenderer, remote } = require('electron') const { closeWindow } = require('./window-helpers') const { resolveGetters } = require('./assert-helpers') +const { emittedOnce } = require('./events-helpers') const { app, BrowserWindow, ipcMain, protocol, session, webContents } = remote const isCI = remote.getGlobal('isCi') const features = process.atomBinding('features') @@ -1312,3 +1313,43 @@ describe('chromium feature', () => { }) }) }) + +describe('font fallback', () => { + it('should fall back to non-PingFang SC font for sans-serif japanese script', async () => { + const w = new BrowserWindow({ show: false }) + try { + const html = ` + + + + + + test 智史 + + + ` + const fallbackFontJa = { + 'win32': 'Meiryo', + 'darwin': 'Hiragino Kaku Gothic ProN', + 'linux': 'VL PGothic' + }[process.platform] + const loaded = emittedOnce(w.webContents, 'did-finish-load') + w.loadURL(`data:text/html,${html}`) + await loaded + w.webContents.debugger.attach() + const sendCommand = (...args) => new Promise((resolve, reject) => { + w.webContents.debugger.sendCommand(...args, (e, r) => { + if (e) { reject(e) } else { resolve(r) } + }) + }) + const { nodeId } = (await sendCommand('DOM.getDocument')).root.children[0] + await sendCommand('CSS.enable') + const { fonts } = await sendCommand('CSS.getPlatformFontsForNode', {nodeId}) + expect(fonts).to.be.an('array') + expect(fonts).to.have.length(1) + expect(fonts[0].familyName).to.equal(fallbackFontJa) + } finally { + w.close() + } + }) +})