blob: c9eef7d1ed3fb2c9e6b7bb61b292e22edbe41aa5 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test-pre.js"></script>
<script>
var element;
function testDOMStringReflection(elementName, contentAttributeName, idlAttributeName) {
idlAttributeName = idlAttributeName || contentAttributeName;
element = document.createElement(elementName);
debug('Reflected DOMString attribute test for ' + elementName + '/@' + contentAttributeName);
debug('Initial value:');
shouldBeEqualToString('element.' + idlAttributeName, '');
shouldBeNull('element.getAttribute("' + contentAttributeName + '")');
debug('Setting a value via the IDL attribute:');
shouldBeEqualToString('element.' + idlAttributeName + ' = "foo"; element.' + idlAttributeName, 'foo');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'foo');
debug('Setting a value via the content attribute:');
shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", " bar\\n"); element.' + idlAttributeName, ' bar\n');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', ' bar\n');
debug('Setting null via the IDL attribute:');
shouldBeEqualToString('element.' + idlAttributeName + ' = null; element.' + idlAttributeName, '');
shouldBeNull('element.getAttribute("' + contentAttributeName + '")');
debug('Setting null via the content attribute:');
shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", null); element.' + idlAttributeName, 'null');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'null');
debug('Setting undefined via the IDL attribute:');
shouldBeEqualToString('element.' + idlAttributeName + ' = undefined; element.' + idlAttributeName, 'undefined');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'undefined');
debug('Setting undefined via the content attribute:');
shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", undefined); element.' + idlAttributeName, 'undefined');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', 'undefined');
debug('Setting non-string via the IDL attribute:');
shouldBeEqualToString('element.' + idlAttributeName + ' = 123; element.' + idlAttributeName, '123');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '123');
debug('Setting non-string via the content attribute:');
shouldBeEqualToString('element.setAttribute("' + contentAttributeName + '", 456); element.' + idlAttributeName, '456');
shouldBeEqualToString('element.getAttribute("' + contentAttributeName + '")', '456');
debug('\n');
}
testDOMStringReflection('button', 'name');
testDOMStringReflection('fieldset', 'name');
testDOMStringReflection('form', 'name');
testDOMStringReflection('input', 'name');
testDOMStringReflection('input', 'step');
testDOMStringReflection('keygen', 'name');
testDOMStringReflection('object', 'name');
testDOMStringReflection('output', 'name');
testDOMStringReflection('select', 'name');
testDOMStringReflection('textarea', 'name');
// Add more DOMString attributes!
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>