2007-04-19 06:49:44 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for computation of values in property database</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="property_database.js"></script>
|
|
|
|
<style type="text/css" id="stylesheet"></style>
|
2010-08-11 23:32:52 +04:00
|
|
|
<style type="text/css">
|
|
|
|
/* For 'width', 'height', etc., need a constant size container. */
|
|
|
|
#display { width: 500px; height: 200px }
|
|
|
|
</style>
|
2007-04-19 06:49:44 +04:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
<script type="text/javascript">
|
2015-01-17 07:16:02 +03:00
|
|
|
var numAssertions = 9;
|
|
|
|
if (SpecialPowers.getBoolPref("layout.css.vertical-text.enabled")) {
|
|
|
|
// these are from the additional margin-inline-{start,end} tests
|
|
|
|
numAssertions += 2;
|
|
|
|
}
|
|
|
|
SimpleTest.expectAssertions(numAssertions);
|
2007-04-19 06:49:44 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2013-09-19 05:35:19 +04:00
|
|
|
SimpleTest.requestLongerTimeout(2);
|
2007-04-19 06:49:44 +04:00
|
|
|
|
|
|
|
var load_count = 0;
|
|
|
|
function load_done() {
|
2007-04-26 03:27:36 +04:00
|
|
|
if (++load_count == 3)
|
2007-04-19 06:49:44 +04:00
|
|
|
run_tests();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2007-04-26 03:27:36 +04:00
|
|
|
<p id="display"><span><span id="elementf"></span></span>
|
|
|
|
<iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe>
|
|
|
|
<iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe>
|
2007-04-19 06:49:44 +04:00
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
2007-04-26 03:27:36 +04:00
|
|
|
<div><span id="elementn"></span></div>
|
2007-04-19 06:49:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for computation of values in property database **/
|
|
|
|
|
|
|
|
var gBadComputed = {
|
2007-07-22 21:58:37 +04:00
|
|
|
// These values are treated as auto.
|
|
|
|
"page-break-after": [ "avoid" ],
|
|
|
|
"page-break-before": [ "avoid" ],
|
2010-12-30 20:59:33 +03:00
|
|
|
|
|
|
|
// This is the only SVG-length property (i.e., length allowing
|
|
|
|
// unitless lengths) whose initial value is zero.
|
2012-09-06 08:58:47 +04:00
|
|
|
"stroke-dashoffset": [ "0", "-moz-objectValue" ],
|
2010-09-09 19:21:46 +04:00
|
|
|
};
|
2007-07-22 21:58:37 +04:00
|
|
|
|
2010-09-09 19:21:46 +04:00
|
|
|
var gBadComputedNoFrame = {
|
2007-04-19 06:49:44 +04:00
|
|
|
// These are probably bogus tests...
|
2012-07-14 02:06:50 +04:00
|
|
|
"border-radius": [ "0%", "calc(-1%)", "calc(0px) calc(0pt) calc(0%) calc(0em)" ],
|
|
|
|
"border-bottom-left-radius": [ "0%", "calc(-1%)" ],
|
|
|
|
"border-bottom-right-radius": [ "0%", "calc(-1%)" ],
|
|
|
|
"border-top-left-radius": [ "0%", "calc(-1%)" ],
|
|
|
|
"border-top-right-radius": [ "0%", "calc(-1%)" ],
|
2015-01-17 07:16:02 +03:00
|
|
|
"-moz-margin-end": [ "0%", "calc(0% + 0px)" ],
|
|
|
|
"-moz-margin-start": [ "0%", "calc(0% + 0px)" ],
|
2012-07-14 02:06:50 +04:00
|
|
|
"-moz-outline-radius": [ "0%", "calc(-1%)", "calc(0px) calc(0pt) calc(0%) calc(0em)" ],
|
|
|
|
"-moz-outline-radius-bottomleft": [ "0%", "calc(-1%)" ],
|
|
|
|
"-moz-outline-radius-bottomright": [ "0%", "calc(-1%)" ],
|
|
|
|
"-moz-outline-radius-topleft": [ "0%", "calc(-1%)" ],
|
|
|
|
"-moz-outline-radius-topright": [ "0%", "calc(-1%)" ],
|
|
|
|
"-moz-padding-end": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
|
|
|
"-moz-padding-start": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
2007-04-19 06:49:44 +04:00
|
|
|
"margin": [ "0% 0px 0em 0pt" ],
|
2012-07-14 02:06:50 +04:00
|
|
|
"margin-bottom": [ "0%", "calc(0% + 0px)" ],
|
2015-01-17 07:16:02 +03:00
|
|
|
"margin-inline-end": [ "0%", "calc(0% + 0px)" ],
|
|
|
|
"margin-inline-start": [ "0%", "calc(0% + 0px)" ],
|
2012-07-14 02:06:50 +04:00
|
|
|
"margin-left": [ "0%", "calc(0% + 0px)" ],
|
|
|
|
"margin-right": [ "0%", "calc(0% + 0px)" ],
|
|
|
|
"margin-top": [ "0%", "calc(0% + 0px)" ],
|
|
|
|
"min-height": [ "calc(-1%)" ],
|
|
|
|
"min-width": [ "calc(-1%)" ],
|
|
|
|
"padding": [ "0% 0px 0em 0pt", "calc(0px) calc(0em) calc(-2px) calc(-1%)" ],
|
2015-01-17 07:22:51 +03:00
|
|
|
"padding-block-end": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
|
|
|
"padding-block-start": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
2012-07-14 02:06:50 +04:00
|
|
|
"padding-bottom": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
2015-01-17 07:16:02 +03:00
|
|
|
"padding-inline-end": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
|
|
|
"padding-inline-start": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
2012-07-14 02:06:50 +04:00
|
|
|
"padding-left": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
|
|
|
"padding-right": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
|
|
|
"padding-top": [ "0%", "calc(0% + 0px)", "calc(-1%)" ],
|
2007-04-19 06:49:44 +04:00
|
|
|
};
|
|
|
|
|
2007-04-26 03:27:36 +04:00
|
|
|
function xfail_value(property, value, is_initial, has_frame) {
|
2007-04-19 06:49:44 +04:00
|
|
|
if ((property in gBadComputed) &&
|
|
|
|
gBadComputed[property].indexOf(value) != -1)
|
|
|
|
return true;
|
|
|
|
|
2007-04-26 03:27:36 +04:00
|
|
|
if (!has_frame && (property in gBadComputedNoFrame) &&
|
|
|
|
gBadComputedNoFrame[property].indexOf(value) != -1)
|
|
|
|
return true;
|
|
|
|
|
2007-04-19 06:49:44 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-11 23:32:52 +04:00
|
|
|
var gSwapInitialWhenHaveFrame = {
|
|
|
|
// When there's a frame, '-moz-available' works out to the same as
|
|
|
|
// 'auto' given the prerequisites of only 'display: block'.
|
|
|
|
"width": [ "-moz-available" ],
|
|
|
|
};
|
|
|
|
|
|
|
|
function swap_when_frame(property, value) {
|
|
|
|
return (property in gSwapInitialWhenHaveFrame) &&
|
|
|
|
gSwapInitialWhenHaveFrame[property].indexOf(value) != -1;
|
|
|
|
}
|
|
|
|
|
2007-04-26 03:27:36 +04:00
|
|
|
var gElementN = document.getElementById("elementn");
|
|
|
|
var gElementF = document.getElementById("elementf");
|
|
|
|
var gStyleSheet = document.getElementById("stylesheet").sheet;
|
|
|
|
var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
|
|
|
|
var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)];
|
|
|
|
|
|
|
|
var gInitialValuesN;
|
|
|
|
var gInitialValuesF;
|
|
|
|
var gInitialPrereqsRuleN;
|
|
|
|
var gInitialPrereqsRuleF;
|
|
|
|
|
|
|
|
function setup_initial_values(id, ivalprop, prereqprop) {
|
|
|
|
var iframe = document.getElementById(id);
|
|
|
|
window[ivalprop] = iframe.contentWindow.getComputedStyle(
|
|
|
|
iframe.contentDocument.documentElement.firstChild, "");
|
2007-04-19 06:49:44 +04:00
|
|
|
var sheet = iframe.contentDocument.styleSheets[0];
|
2010-08-11 23:32:52 +04:00
|
|
|
// For 'width', 'height', etc., need a constant size container.
|
|
|
|
sheet.insertRule(":root { height: 200px; width: 500px }", sheet.cssRules.length);
|
|
|
|
|
2007-04-26 03:27:36 +04:00
|
|
|
window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_value(property, val, is_initial)
|
|
|
|
{
|
|
|
|
var info = gCSSProperties[property];
|
|
|
|
if (info.backend_only)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ("prerequisites" in info) {
|
|
|
|
var prereqs = info.prerequisites;
|
|
|
|
for (var prereq in prereqs) {
|
2007-04-20 07:41:05 +04:00
|
|
|
gRule1.style.setProperty(prereq, prereqs[prereq], "");
|
2007-04-26 03:27:36 +04:00
|
|
|
gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], "");
|
|
|
|
gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], "");
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info.inherited && is_initial) {
|
2007-04-26 03:27:36 +04:00
|
|
|
gElementN.parentNode.style.setProperty(property, info.other_values[0], "");
|
|
|
|
gElementF.parentNode.style.setProperty(property, info.other_values[0], "");
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
|
2007-04-26 03:27:36 +04:00
|
|
|
var initial_computed_n = get_computed_value(gInitialValuesN, property);
|
|
|
|
var initial_computed_f = get_computed_value(gInitialValuesF, property);
|
2007-04-19 06:49:44 +04:00
|
|
|
if (is_initial) {
|
|
|
|
gRule1.style.setProperty(property, info.other_values[0], "");
|
2007-04-26 03:27:36 +04:00
|
|
|
var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
|
|
|
|
var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
|
2007-07-22 23:57:15 +04:00
|
|
|
isnot(other_computed_n, initial_computed_n,
|
2007-04-26 03:27:36 +04:00
|
|
|
"should be testing with values that compute to different things " +
|
|
|
|
"for '" + property + "'");
|
2007-07-22 23:57:15 +04:00
|
|
|
isnot(other_computed_f, initial_computed_f,
|
2007-04-19 06:49:44 +04:00
|
|
|
"should be testing with values that compute to different things " +
|
|
|
|
"for '" + property + "'");
|
|
|
|
}
|
2007-04-20 07:41:05 +04:00
|
|
|
// It's important for values that are supposed to compute to the
|
|
|
|
// initial value (given the current design of nsRuleNode) that we're
|
|
|
|
// modifying the most specific rule that matches the element, and that
|
|
|
|
// we've already requested style while that rule was empty. This
|
|
|
|
// means we'll have a cached aStartStruct from the parent in the rule
|
|
|
|
// tree (caching the "other" value), so we'll make sure we don't get
|
|
|
|
// the initial value from the luck of default-initialization.
|
|
|
|
// This means that it's important that we set the prereqs on
|
|
|
|
// gRule1.style rather than on gElement.style.
|
2007-04-19 06:49:44 +04:00
|
|
|
gRule2.style.setProperty(property, val, "");
|
2007-04-26 03:27:36 +04:00
|
|
|
var val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property);
|
|
|
|
var val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property);
|
2007-07-22 23:57:15 +04:00
|
|
|
isnot(val_computed_n, "",
|
|
|
|
"should not get empty value for '" + property + ":" + val + "'");
|
|
|
|
isnot(val_computed_f, "",
|
|
|
|
"should not get empty value for '" + property + ":" + val + "'");
|
2007-04-19 06:49:44 +04:00
|
|
|
if (is_initial) {
|
2007-04-26 03:27:36 +04:00
|
|
|
(xfail_value(property, val, is_initial, false) ? todo_is : is)(
|
|
|
|
val_computed_n, initial_computed_n,
|
|
|
|
"should get initial value for '" + property + ":" + val + "'");
|
|
|
|
(xfail_value(property, val, is_initial, true) ? todo_is : is)(
|
|
|
|
val_computed_f, initial_computed_f,
|
2007-04-19 06:49:44 +04:00
|
|
|
"should get initial value for '" + property + ":" + val + "'");
|
|
|
|
} else {
|
2007-04-26 03:27:36 +04:00
|
|
|
(xfail_value(property, val, is_initial, false) ? todo_isnot : isnot)(
|
|
|
|
val_computed_n, initial_computed_n,
|
2009-05-19 02:13:12 +04:00
|
|
|
"should not get initial value for '" + property + ":" + val + "' on elementn.");
|
2010-08-11 23:32:52 +04:00
|
|
|
var swap = swap_when_frame(property, val);
|
|
|
|
(xfail_value(property, val, is_initial, true) ? todo_isnot : (swap ? is : isnot))(
|
2007-04-26 03:27:36 +04:00
|
|
|
val_computed_f, initial_computed_f,
|
2010-08-11 23:32:52 +04:00
|
|
|
"should " + (swap ? "" : "not ") +
|
|
|
|
"get initial value for '" + property + ":" + val + "' on elementf.");
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
if (is_initial)
|
|
|
|
gRule1.style.removeProperty(property);
|
|
|
|
gRule2.style.removeProperty(property);
|
|
|
|
|
|
|
|
if ("prerequisites" in info) {
|
|
|
|
var prereqs = info.prerequisites;
|
|
|
|
for (var prereq in prereqs) {
|
2007-04-20 07:41:05 +04:00
|
|
|
gRule1.style.removeProperty(prereq);
|
2007-04-26 03:27:36 +04:00
|
|
|
gInitialPrereqsRuleN.style.removeProperty(prereq);
|
|
|
|
gInitialPrereqsRuleF.style.removeProperty(prereq);
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info.inherited && is_initial) {
|
2007-04-26 03:27:36 +04:00
|
|
|
gElementN.parentNode.style.removeProperty(property);
|
|
|
|
gElementF.parentNode.style.removeProperty(property);
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
2010-09-09 19:21:46 +04:00
|
|
|
|
|
|
|
// FIXME: Something (maybe with the -moz-binding values) causes
|
|
|
|
// gElementF's frame to get lost. Force it to get recreated after
|
|
|
|
// each property.
|
|
|
|
gElementF.parentNode.style.display = "none";
|
|
|
|
get_computed_value(getComputedStyle(gElementF, ""), "width");
|
|
|
|
gElementF.parentNode.style.display = "";
|
|
|
|
get_computed_value(getComputedStyle(gElementF, ""), "width");
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_property(prop) {
|
|
|
|
var info = gCSSProperties[prop];
|
|
|
|
for (var idx in info.initial_values)
|
|
|
|
test_value(prop, info.initial_values[idx], true);
|
|
|
|
for (var idx in info.other_values)
|
|
|
|
test_value(prop, info.other_values[idx], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_tests() {
|
2007-04-26 03:27:36 +04:00
|
|
|
setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN");
|
|
|
|
setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF");
|
2007-04-19 06:49:44 +04:00
|
|
|
var props = [];
|
|
|
|
for (var prop in gCSSProperties)
|
|
|
|
props.push(prop);
|
|
|
|
props = props.reverse();
|
2009-03-31 23:37:40 +04:00
|
|
|
function do_one() {
|
|
|
|
if (props.length == 0) {
|
2007-04-19 06:49:44 +04:00
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-31 23:37:40 +04:00
|
|
|
test_property(props.pop());
|
|
|
|
SimpleTest.executeSoon(do_one);
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
2009-03-31 23:37:40 +04:00
|
|
|
SimpleTest.executeSoon(do_one);
|
2007-04-19 06:49:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
load_done();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|