|
| 1 | +// Copyright 2025 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import {assert} from 'chai'; |
| 6 | + |
| 7 | +import { |
| 8 | + clickNthChildOfSelectedElementNode, |
| 9 | + getElementStyleFontEditorButton, |
| 10 | + getFontEditorButtons, |
| 11 | + getHiddenFontEditorButtons, |
| 12 | + waitForContentOfSelectedElementsNode, |
| 13 | + waitForCSSPropertyValue, |
| 14 | +} from '../../e2e/helpers/elements-helpers.js'; |
| 15 | +import type {DevToolsPage} from '../shared/frontend-helper.js'; |
| 16 | +import type {InspectedPage} from '../shared/target-helper.js'; |
| 17 | + |
| 18 | +async function goToTestPageAndSelectTestElement( |
| 19 | + inspectedPage: InspectedPage, devToolsPage: DevToolsPage, path = 'inline_editor/fontEditor.html') { |
| 20 | + await inspectedPage.goToResource(path); |
| 21 | + // Wait for the body to be selected |
| 22 | + await waitForContentOfSelectedElementsNode('<body>\u200B', devToolsPage); |
| 23 | + // Select the first child of the body, which is the div with the test styles |
| 24 | + await clickNthChildOfSelectedElementNode(1, devToolsPage); |
| 25 | +} |
| 26 | + |
| 27 | +async function openFontEditorForInlineStyle(devToolsPage: DevToolsPage) { |
| 28 | + const fontEditorButton = await getElementStyleFontEditorButton(devToolsPage); |
| 29 | + if (!fontEditorButton) { |
| 30 | + throw new Error('Missing font editor button in the element style section'); |
| 31 | + } |
| 32 | + await fontEditorButton.click(); |
| 33 | + await devToolsPage.waitFor('.font-selector-section'); |
| 34 | +} |
| 35 | + |
| 36 | +describe('The font editor', function() { |
| 37 | + setup({ |
| 38 | + enabledDevToolsExperiments: ['font-editor'], |
| 39 | + }); |
| 40 | + |
| 41 | + async function setupFontEditorTest(inspectedPage: InspectedPage, devToolsPage: DevToolsPage) { |
| 42 | + await goToTestPageAndSelectTestElement(inspectedPage, devToolsPage); |
| 43 | + await waitForCSSPropertyValue('#inspected', 'color', 'red', undefined, devToolsPage); |
| 44 | + } |
| 45 | + |
| 46 | + it('icon is displayed for sections containing font properties', async ({devToolsPage, inspectedPage}) => { |
| 47 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 48 | + const fontEditorButtons = await getFontEditorButtons(devToolsPage); |
| 49 | + const hiddenFontEditorButtons = await getHiddenFontEditorButtons(devToolsPage); |
| 50 | + assert.lengthOf(fontEditorButtons, 5); |
| 51 | + assert.lengthOf(hiddenFontEditorButtons, 2); |
| 52 | + }); |
| 53 | + |
| 54 | + it('opens when button is clicked', async ({devToolsPage, inspectedPage}) => { |
| 55 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 56 | + await openFontEditorForInlineStyle(devToolsPage); |
| 57 | + }); |
| 58 | + |
| 59 | + it('is properly applying font family changes to the style section', async ({devToolsPage, inspectedPage}) => { |
| 60 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 61 | + await openFontEditorForInlineStyle(devToolsPage); |
| 62 | + const fontFamilySelector = await devToolsPage.waitFor('[aria-label="Font Family"]'); |
| 63 | + await fontFamilySelector.focus(); |
| 64 | + await devToolsPage.typeText('a'); |
| 65 | + await waitForCSSPropertyValue('element.style', 'font-family', 'Arial', undefined, devToolsPage); |
| 66 | + }); |
| 67 | + |
| 68 | + it('is properly applying slider input changes to the style section', async ({devToolsPage, inspectedPage}) => { |
| 69 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 70 | + await openFontEditorForInlineStyle(devToolsPage); |
| 71 | + const fontSizeSliderInput = await devToolsPage.waitFor('[aria-label="font-size Slider Input"]'); |
| 72 | + await fontSizeSliderInput.focus(); |
| 73 | + await devToolsPage.pressKey('ArrowRight'); |
| 74 | + await waitForCSSPropertyValue('element.style', 'font-size', '11px', undefined, devToolsPage); |
| 75 | + }); |
| 76 | + |
| 77 | + it('is properly applying text input changes to the style section', async ({devToolsPage, inspectedPage}) => { |
| 78 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 79 | + await openFontEditorForInlineStyle(devToolsPage); |
| 80 | + const fontSizeTextInput = await devToolsPage.waitFor('[aria-label="font-size Text Input"]'); |
| 81 | + await fontSizeTextInput.focus(); |
| 82 | + await devToolsPage.pressKey('ArrowUp'); |
| 83 | + await waitForCSSPropertyValue('element.style', 'font-size', '11px', undefined, devToolsPage); |
| 84 | + }); |
| 85 | + |
| 86 | + it('is properly applying selector key values to the style section', async ({devToolsPage, inspectedPage}) => { |
| 87 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 88 | + await openFontEditorForInlineStyle(devToolsPage); |
| 89 | + const fontWeightSelectorInput = await devToolsPage.waitFor('[aria-label="font-weight Key Value Selector"]'); |
| 90 | + await fontWeightSelectorInput.focus(); |
| 91 | + await devToolsPage.typeText('i'); |
| 92 | + await waitForCSSPropertyValue('element.style', 'font-weight', 'inherit', undefined, devToolsPage); |
| 93 | + }); |
| 94 | + |
| 95 | + it('is properly converting units and applying changes to the styles section', |
| 96 | + async ({devToolsPage, inspectedPage}) => { |
| 97 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 98 | + await openFontEditorForInlineStyle(devToolsPage); |
| 99 | + const fontSizeUnitInput = await devToolsPage.waitFor('[aria-label="font-size Unit Input"]'); |
| 100 | + await fontSizeUnitInput.focus(); |
| 101 | + await devToolsPage.typeText('e'); |
| 102 | + await waitForCSSPropertyValue('element.style', 'font-size', '0.6em', undefined, devToolsPage); |
| 103 | + }); |
| 104 | + |
| 105 | + it('computed font list is being generated correctly', async ({devToolsPage, inspectedPage}) => { |
| 106 | + await setupFontEditorTest(inspectedPage, devToolsPage); |
| 107 | + await openFontEditorForInlineStyle(devToolsPage); |
| 108 | + await devToolsPage.waitFor('[value="testFont"]'); |
| 109 | + }); |
| 110 | +}); |
0 commit comments