diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /layout/style/test/test_revert.html | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/style/test/test_revert.html')
-rw-r--r-- | layout/style/test/test_revert.html | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/layout/style/test/test_revert.html b/layout/style/test/test_revert.html new file mode 100644 index 0000000000..48897a75ca --- /dev/null +++ b/layout/style/test/test_revert.html @@ -0,0 +1,103 @@ +<!DOCTYPE HTML> +<title>Test for computation of CSS 'revert' on all properties</title> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="property_database.js"></script> +<style id="stylesheet"></style> +<link rel="stylesheet" href="/tests/SimpleTest/test.css" /> +<div id="inheritanceParent"> + <div id="inherited"></div> +</div> +<div id="nonInherited"></div> +<div id="noAuthorStyleApplied"></div> +<pre id="test"> +<script class="testbody"> + +const kSheet = document.getElementById("stylesheet").sheet; +const kAllDifferentFromInitialRule = kSheet.cssRules[kSheet.insertRule("#inheritanceParent {}", kSheet.cssRules.length)]; +const kPrerequisites = kSheet.cssRules[kSheet.insertRule("#inherited, #inheritanceParent, #nonInherited, #noAuthorStyleApplied {}", kSheet.cssRules.length)]; +const kResetPropRule = kSheet.cssRules[kSheet.insertRule("#nonInherited {}", kSheet.cssRules.length)]; + +const kInheritedDiv = document.getElementById("inherited"); +const kResetDiv = document.getElementById("nonInherited"); +const kNoAuthorStylesDiv = document.getElementById("noAuthorStyleApplied"); + +function computedValue(node, property) { + return get_computed_value(getComputedStyle(node), property); +} + +function getInitialValue(node, property) { + node.style.setProperty(property, "initial"); + const initial = computedValue(node, property); + node.style.removeProperty(property); + return initial; +} + +function testResetProperty(property, info) { + kResetPropRule.style.setProperty(property, info.other_values[0]); + + const div = kResetDiv; + const initial = getInitialValue(div, property); + const computed = computedValue(div, property); + + isnot(computed, initial, `${property}: Should get something non-initial to begin with`); + + const defaultValue = computedValue(kNoAuthorStylesDiv, property); + + div.style.setProperty(property, "revert"); + const reverted = computedValue(div, property); + is(reverted, defaultValue, `${property}: Should behave as if there was no author style`); + div.style.removeProperty(property); + kResetPropRule.style.removeProperty(property); +} + +function testInheritedProperty(property, info) { + // Given how line-height works, and that it always returns the used value, we + // cannot test it. The prerequisites for line-height makes getComputedStyle + // and getDefaultComputedStyle return the same, even though the computed value + // is different (normal vs. 19px). + if (property == "line-height") + return; + + const div = kInheritedDiv; + const initial = getInitialValue(div, property); + const parentValue = computedValue(div.parentNode, property); + + isnot(parentValue, initial, `${property}: Should inherit something non-initial to begin with`); + + const inheritedValue = computedValue(div, property); + const hasUARule = inheritedValue != parentValue; + + const defaultValue = computedValue(kNoAuthorStylesDiv, property); + (hasUARule ? is : isnot)(defaultValue, inheritedValue, `${property}: Should get the non-inherited value from somewhere (expected ${hasUARule ? "UA Rule" : "inheritance"} - inherited: ${inheritedValue} - parent: ${parentValue} - default: ${defaultValue})`); + + div.style.setProperty(property, "revert"); + const reverted = computedValue(div, property); + if (hasUARule) + is(reverted, defaultValue, `${property}: Should behave as if there was no author style`); + else + is(reverted, inheritedValue, `${property}: Should behave as if there was no author style`); + div.style.removeProperty(property); +} + +function testProperty(property, info) { + if (info.prerequisites) + for (const prereq in info.prerequisites) + kPrerequisites.style.setProperty(prereq, info.prerequisites[prereq]); + if (info.inherited) + testInheritedProperty(property, info); + else + testResetProperty(property, info); + kPrerequisites.style = ""; +} + +for (const prop in gCSSProperties) { + const info = gCSSProperties[prop]; + if (info.type != CSS_TYPE_LONGHAND) + continue; + kAllDifferentFromInitialRule.style.setProperty(prop, info.other_values[0]); +} + +for (const prop in gCSSProperties) + testProperty(prop, gCSSProperties[prop]); +</script> +</pre> |