use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.
the class StyleAttributesTest method lexicographicOrder.
/**
* Test of alphabetical order.
*/
@Test
public void lexicographicOrder() {
String lastName = null;
for (final Definition definition : StyleAttributes.Definition.values()) {
final String name = definition.name();
if (lastName != null && name.compareToIgnoreCase(lastName) < 1) {
fail("StyleAttributes.Definition: '" + name + "' should be before '" + lastName + "'");
}
lastName = name;
}
}
use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.
the class CSSStyleDeclarationTest method styleAttributes.
/**
* Tests that all getters and setters {@link CSSStyleDeclaration} have correct browser support
* as defined in {@link StyleAttributes}.
*
* @throws Exception if an error occurs
*/
@Test
public void styleAttributes() throws Exception {
final List<String> allProperties = new ArrayList<>();
for (final BrowserVersion browserVersion : allBrowsers()) {
final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
if (!definition.name().endsWith("_")) {
final String propertyName = definition.getPropertyName();
final PropertyInfo info = config.getPropertyMap().get(propertyName);
if (info != null) {
allProperties.add(propertyName);
}
}
}
}
final BrowserVersion browserVersion = getBrowserVersion();
final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
if (!definition.name().endsWith("_")) {
final String propertyName = definition.getPropertyName();
final PropertyInfo info = config.getPropertyMap().get(propertyName);
if (allProperties.contains(propertyName) && (info == null || info.getReadMethod() == null || info.getWriteMethod() == null)) {
fail("CSSStyleDeclaration: " + propertyName + " must support " + browserVersion.getNickname());
}
}
}
for (final String propertyName : config.getPropertyMap().keySet()) {
if (!"length".equals(propertyName) && !"parentRule".equals(propertyName) && !"cssText".equals(propertyName) && StyleAttributes.getDefinition(propertyName, browserVersion) == null) {
fail("CSSStyleDeclaration: incorrectly defines " + propertyName + " for " + browserVersion.getNickname());
}
}
}
use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.
the class CSSStyleDeclaration method getIds.
@Override
public Object[] getIds() {
final List<Object> ids = new ArrayList<>();
for (final Definition styleAttribute : StyleAttributes.getDefinitions(getBrowserVersion())) {
ids.add(styleAttribute.getPropertyName());
}
final Object[] normalIds = super.getIds();
for (final Object o : normalIds) {
if (!ids.contains(o)) {
ids.add(o);
}
}
return ids.toArray();
}
use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.
the class CSSStyleDeclaration method get.
/**
* {@inheritDoc}
*/
@Override
public Object get(final String name, final Scriptable start) {
if (this != start) {
return super.get(name, start);
}
Scriptable prototype = getPrototype();
while (prototype != null) {
Object value = prototype.get(name, start);
if (value != Scriptable.NOT_FOUND) {
return value;
}
final String camel = camelize(name);
if (!name.equals(camel)) {
value = prototype.get(camel, start);
if (value != Scriptable.NOT_FOUND) {
return value;
}
}
prototype = prototype.getPrototype();
}
final Definition style = StyleAttributes.getDefinition(name, getBrowserVersion());
if (style != null) {
return getStyleAttribute(style);
}
return super.get(name, start);
}
use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.
the class CSSStyleDeclaration method put.
@Override
public void put(final String name, final Scriptable start, final Object value) {
if (this != start) {
super.put(name, start, value);
return;
}
final Scriptable prototype = getPrototype();
if (prototype != null && !"constructor".equals(name)) {
if (prototype.get(name, start) != Scriptable.NOT_FOUND) {
prototype.put(name, start, value);
return;
}
final String camel = camelize(name);
if (!name.equals(camel) && prototype.get(camel, start) != Scriptable.NOT_FOUND) {
prototype.put(camel, start, value);
return;
}
}
if (getDomNodeOrNull() != null) {
// check if prototype or not
final Definition style = StyleAttributes.getDefinition(name, getBrowserVersion());
if (style != null) {
final String stringValue = Context.toString(value);
setStyleAttribute(style.getAttributeName(), stringValue);
return;
}
}
super.put(name, start, value);
}
Aggregations