summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/test/browser_css_angle.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/shared/test/browser_css_angle.js
parentInitial commit. (diff)
downloadthunderbird-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 'devtools/client/shared/test/browser_css_angle.js')
-rw-r--r--devtools/client/shared/test/browser_css_angle.js204
1 files changed, 204 insertions, 0 deletions
diff --git a/devtools/client/shared/test/browser_css_angle.js b/devtools/client/shared/test/browser_css_angle.js
new file mode 100644
index 0000000000..a29d3e4f0e
--- /dev/null
+++ b/devtools/client/shared/test/browser_css_angle.js
@@ -0,0 +1,204 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* import-globals-from head.js */
+"use strict";
+
+var { angleUtils } = require("resource://devtools/client/shared/css-angle.js");
+
+add_task(async function () {
+ await addTab("about:blank");
+ const { host } = await createHost("bottom");
+
+ info("Starting the test");
+ testAngleUtils();
+ testAngleValidity();
+
+ host.destroy();
+ gBrowser.removeCurrentTab();
+});
+
+function testAngleUtils() {
+ const data = getTestData();
+
+ for (const { authored, deg, rad, grad, turn } of data) {
+ const angle = new angleUtils.CssAngle(authored);
+
+ // Check all values.
+ info("Checking values for " + authored);
+ is(angle.deg, deg, "color.deg === deg");
+ is(angle.rad, rad, "color.rad === rad");
+ is(angle.grad, grad, "color.grad === grad");
+ is(angle.turn, turn, "color.turn === turn");
+
+ testToString(angle, deg, rad, grad, turn);
+ }
+}
+
+function testAngleValidity() {
+ const data = getAngleValidityData();
+
+ for (const { angle, result } of data) {
+ const testAngle = new angleUtils.CssAngle(angle);
+ const validString = testAngle.valid ? " a valid" : "an invalid";
+
+ is(
+ testAngle.valid,
+ result,
+ `Testing that "${angle}" is ${validString} angle`
+ );
+ }
+}
+
+function testToString(angle, deg, rad, grad, turn) {
+ const { ANGLEUNIT } = angleUtils.CssAngle.prototype;
+ angle.angleUnit = ANGLEUNIT.deg;
+ is(angle.toString(), deg, "toString() with deg type");
+
+ angle.angleUnit = ANGLEUNIT.rad;
+ is(angle.toString(), rad, "toString() with rad type");
+
+ angle.angleUnit = ANGLEUNIT.grad;
+ is(angle.toString(), grad, "toString() with grad type");
+
+ angle.angleUnit = ANGLEUNIT.turn;
+ is(angle.toString(), turn, "toString() with turn type");
+}
+
+function getAngleValidityData() {
+ return [
+ {
+ angle: "0.2turn",
+ result: true,
+ },
+ {
+ angle: "-0.2turn",
+ result: true,
+ },
+ {
+ angle: "-.2turn",
+ result: true,
+ },
+ {
+ angle: "1e02turn",
+ result: true,
+ },
+ {
+ angle: "-2e2turn",
+ result: true,
+ },
+ {
+ angle: ".2turn",
+ result: true,
+ },
+ {
+ angle: "0.2aaturn",
+ result: false,
+ },
+ {
+ angle: "2dega",
+ result: false,
+ },
+ {
+ angle: "0.deg",
+ result: false,
+ },
+ {
+ angle: ".deg",
+ result: false,
+ },
+ {
+ angle: "..2turn",
+ result: false,
+ },
+ ];
+}
+
+function getTestData() {
+ return [
+ {
+ authored: "0deg",
+ deg: "0deg",
+ rad: "0rad",
+ grad: "0grad",
+ turn: "0turn",
+ },
+ {
+ authored: "180deg",
+ deg: "180deg",
+ rad: `${Math.round(Math.PI * 10000) / 10000}rad`,
+ grad: "200grad",
+ turn: "0.5turn",
+ },
+ {
+ authored: "180DEG",
+ deg: "180DEG",
+ rad: `${Math.round(Math.PI * 10000) / 10000}RAD`,
+ grad: "200GRAD",
+ turn: "0.5TURN",
+ },
+ {
+ authored: `-${Math.PI}rad`,
+ deg: "-180deg",
+ rad: `-${Math.PI}rad`,
+ grad: "-200grad",
+ turn: "-0.5turn",
+ },
+ {
+ authored: `-${Math.PI}RAD`,
+ deg: "-180DEG",
+ rad: `-${Math.PI}RAD`,
+ grad: "-200GRAD",
+ turn: "-0.5TURN",
+ },
+ {
+ authored: "100grad",
+ deg: "90deg",
+ rad: `${Math.round((Math.PI / 2) * 10000) / 10000}rad`,
+ grad: "100grad",
+ turn: "0.25turn",
+ },
+ {
+ authored: "100GRAD",
+ deg: "90DEG",
+ rad: `${Math.round((Math.PI / 2) * 10000) / 10000}RAD`,
+ grad: "100GRAD",
+ turn: "0.25TURN",
+ },
+ {
+ authored: "-1turn",
+ deg: "-360deg",
+ rad: `${(-1 * Math.round(Math.PI * 2 * 10000)) / 10000}rad`,
+ grad: "-400grad",
+ turn: "-1turn",
+ },
+ {
+ authored: "-10TURN",
+ deg: "-3600DEG",
+ rad: `${(-1 * Math.round(Math.PI * 2 * 10 * 10000)) / 10000}RAD`,
+ grad: "-4000GRAD",
+ turn: "-10TURN",
+ },
+ {
+ authored: "inherit",
+ deg: "inherit",
+ rad: "inherit",
+ grad: "inherit",
+ turn: "inherit",
+ },
+ {
+ authored: "initial",
+ deg: "initial",
+ rad: "initial",
+ grad: "initial",
+ turn: "initial",
+ },
+ {
+ authored: "unset",
+ deg: "unset",
+ rad: "unset",
+ grad: "unset",
+ turn: "unset",
+ },
+ ];
+}