|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import assert from 'assert'; |
| 7 | +import { mock } from '../../../../../base/test/common/mock.js'; |
| 8 | +import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js'; |
| 9 | +import { IEnvironmentService } from '../../../../../platform/environment/common/environment.js'; |
| 10 | +import { Registry } from '../../../../../platform/registry/common/platform.js'; |
| 11 | +import { editorInfoForeground, editorWarningForeground } from '../../../../../platform/theme/common/colorRegistry.js'; |
| 12 | +import { ColorScheme } from '../../../../../platform/theme/common/theme.js'; |
| 13 | +import { Extensions, IThemingRegistry } from '../../../../../platform/theme/common/themeService.js'; |
| 14 | +import { ColorThemeData } from '../../../../services/themes/common/colorThemeData.js'; |
| 15 | +import { registerColors } from '../../browser/debugColors.js'; |
| 16 | + |
| 17 | +const themingRegistry = Registry.as<IThemingRegistry>(Extensions.ThemingContribution); |
| 18 | +const participantIndex = themingRegistry.getThemingParticipants().length; |
| 19 | +registerColors(); |
| 20 | +const debugThemingParticipant = themingRegistry.getThemingParticipants()[participantIndex]; |
| 21 | + |
| 22 | +suite('Debug Colors', () => { |
| 23 | + ensureNoDisposablesAreLeakedInTestSuite(); |
| 24 | + |
| 25 | + test('debug console info and warning colors do not inherit transparent editor diagnostic customizations', () => { |
| 26 | + const themes = [ |
| 27 | + { type: ColorScheme.DARK, info: '#59a4f9', warning: '#cca700' }, |
| 28 | + { type: ColorScheme.LIGHT, info: '#0063d3', warning: '#bf8803' }, |
| 29 | + { type: ColorScheme.HIGH_CONTRAST_DARK, info: '#ffffff', warning: '#008000' }, |
| 30 | + { type: ColorScheme.HIGH_CONTRAST_LIGHT, info: '#292929', warning: '#895503' }, |
| 31 | + ]; |
| 32 | + |
| 33 | + assert.deepStrictEqual(themes.map(({ type }) => { |
| 34 | + const theme = ColorThemeData.createUnloadedThemeForThemeType(type); |
| 35 | + theme.setCustomColors({ [editorInfoForeground]: '#00000000', [editorWarningForeground]: '#00000000' }); |
| 36 | + return [ |
| 37 | + theme.getColor('debugConsole.infoForeground')?.toString(), |
| 38 | + theme.getColor('debugConsole.warningForeground')?.toString() |
| 39 | + ]; |
| 40 | + }), themes.map(({ info, warning }) => [info, warning])); |
| 41 | + }); |
| 42 | + |
| 43 | + test('preserves theme-defined diagnostic colors despite editor customizations', () => { |
| 44 | + const themes = [ |
| 45 | + { type: ColorScheme.DARK, info: '#17ff12', warning: '#ff1212' }, |
| 46 | + { type: ColorScheme.LIGHT, info: '#17ff12', warning: '#ff1212' }, |
| 47 | + { type: ColorScheme.HIGH_CONTRAST_DARK, info: '#ffffff', warning: '#008000' }, |
| 48 | + { type: ColorScheme.HIGH_CONTRAST_LIGHT, info: '#292929', warning: '#ff1212' }, |
| 49 | + ]; |
| 50 | + |
| 51 | + assert.deepStrictEqual(themes.map(({ type }) => { |
| 52 | + const theme = ColorThemeData.createUnloadedThemeForThemeType(type, { |
| 53 | + [editorInfoForeground]: '#17ff12', |
| 54 | + [editorWarningForeground]: '#ff1212', |
| 55 | + }); |
| 56 | + theme.setCustomColors({ [editorInfoForeground]: '#00000000', [editorWarningForeground]: '#00000000' }); |
| 57 | + return [ |
| 58 | + theme.getColor('debugConsole.infoForeground')?.toString(), |
| 59 | + theme.getColor('debugConsole.warningForeground')?.toString() |
| 60 | + ]; |
| 61 | + }), themes.map(({ info, warning }) => [info, warning])); |
| 62 | + }); |
| 63 | + |
| 64 | + test('explicit console colors override theme colors and appear in the generated styles', () => { |
| 65 | + const theme = ColorThemeData.createUnloadedThemeForThemeType(ColorScheme.DARK, { |
| 66 | + [editorInfoForeground]: '#17ff12', |
| 67 | + [editorWarningForeground]: '#ff1212', |
| 68 | + 'debugConsole.infoForeground': '#112233', |
| 69 | + 'debugConsole.warningForeground': '#445566', |
| 70 | + }); |
| 71 | + const themeColors = [ |
| 72 | + theme.getColor('debugConsole.infoForeground')?.toString(), |
| 73 | + theme.getColor('debugConsole.warningForeground')?.toString() |
| 74 | + ]; |
| 75 | + theme.setCustomColors({ |
| 76 | + [editorInfoForeground]: '#00000000', |
| 77 | + [editorWarningForeground]: '#00000000', |
| 78 | + 'debugConsole.infoForeground': '#123456', |
| 79 | + 'debugConsole.warningForeground': '#abcdef', |
| 80 | + }); |
| 81 | + const rules: string[] = []; |
| 82 | + const environment = new class extends mock<IEnvironmentService>() { }; |
| 83 | + debugThemingParticipant(theme, { addRule: rule => rules.push(rule) }, environment); |
| 84 | + const css = rules.join('\n'); |
| 85 | + |
| 86 | + assert.deepStrictEqual([ |
| 87 | + ...themeColors, |
| 88 | + theme.getColor('debugConsole.infoForeground')?.toString(), |
| 89 | + theme.getColor('debugConsole.warningForeground')?.toString(), |
| 90 | + ...['info', 'warn'].map(severity => css.match(new RegExp(`\\.value\\.${severity} \\{\\s*color: (?<color>[^;]+);`))?.groups?.color) |
| 91 | + ], ['#112233', '#445566', '#123456', '#abcdef', '#123456', '#abcdef']); |
| 92 | + }); |
| 93 | +}); |
0 commit comments