From 5c8187f5da9a31f4876427ea29a3e87c417f2687 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Tue, 6 Nov 2018 13:30:32 -0800 Subject: [PATCH] another test --- atom/browser/font_defaults.cc | 12 ++++++++ spec/chromium-spec.js | 56 ++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/atom/browser/font_defaults.cc b/atom/browser/font_defaults.cc index fb8c496254158..85e57feb9d708 100644 --- a/atom/browser/font_defaults.cc +++ b/atom/browser/font_defaults.cc @@ -16,6 +16,14 @@ namespace { +// The following list of font defaults was copied from +// https://chromium.googlesource.com/chromium/src/+/69.0.3497.106/chrome/browser/ui/prefs/prefs_tab_helper.cc#152 +// +// The only updates that should be made to this list are copying updates that +// were made in Chromium. +// +// vvvvv DO NOT EDIT vvvvv + struct FontDefault { const char* pref_name; int resource_id; @@ -97,6 +105,8 @@ const FontDefault kFontDefaults[] = { }; const size_t kFontDefaultsLength = arraysize(kFontDefaults); +// ^^^^^ DO NOT EDIT ^^^^^ + std::string GetDefaultFontForPref(const char* pref_name) { for (size_t i = 0; i < kFontDefaultsLength; ++i) { FontDefault pref = kFontDefaults[i]; @@ -115,6 +125,8 @@ using ScriptFontMap = std::unordered_map; // Key comparison uses pointer equality. using FontFamilyMap = std::unordered_map; +// A lookup table mapping (font-family, script) -> font-name +// e.g. ("sans-serif", "Zyyy") -> "Arial" FontFamilyMap g_font_cache; base::string16 FetchFont(const char* script, const char* map_name) { diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 15276223ed3e1..195720d8fd33b 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -1315,24 +1315,9 @@ describe('chromium feature', () => { }) describe('font fallback', () => { - it('should fall back to non-PingFang SC font for sans-serif japanese script', async () => { + async function getRenderedFonts (html) { 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 @@ -1344,12 +1329,43 @@ describe('font fallback', () => { }) 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) + const { fonts } = await sendCommand('CSS.getPlatformFontsForNode', { nodeId }) + return fonts } finally { w.close() } + } + + it('should use Helvetica for sans-serif on mac, and Arial on windows and linux', async () => { + const html = `test` + const fonts = await getRenderedFonts(html) + expect(fonts).to.be.an('array') + expect(fonts).to.have.length(1) + expect(fonts[0].familyName).to.equal({ + 'win32': 'Arial', + 'darwin': 'Helvetica', + 'linux': 'Arial' + }[process.platform]) + }) + + it('should fall back to non-PingFang SC font for sans-serif japanese script', async () => { + if (process.platform === 'linux') { + return this.skip() + } + const html = ` + + + + + test 智史 + + ` + const fonts = await getRenderedFonts(html) + expect(fonts).to.be.an('array') + expect(fonts).to.have.length(1) + expect(fonts[0].familyName).to.equal({ + 'win32': 'Meiryo', + 'darwin': 'Hiragino Kaku Gothic ProN' + }[process.platform]) }) })