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_parseSingleValue.js | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 devtools/client/shared/test/xpcshell/test_parseSingleValue.js (limited to 'devtools/client/shared/test/xpcshell/test_parseSingleValue.js') diff --git a/devtools/client/shared/test/xpcshell/test_parseSingleValue.js b/devtools/client/shared/test/xpcshell/test_parseSingleValue.js new file mode 100644 index 0000000000..4617c6de2c --- /dev/null +++ b/devtools/client/shared/test/xpcshell/test_parseSingleValue.js @@ -0,0 +1,106 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { + parseSingleValue, +} = require("resource://devtools/shared/css/parsing-utils.js"); +const { + isCssPropertyKnown, +} = require("resource://devtools/server/actors/css-properties.js"); + +const TEST_DATA = [ + { input: null, throws: true }, + { input: undefined, throws: true }, + { input: "", expected: { value: "", priority: "" } }, + { input: " \t \t \n\n ", expected: { value: "", priority: "" } }, + { input: "blue", expected: { value: "blue", priority: "" } }, + { + input: "blue !important", + expected: { value: "blue", priority: "important" }, + }, + { + input: "blue!important", + expected: { value: "blue", priority: "important" }, + }, + { + input: "blue ! important", + expected: { value: "blue", priority: "important" }, + }, + { + input: "blue ! important", + expected: { value: "blue", priority: "important" }, + }, + { input: "blue !", expected: { value: "blue !", priority: "" } }, + { + input: "blue !mportant", + expected: { value: "blue !mportant", priority: "" }, + }, + { + input: " blue !important ", + expected: { value: "blue", priority: "important" }, + }, + { + input: 'url("http://url.com/whyWouldYouDoThat!important.png") !important', + expected: { + value: 'url("http://url.com/whyWouldYouDoThat!important.png")', + priority: "important", + }, + }, + { + input: 'url("http://url.com/whyWouldYouDoThat!important.png")', + expected: { + value: 'url("http://url.com/whyWouldYouDoThat!important.png")', + priority: "", + }, + }, + { + input: '"content!important" !important', + expected: { + value: '"content!important"', + priority: "important", + }, + }, + { + input: '"content!important"', + expected: { + value: '"content!important"', + priority: "", + }, + }, + { + input: '"all the \\"\'\\\\ special characters"', + expected: { + value: '"all the \\"\'\\\\ special characters"', + priority: "", + }, + }, +]; + +function run_test() { + for (const test of TEST_DATA) { + info("Test input value " + test.input); + try { + const output = parseSingleValue(isCssPropertyKnown, test.input); + assertOutput(output, test.expected); + } catch (e) { + info( + "parseSingleValue threw an exception with the given input " + "value" + ); + if (test.throws) { + info("Exception expected"); + Assert.ok(true); + } else { + info("Exception unexpected\n" + e); + Assert.ok(false); + } + } + } +} + +function assertOutput(actual, expected) { + info("Check that the output has the expected value and priority"); + Assert.equal(expected.value, actual.value); + Assert.equal(expected.priority, actual.priority); +} -- cgit v1.2.3