зеркало из https://github.com/mozilla/pjs.git
Add tests for parsing, storage, and serialization of inherit and -moz-initial values.
This commit is contained in:
Родитель
caa7e9b8e7
Коммит
949c29498f
|
@ -0,0 +1,205 @@
|
|||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is ListCSSProperties.
|
||||
*
|
||||
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* build (from code) lists of all supported CSS properties */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct PropertyInfo {
|
||||
const char *propName;
|
||||
const char *domName;
|
||||
};
|
||||
|
||||
const PropertyInfo gLonghandProperties[] = {
|
||||
|
||||
#define CSS_PROP_NOTIMPLEMENTED(name_, id_, method_) \
|
||||
{ #name_, #method_ },
|
||||
#define CSS_PROP(name_, id_, method_, datastruct_, member_, type_, kwtable_) \
|
||||
{ #name_, #method_ },
|
||||
|
||||
#include "nsCSSPropList.h"
|
||||
|
||||
#undef CSS_PROP_NOTIMPLEMENTED
|
||||
#undef CSS_PROP
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* These are the properties for which domName in the above list should
|
||||
* be used. They're in the same order as the above list, with some
|
||||
* items skipped.
|
||||
*/
|
||||
const char* gLonghandPropertiesWithDOMProp[] = {
|
||||
|
||||
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
|
||||
#define CSS_PROP_NOTIMPLEMENTED(name_, id_, method_) \
|
||||
#name_,
|
||||
#define CSS_PROP(name_, id_, method_, datastruct_, member_, type_, kwtable_) \
|
||||
#name_,
|
||||
|
||||
#include "nsCSSPropList.h"
|
||||
|
||||
#undef CSS_PROP_NOTIMPLEMENTED
|
||||
#undef CSS_PROP
|
||||
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
|
||||
|
||||
};
|
||||
|
||||
const PropertyInfo gShorthandProperties[] = {
|
||||
|
||||
#define CSS_PROP_SHORTHAND(name_, id_, method_) \
|
||||
{ #name_, #method_ },
|
||||
|
||||
#include "nsCSSPropList.h"
|
||||
|
||||
#undef CSS_PROP_SHORTHAND
|
||||
|
||||
};
|
||||
|
||||
/* see gLonghandPropertiesWithDOMProp */
|
||||
const char* gShorthandPropertiesWithDOMProp[] = {
|
||||
|
||||
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
|
||||
#define CSS_PROP_SHORTHAND(name_, id_, method_) \
|
||||
#name_,
|
||||
|
||||
#include "nsCSSPropList.h"
|
||||
|
||||
#undef CSS_PROP_SHORTHAND
|
||||
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define ARRAY_LENGTH(a_) (sizeof(a_)/sizeof((a_)[0]))
|
||||
|
||||
const char *gInaccessibleProperties[] = {
|
||||
// Don't print the properties that aren't accepted by the parser, per
|
||||
// CSSParserImpl::ParseProperty
|
||||
"-x-background-x-position",
|
||||
"-x-background-y-position",
|
||||
"margin-end-value",
|
||||
"margin-left-value",
|
||||
"margin-right-value",
|
||||
"margin-start-value",
|
||||
"margin-left-ltr-source",
|
||||
"margin-left-rtl-source",
|
||||
"margin-right-ltr-source",
|
||||
"margin-right-rtl-source",
|
||||
"padding-end-value",
|
||||
"padding-left-value",
|
||||
"padding-right-value",
|
||||
"padding-start-value",
|
||||
"padding-left-ltr-source",
|
||||
"padding-left-rtl-source",
|
||||
"padding-right-ltr-source",
|
||||
"padding-right-rtl-source"
|
||||
};
|
||||
|
||||
inline int
|
||||
is_inaccessible(const char* aPropName)
|
||||
{
|
||||
for (unsigned j = 0; j < ARRAY_LENGTH(gInaccessibleProperties); ++j) {
|
||||
if (strcmp(aPropName, gInaccessibleProperties[j]) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
print_array(const char *aName,
|
||||
const PropertyInfo *aProps, unsigned aPropsLength,
|
||||
const char * const * aDOMProps, unsigned aDOMPropsLength)
|
||||
{
|
||||
printf("var %s = [\n", aName);
|
||||
|
||||
int first = 1;
|
||||
unsigned j = 0; // index into DOM prop list
|
||||
for (unsigned i = 0; i < aPropsLength; ++i) {
|
||||
const PropertyInfo *p = aProps + i;
|
||||
|
||||
if (is_inaccessible(p->propName))
|
||||
// inaccessible properties never have DOM props, so don't
|
||||
// worry about incrementing j. The assertion below will
|
||||
// catch if they do.
|
||||
continue;
|
||||
|
||||
if (first)
|
||||
first = 0;
|
||||
else
|
||||
printf(",\n");
|
||||
|
||||
printf("\t{ name: \"%s\", prop: ", p->propName);
|
||||
if (j >= aDOMPropsLength || strcmp(p->propName, aDOMProps[j]) != 0)
|
||||
printf("null");
|
||||
else {
|
||||
++j;
|
||||
if (strncmp(p->domName, "Moz", 3) == 0)
|
||||
printf("\"%s\"", p->domName);
|
||||
else
|
||||
// lowercase the first letter
|
||||
printf("\"%c%s\"", p->domName[0] + 32, p->domName + 1);
|
||||
}
|
||||
printf("}");
|
||||
}
|
||||
|
||||
if (j != aDOMPropsLength) {
|
||||
fprintf(stderr, "Assertion failure %s:%d\n", __FILE__, __LINE__);
|
||||
fprintf(stderr, "j==%d, aDOMPropsLength == %d\n", j, aDOMPropsLength);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("\n];\n\n");
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
print_array("gLonghandProperties",
|
||||
gLonghandProperties,
|
||||
ARRAY_LENGTH(gLonghandProperties),
|
||||
gLonghandPropertiesWithDOMProp,
|
||||
ARRAY_LENGTH(gLonghandPropertiesWithDOMProp));
|
||||
print_array("gShorthandProperties",
|
||||
gShorthandProperties,
|
||||
ARRAY_LENGTH(gShorthandProperties),
|
||||
gShorthandPropertiesWithDOMProp,
|
||||
ARRAY_LENGTH(gShorthandPropertiesWithDOMProp));
|
||||
return 0;
|
||||
}
|
|
@ -42,14 +42,34 @@ VPATH = @srcdir@
|
|||
relativesrcdir = layout/style/test
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = layout
|
||||
|
||||
# XXX want HOST_CPPSRCS
|
||||
CPPSRCS = \
|
||||
ListCSSProperties.cpp \
|
||||
$(NULL)
|
||||
|
||||
# XXX want HOST_SIMPLE_PROGRAMS
|
||||
SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX))
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
css_properties.js: ListCSSProperties$(BIN_SUFFIX) css_properties_like_longhand.js Makefile
|
||||
$(RM) $@
|
||||
./ListCSSProperties$(BIN_SUFFIX) > $@
|
||||
cat $(srcdir)/css_properties_like_longhand.js >> $@
|
||||
|
||||
_TEST_FILES = test_bug302186.html \
|
||||
test_bug319381.html \
|
||||
test_bug365932.html \
|
||||
test_bug372770.html \
|
||||
test_bug373293.html \
|
||||
test_inherit_storage.html \
|
||||
test_initial_storage.html \
|
||||
css_properties.js \
|
||||
$(NULL)
|
||||
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
var gShorthandPropertiesLikeLonghand = [
|
||||
{ name: "background-position", prop: "backgroundPosition"},
|
||||
{ name: "-moz-margin-end", prop: "MozMarginEnd"},
|
||||
{ name: "margin-left", prop: "marginLeft"},
|
||||
{ name: "margin-right", prop: "marginRight"},
|
||||
{ name: "-moz-margin-start", prop: "MozMarginStart"},
|
||||
{ name: "overflow", prop: "overflow"},
|
||||
{ name: "-moz-padding-end", prop: "MozPaddingEnd"},
|
||||
{ name: "padding-left", prop: "paddingLeft"},
|
||||
{ name: "padding-right", prop: "paddingRight"},
|
||||
{ name: "-moz-padding-start", prop: "MozPaddingStart"},
|
||||
];
|
|
@ -0,0 +1,75 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=375363
|
||||
-->
|
||||
<head>
|
||||
<title>Test for parsing, storage, and serialization of CSS 'inherit'</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="css_properties.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375363">Mozilla Bug 375363</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
<div id="testnode"></div>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for parsing, storage, and serialization of CSS 'inherit' **/
|
||||
|
||||
var gDeclaration = document.getElementById("testnode").style;
|
||||
|
||||
/* all failures covered by bug 375363 */
|
||||
var gKnownFails = {
|
||||
"-moz-force-broken-image-icon": true,
|
||||
"quotes": true,
|
||||
"-moz-box-ordinal-group": true,
|
||||
"background-position": 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;
|
||||
|
||||
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;
|
||||
|
||||
(property.name in gKnownFails ? todo : ok)(pass && match, "inherit parsed, stored, and serialized for CSS '" + property.name + "'");
|
||||
if (!match) {
|
||||
/* already included in above todo/ok, but exceptional in itself */
|
||||
ok(match, "getPropertyValue matches nsICSSProperties for CSS '" + property.name + "'");
|
||||
}
|
||||
}
|
||||
|
||||
for (var idx in gLonghandProperties)
|
||||
test_property(gLonghandProperties[idx]);
|
||||
for (var idx in gShorthandPropertiesLikeLonghand)
|
||||
test_property(gShorthandPropertiesLikeLonghand[idx]);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,75 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=375363
|
||||
-->
|
||||
<head>
|
||||
<title>Test for parsing, storage, and serialization of CSS '-moz-initial'</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="css_properties.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375363">Mozilla Bug 375363</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
<div id="testnode"></div>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for parsing, storage, and serialization of CSS '-moz-initial' **/
|
||||
|
||||
var gDeclaration = document.getElementById("testnode").style;
|
||||
|
||||
/* all failures covered by bug 375363 */
|
||||
var gKnownFails = {
|
||||
"-moz-force-broken-image-icon": true,
|
||||
"quotes": true,
|
||||
"-moz-box-ordinal-group": true,
|
||||
"background-position": 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;
|
||||
|
||||
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;
|
||||
|
||||
(property.name in gKnownFails ? todo : ok)(pass && match, "-moz-initial parsed, stored, and serialized for CSS '" + property.name + "'");
|
||||
if (!match) {
|
||||
/* already included in above todo/ok, but exceptional in itself */
|
||||
ok(match, "getPropertyValue matches nsICSSProperties for CSS '" + property.name + "'");
|
||||
}
|
||||
}
|
||||
|
||||
for (var idx in gLonghandProperties)
|
||||
test_property(gLonghandProperties[idx]);
|
||||
for (var idx in gShorthandPropertiesLikeLonghand)
|
||||
test_property(gShorthandPropertiesLikeLonghand[idx]);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче