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/shared/tests/chrome/test_css-logic-getCssPath.html | |
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/shared/tests/chrome/test_css-logic-getCssPath.html | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/devtools/shared/tests/chrome/test_css-logic-getCssPath.html b/devtools/shared/tests/chrome/test_css-logic-getCssPath.html new file mode 100644 index 0000000000..333c9e0fdf --- /dev/null +++ b/devtools/shared/tests/chrome/test_css-logic-getCssPath.html @@ -0,0 +1,106 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1323700 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1323700</title> + + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> + <script type="application/javascript"> +"use strict"; + +const { require } = ChromeUtils.importESModule("resource://devtools/shared/loader/Loader.sys.mjs"); +const CssLogic = require("devtools/shared/inspector/css-logic"); + +var _tests = []; +function addTest(test) { + _tests.push(test); +} + +function runNextTest() { + if (!_tests.length) { + SimpleTest.finish() + return; + } + _tests.shift()(); +} + +window.onload = function() { + SimpleTest.waitForExplicitFinish(); + runNextTest(); +} + +addTest(function getCssPathForUnattachedElement() { + const unattached = document.createElement("div"); + unattached.id = "unattached"; + is(CssLogic.getCssPath(unattached), "", "Unattached node returns empty string"); + + const unattachedChild = document.createElement("div"); + unattached.appendChild(unattachedChild); + is(CssLogic.getCssPath(unattachedChild), "", "Unattached child returns empty string"); + + const unattachedBody = document.createElement("body"); + is(CssLogic.getCssPath(unattachedBody), "", "Unattached body returns empty string"); + + runNextTest(); +}); + +addTest(function cssPathHasOneStepForEachAncestor() { + for (const el of [...document.querySelectorAll('*')]) { + const splitPath = CssLogic.getCssPath(el).split(" "); + + let expectedNbOfParts = 0; + let parent = el.parentNode; + while (parent) { + expectedNbOfParts ++; + parent = parent.parentNode; + } + + is(splitPath.length, expectedNbOfParts, "There are enough parts in the full path"); + } + + runNextTest(); +}); + +addTest(function getCssPath() { + const data = [{ + selector: "#id", + path: "html body div div div.class div#id" + }, { + selector: "html", + path: "html" + }, { + selector: "body", + path: "html body" + }, { + selector: ".c1.c2.c3", + path: "html body span.c1.c2.c3" + }, { + selector: "#i", + path: "html body span#i.c1.c2" + }]; + + for (const {selector, path} of data) { + const node = document.querySelector(selector); + is (CssLogic.getCssPath(node), path, `Full css path is correct for ${selector}`); + } + + runNextTest(); +}); + </script> +</head> +<body> + <div> + <div> + <div class="class"> + <div id="id"></div> + </div> + </div> + </div> + <span class="c1 c2 c3"></span> + <span id="i" class="c1 c2"></span> +</body> +</html> |