diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/inspector/fonts/test/browser_fontinspector_editor-letter-spacing-conversion.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | devtools/client/inspector/fonts/test/browser_fontinspector_editor-letter-spacing-conversion.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/devtools/client/inspector/fonts/test/browser_fontinspector_editor-letter-spacing-conversion.js b/devtools/client/inspector/fonts/test/browser_fontinspector_editor-letter-spacing-conversion.js new file mode 100644 index 0000000000..ff680717a9 --- /dev/null +++ b/devtools/client/inspector/fonts/test/browser_fontinspector_editor-letter-spacing-conversion.js @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +/* global getPropertyValue */ + +"use strict"; + +// Unit test for math behind conversion of units for letter-spacing. + +const TEST_URI = ` + <style type='text/css'> + body { + /* Set root font-size to equivalent of 32px (2*16px) */ + font-size: 200%; + } + div { + letter-spacing: 1em; + } + </style> + <div>LETTER SPACING</div> +`; + +add_task(async function () { + const URI = "data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI); + const { inspector, view } = await openFontInspectorForURL(URI); + const viewDoc = view.document; + const property = "letter-spacing"; + const UNITS = { + px: 32, + rem: 2, + em: 1, + }; + + await selectNode("div", inspector); + + info("Check that font editor shows letter-spacing value in original units"); + const letterSpacing = getPropertyValue(viewDoc, property); + is( + letterSpacing.value + letterSpacing.unit, + "1em", + "Original letter spacing is 1em" + ); + + // Starting value and unit for conversion. + let prevValue = letterSpacing.value; + let prevUnit = letterSpacing.unit; + + for (const unit in UNITS) { + const value = UNITS[unit]; + + info(`Convert letter-spacing from ${prevValue}${prevUnit} to ${unit}`); + const convertedValue = await view.convertUnits( + property, + prevValue, + prevUnit, + unit + ); + is( + convertedValue, + value, + `Converting to ${unit} returns transformed value.` + ); + + // Store current unit and value to use in conversion on the next iteration. + prevUnit = unit; + prevValue = value; + } + + info(`Check that conversion to fake unit returns 1-to-1 mapping`); + const valueToFakeUnit = await view.convertUnits(property, 1, "px", "fake"); + is(valueToFakeUnit, 1, `Converting to fake unit returns same value.`); +}); |