From 5138fbff1b47461b9d7967d0ebf2a71e2015dc9e Mon Sep 17 00:00:00 2001 From: "dbaron@dbaron.org" Date: Sun, 15 Apr 2007 15:28:07 -0700 Subject: [PATCH] Test for inherit and initial on shorthand properties as well. b=258080 --- layout/style/test/test_inherit_storage.html | 102 ++++++++++++----- layout/style/test/test_initial_storage.html | 104 +++++++++++++----- layout/style/test/test_property_database.html | 32 ++++++ 3 files changed, 182 insertions(+), 56 deletions(-) diff --git a/layout/style/test/test_inherit_storage.html b/layout/style/test/test_inherit_storage.html index 6766f07fccc8..eba2e83b99e0 100644 --- a/layout/style/test/test_inherit_storage.html +++ b/layout/style/test/test_inherit_storage.html @@ -7,7 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=375363 Test for parsing, storage, and serialization of CSS 'inherit' - + @@ -25,41 +25,87 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=375363 var gDeclaration = document.getElementById("testnode").style; +var gKnownFails = { + /* bug 377519: */ + "-moz-border-radius": true, + "-moz-outline-radius": true, + "background": true, + "border": true, + "border-bottom": true, + "border-color": true, + "border-left": true, + "border-right": true, + "border-style": true, + "border-top": true, + "border-width": true, + "cue": true, + "font": true, + "list-style": true, + "margin": true, + "outline": true, + "padding": true, + "pause": true +}; + function test_property(property) { var pass = true; - var match = true; - var val = gDeclaration.getPropertyValue(property.name); - pass = pass && val == ""; - if (property.prop) - match = match && gDeclaration[property.prop] == val; + var info = gCSSProperties[property]; - gDeclaration.setProperty(property.name, "inherit", ""); - - val = gDeclaration.getPropertyValue(property.name); - pass = pass && val == "inherit"; - if (property.prop) - match = match && gDeclaration[property.prop] == val; - - gDeclaration.removeProperty(property.name); - - val = gDeclaration.getPropertyValue(property.name); - pass = pass && val == ""; - if (property.prop) - match = match && gDeclaration[property.prop] == val; - - ok(pass && match, "inherit parsed, stored, and serialized for CSS '" + property.name + "'"); - if (!match) { - /* already included in above ok, but exceptional in itself */ - ok(match, "getPropertyValue matches nsICSSProperties for CSS '" + property.name + "'"); + function check_initial(sproperty) { + var sinfo = gCSSProperties[sproperty]; + var val = gDeclaration.getPropertyValue(sproperty); + is(val, "", "value of '" + sproperty + "' before we do anything"); + if (sinfo.domProp) { + is(val, gDeclaration[sinfo.domProp], + "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); + } } + check_initial(property); + if ("subproperties" in info) + for (var idx in info.subproperties) + check_initial(info.subproperties[idx]); + + gDeclaration.setProperty(property, "inherit", ""); + + function check_set(sproperty) { + var sinfo = gCSSProperties[sproperty]; + val = gDeclaration.getPropertyValue(sproperty); + if (sproperty == property && property in gKnownFails) { + todo(val == "inherit", "inherit reported back for property '" + sproperty + "'"); + } else { + is(val, "inherit", "inherit reported back for property '" + sproperty + "'"); + } + if (sinfo.domProp) { + is(val, gDeclaration[sinfo.domProp], + "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); + } + } + check_set(property); + if ("subproperties" in info) + for (var idx in info.subproperties) + check_set(info.subproperties[idx]); + + gDeclaration.removeProperty(property); + + function check_final(sproperty) { + var sinfo = gCSSProperties[sproperty]; + var val = gDeclaration.getPropertyValue(sproperty); + is(val, "", "value of '" + sproperty + "' after removal of value"); + if (sinfo.domProp) { + is(val, gDeclaration[sinfo.domProp], + "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); + } + } + check_final(property); + if ("subproperties" in info) + for (var idx in info.subproperties) + check_final(info.subproperties[idx]); } -for (var idx in gLonghandProperties) - test_property(gLonghandProperties[idx]); -for (var idx in gShorthandPropertiesLikeLonghand) - test_property(gShorthandPropertiesLikeLonghand[idx]); +for (var prop in gCSSProperties) + test_property(prop); diff --git a/layout/style/test/test_initial_storage.html b/layout/style/test/test_initial_storage.html index 4b0790c8f092..f9fa81361592 100644 --- a/layout/style/test/test_initial_storage.html +++ b/layout/style/test/test_initial_storage.html @@ -7,7 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=375363 Test for parsing, storage, and serialization of CSS '-moz-initial' - + @@ -25,41 +25,89 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=375363 var gDeclaration = document.getElementById("testnode").style; +var gKnownFails = { + /* bug 377519: */ + "-moz-border-radius": true, + "-moz-outline-radius": true, + "background": true, + "border": true, + "border-bottom": true, + "border-color": true, + "border-left": true, + "border-right": true, + "border-style": true, + "border-top": true, + "border-width": true, + "cue": true, + "font": true, + "list-style": true, + "margin": true, + "outline": true, + "padding": true, + "pause": true + /* also see bug 377521 below */ +}; + function test_property(property) { var pass = true; - var match = true; - var val = gDeclaration.getPropertyValue(property.name); - pass = pass && val == ""; - if (property.prop) - match = match && gDeclaration[property.prop] == val; + var info = gCSSProperties[property]; - gDeclaration.setProperty(property.name, "-moz-initial", ""); - - val = gDeclaration.getPropertyValue(property.name); - pass = pass && val == "-moz-initial"; - if (property.prop) - match = match && gDeclaration[property.prop] == val; - - gDeclaration.removeProperty(property.name); - - val = gDeclaration.getPropertyValue(property.name); - pass = pass && val == ""; - if (property.prop) - match = match && gDeclaration[property.prop] == val; - - ok(pass && match, "-moz-initial parsed, stored, and serialized for CSS '" + property.name + "'"); - if (!match) { - /* already included in above ok, but exceptional in itself */ - ok(match, "getPropertyValue matches nsICSSProperties for CSS '" + property.name + "'"); + function check_initial(sproperty) { + var sinfo = gCSSProperties[sproperty]; + var val = gDeclaration.getPropertyValue(sproperty); + is(val, "", "value of '" + sproperty + "' before we do anything"); + if (sinfo.domProp) { + is(val, gDeclaration[sinfo.domProp], + "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); + } } + check_initial(property); + if ("subproperties" in info) + for (var idx in info.subproperties) + check_initial(info.subproperties[idx]); + + gDeclaration.setProperty(property, "-moz-initial", ""); + + function check_set(sproperty) { + var sinfo = gCSSProperties[sproperty]; + val = gDeclaration.getPropertyValue(sproperty); + if ((sproperty == property && property in gKnownFails) || + (property == "font" && sproperty != "font-family")) { /* bug 377521 */ + todo(val == "-moz-initial", "-moz-initial reported back for property '" + sproperty + "'"); + } else { + is(val, "-moz-initial", "-moz-initial reported back for property '" + sproperty + "'"); + } + if (sinfo.domProp) { + is(val, gDeclaration[sinfo.domProp], + "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); + } + } + check_set(property); + if ("subproperties" in info) + for (var idx in info.subproperties) + check_set(info.subproperties[idx]); + + gDeclaration.removeProperty(property); + + function check_final(sproperty) { + var sinfo = gCSSProperties[sproperty]; + var val = gDeclaration.getPropertyValue(sproperty); + is(val, "", "value of '" + sproperty + "' after removal of value"); + if (sinfo.domProp) { + is(val, gDeclaration[sinfo.domProp], + "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); + } + } + check_final(property); + if ("subproperties" in info) + for (var idx in info.subproperties) + check_final(info.subproperties[idx]); } -for (var idx in gLonghandProperties) - test_property(gLonghandProperties[idx]); -for (var idx in gShorthandPropertiesLikeLonghand) - test_property(gShorthandPropertiesLikeLonghand[idx]); +for (var prop in gCSSProperties) + test_property(prop); diff --git a/layout/style/test/test_property_database.html b/layout/style/test/test_property_database.html index 8d737f76aadc..06d78494bb53 100644 --- a/layout/style/test/test_property_database.html +++ b/layout/style/test/test_property_database.html @@ -55,6 +55,38 @@ for (var idx in gShorthandPropertiesLikeLonghand) { "'" + prop.name + "' listed in gCSSProperties as CSS_TYPE_SHORTHAND_AND_LONGHAND with correct DOM property name"); } +/* + * Test that all shorthand properties have a subproperty list and all + * longhand properties do not. + */ +for (var prop in gCSSProperties) { + var info = gCSSProperties[prop]; + if (info.type == CSS_TYPE_LONGHAND) { + ok(!("subproperties" in info), + "longhand property '" + prop + "' must not have subproperty list"); + } else if (info.type == CSS_TYPE_TRUE_SHORTHAND) { + ok("subproperties" in info, + "shorthand property '" + prop + "' must have subproperty list"); + } + /* optional for CSS_TYPE_SHORTHAND_AND_LONGHAND */ + + if ("subproperties" in info) { + var good = true; + if (info.subproperties.length < 1) { + info("subproperty list for '" + prop + "' is empty"); + good = false; + } + for (var idx in info.subproperties) { + var subprop = info.subproperties[idx]; + if (!(subprop in gCSSProperties)) { + info("subproperty list for '" + prop + "' lists nonexistent subproperty '" + subprop + "'"); + good = false; + } + } + ok(good, "property '" + prop + "' has a good subproperty list"); + } +} +