From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../shared/test/xpcshell/test_cssColor-02.js | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 devtools/client/shared/test/xpcshell/test_cssColor-02.js (limited to 'devtools/client/shared/test/xpcshell/test_cssColor-02.js') diff --git a/devtools/client/shared/test/xpcshell/test_cssColor-02.js b/devtools/client/shared/test/xpcshell/test_cssColor-02.js new file mode 100644 index 0000000000..77b692e6a7 --- /dev/null +++ b/devtools/client/shared/test/xpcshell/test_cssColor-02.js @@ -0,0 +1,50 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +/** + * Test color cycling regression - Bug 1303748. + * + * Values should cycle from a starting value, back to their original values. This can + * potentially be a little flaky due to the precision of different color representations. + */ + +const { colorUtils } = require("resource://devtools/shared/css/color.js"); +const getFixtureColorData = require("resource://test/helper_color_data.js"); + +function run_test() { + getFixtureColorData().forEach( + ({ authored, name, hex, hsl, rgb, hwb, cycle }) => { + if (cycle) { + const nameCycled = runCycle(name, cycle); + const hexCycled = runCycle(hex, cycle); + const hslCycled = runCycle(hsl, cycle); + const rgbCycled = runCycle(rgb, cycle); + const hwbCycled = runCycle(hwb, cycle); + // Cut down on log output by only reporting a single pass/fail for the color. + ok( + nameCycled && hexCycled && hslCycled && rgbCycled && hwbCycled, + `${authored} was able to cycle back to the original value` + ); + } + } + ); +} + +/** + * Test a color cycle to see if a color cycles back to its original value in a fixed + * number of steps. + * + * @param {string} value - The color value, e.g. "#000". + * @param {integer) times - The number of times it takes to cycle back to the + * original color. + */ +function runCycle(value, times) { + let color = new colorUtils.CssColor(value); + const colorUnit = colorUtils.classifyColor(value); + for (let i = 0; i < times; i++) { + const newColor = color.nextColorUnit(); + color = new colorUtils.CssColor(newColor); + } + return color.toString(colorUnit) === value; +} -- cgit v1.2.3